#include "reg51.h" #include "intrins.h"
unsigned char code SMG_CODE[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阴数码管“0”“1”“2”“3”“4”“5”“6”“7”“8”“9” sbit AnJan_1=P1^0; sbit AnJan_2=P1^1; sbit AnJan_3=P1^2; sbit AnJan_4=P1^3; sbit AnJan_5=P1^4; sbit AnJan_6=P1^5; sbit AnJan_7=P1^6; sbit AnJan_8=P1^7;
sbit start=P3^1; //开始键 sbit reset=P3^2; //复位键
sbit BZ=P3^0; //蜂鸣器
char i,a,state=0;
void Yanshi10ms(unsigned int m) //误差0us { unsigned char j,h; for(;m>0;m--) for(h=38;h>0;h--) for(j=130;j>0;j--); }
void main() { BZ=1; TMOD=0x01; //定时器0方式1 TH1=(65536-50000)/256; //恢复定时器1初值 TL1=(65536-50000)%256; EA=1; P0=0x00; while (1) { while(state==0) { if(start==0) { Yanshi10ms(1); if(start==0) { P0 = 0x40; BZ=0; ET1=1;TR1=1; a=0; state=1; while(start==0); } } }
while(state==1) { if(AnJan_1==0) { P0 = SMG_CODE[1]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_2==0) { P0 = SMG_CODE[2]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_3==0) { P0 = SMG_CODE[3]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_4==0) { P0 = SMG_CODE[4]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_5==0) { P0 = SMG_CODE[5]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_6==0) { P0 = SMG_CODE[6]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_7==0) { P0 = SMG_CODE[7]; BZ=0; ET1=1;TR1=1; state=2; }
if(AnJan_8==0) { P0 = SMG_CODE[8]; BZ=0; ET1=1;TR1=1; state=2; }
if(reset==0) { state=0; P0=SMG_CODE[17]; BZ=1; break; } }
while(state==2) { if(reset==0) { state=0; BZ=1; P0=SMG_CODE[17]; break; } }
} }
void Dingshiqi1() interrupt 3 { TH1=(65536-50000)/256; TL1=(65536-50000)%256; a++; if(a>=20) { ET1=0;TR1=0; a=0; BZ=1; } }
|