单片机原理及系统课程设计报告
附录 源程序代码
#include
unsigned char code time[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char cont=0,shi,ge,i; unsigned char T; //答题时间 void inter() interrupt 1 {
TH0=(65536-50000)/256; TL0=(65536-50000)%6; cont++; }
main() {
while(1) {
// 1.待机阶段 while( start==1 ) { S=1; G=0; P0=time[0]; for( i=0 ; i<100 ; i++ ) ; P0=0xff; S=0; G=1; P0=time[0]; for( i=0 ; i<100 ; i++ ) ; P0=0xff; } // 2.抢答阶段 while(1) { // 1).开始抢答
6
单片机原理及系统课程设计报告
ans=0; // 判断那个选手抢到题 while(1) { if ( p1==0 ) { light1=0; break; } if ( p2==0 ) { light2=0; break; } } // 禁止其他选手再选题 while( please==1 ) ; // 2).开始答题 ans=1; T=6; TMOD=0x01;
TH0=(65536-50000)/256; TL0=(65536-50000)%6; EA=1; ET0=1; TR0=1;
while( T<200&&stop==1 ) { shi=T/10; ge=T; S=1; G=0; P0=time[shi]; for( i=0 ; i<100 ; i++ ) ; P0=0xff; S=0; G=1; P0=time[ge]; for( i=0 ; i<100 ; i++ ) ; P0=0xff; if ( cont>20 ) { cont=0;T--; }
7
单片机原理及系统课程设计报告
}
// 3).停止答题 P3=0xff; break; } } }
8