当前位置:文档之家› 打靶系统程序清单

打靶系统程序清单

程序清单计算机0206班陈召学号:012002013805 试验台:87、88 整个系统包含两大块程序:下行机的client.cpp和主控机的host.cpp一、下行机程序:client.cpp1、程序功能:负责读取靶数,并进行相关的显示,同时负责与主控机进行通信;2、开发环境:TC2.0;3、开发人:陈召,左明,许诺,刘树伟4、开发日期:2005年9月7日源代码:#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <dos.h>#include <graphics.h>#define data51 0x308 /*8251数据口*/#define ctrl51 0x309 /*8251命令/状态口*/#define dataa55 0x300 /*8255数据A口*/#define datab55 0x301 /*8255数据B口*/#define datac55 0x302 /*8255数据C口*/#define ctrl55 0x303 /*8255命令口*/void int51();void int55();int send(int,int);void main(){int temp,temp2,total,count=0;int data,x0,y0,c=0;double ab,r,x,y;float e;int graphdriver=VGA,graphmode=VGAHI;int flag=0x00;int51();int55();/*struct fillsettingstype save;*/initgraph(&graphdriver,&graphmode," ");/*getfillsettings(&save);*/ /*得到初始化时填充模式*/setbkcolor(EGA_BLUE);cleardevice();setcolor(12);circle(320,220,30); /*在显示器上显示靶图*/circle(320,220,45);circle(320,220,60);circle(320,220,75);circle(320,220,90);circle(320,220,105);circle(320,220,120);circle(320,220,135);circle(320,220,150);circle(320,220,165);while(1){dotemp=inportb(datab55);while(flag==(temp&0x80)); /*当从8255b口读出的数据最高位改变时,跳出循环*/if(flag==0) { /*将标志flag改变*/flag=0x80;}else flag=0x00;data=temp&0x7f; /*将数据的最高位置0*/if(data>10) data=0;count++; /**/c=c+19;e=c%100;e=e/100;if(data==0){;}else{r=(10-data)*15+22;x=r*e;ab=r*r-x*x;y=sqrt(ab);if(e>0.5){ /*随机决定点x0坐标的区间*/x0=320+x;}else x0=320-x;if(e>0.5){ /*随机决定点y0坐标的区间*/y0=220+y;}else y0=220-y;setcolor(15);circle(x0,y0,6);}/*转入发送程序*/total=send(data,count);if(count==10){/*getch();*/closegraph();count=0;flag=0x00;printf("\n**********************************************************");printf("\n ***************Welcome to our shooting game!********************");printf("\n**********************************************************");printf("\n************************************************************* ************");printf("\nyou have shot %d",total);printf("\npress anykey to restart");printf("\npress 2 to exit\n");scanf("%d",&temp2);if(temp2==2){count=send(0xff,0);break;}clrscr();/*struct fillsettingstype save;*/initgraph(&graphdriver,&graphmode," ");/*getfillsettings(&save);*/ /*得到初始化时填充模式*/setbkcolor(EGA_BLUE);cleardevice();setcolor(EGA_GREEN);circle(320,220,30); /*重新在显示器上显示靶图*/setcolor(12);circle(320,220,45);circle(320,220,60);circle(320,220,75);circle(320,220,90);circle(320,220,105);circle(320,220,120);circle(320,220,135);circle(320,220,150);circle(320,220,165);}}}int send(int data,int count){ /*串行通信程序*/int status,rletter;dostatus=inportb(ctrl51); /*获取8251 TXRDY 状态*/while((status&0x01)==0); /*已准备好,则将数据发送出去*/outportb(data51,data);if(count==10){dostatus=inportb(ctrl51);/*已准备好,即有数据传送过来,则接收1个字符*/while((status&0x02)==0);rletter=inportb(data51);return rletter;}else return 0;}void int51() /*8251的初始化程序*/{outportb(ctrl51,0x00);delay(100);outportb(ctrl51,0x40);/*8251复位*/delay(100);outportb(ctrl51,0x4e);/*8251A方式命令*/delay(100);outportb(ctrl51,0x27);/*8251A工作命令*/}void int55(){ /*8255的初始化程序*/outportb(ctrl55,0x92);}二、主控机程序:host.cpp1、程序功能:从下行机获取数据并储存,当达到一定的数目时计算总成绩返回到下行机;还包括其他一些显示功能;2、开发环境:TC2.0;3、开发人:左明,陈召,许诺,刘树伟4、开发日期:2005年9月7日源程序:#include<stdio.h>#include<conio.h>#include<dos.h>#define data51 0x308 /*8251数据口*/#define ctrl51 0x309 /*8251命令/状态口*/#define dataa55 0x300 /*8255数据A口*/#define datab55 0x301 /*8255数据B口*/#define datac55 0x302 /*8255数据C口*/#define ctrl55 0x303 /*8255命令口*/#define COUNT 10 /*每局打靶的次数*/void int51()/*初始化函数*/{outportb(ctrl51,0x00);/*空操作*/delay(100);outportb(ctrl51,0x40);/*8251复位*/delay(100);outportb(ctrl51,0x4e);/*8251A方式命令*/delay(100);outportb(ctrl51,0x27);/*8251A工作命令*/}void main(void){int a[COUNT];int j;int b=0;int e;int i=0;int status;int temp;int51();printf(" **************************************\n\r ");printf(" * THE SHOOTING SYSTEM *\n\r ");printf(" * ver1.0 cz xn zm lsw *\n\r ");printf(" ********************************\n\r ");for(;;)/*总循环*/{if(i==COUNT){ /*如果一局打完输出此局各次的成绩和总成绩*/for(j=0;j<COUNT;j++){b+=a[j];}printf("\n***************************************");printf("\nYour total score is :%d",b);i=0;dostatus=inportb(ctrl51);/*获取8251 TXRDY 状态*/while((status&0x01)==0);/*已准备好,则将键入的字符发送出去*/outportb(0x308,b);b=0;for(j=0;j<COUNT;j++) /*将各元素的值清零*/a[j]=0;}dostatus=inportb(0x309);/*检测8251状态,若有数据传送过来,则接收1个字符*/while((status&0x02)==0);a[i++]=inportb(0x308);printf("\nThe score of your %dth %d",i,a[i-1]);if(a[i-1]==255){clrscr();printf("\nIf you want to EXIT:press Esc!\nCONTINUE:press any key!");if((e=getche())==0x1b)/*是ESC?是,则退出,并返回DOS*/break;}}}。

相关主题