#include<reg52.h> #defineuint unsigned int uinttemp,qian,bai,shi,ge,aa,n; sbitdula=P0; sbitwela=P1; sbitzd=P3^2; uint codetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
voiddisplay(uint qian,uint bai,uint shi,uint ge); void delay(uint z); voidinit();
void main() { EA=1;//开总中断 EX0=1;//开外部中断0 init();//初始化子程序 while(1) { display(qian,bai,shi,ge); } }
voiddelay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); }
voiddisplay(uint qian,uint bai,uint shi,uint ge) { P0=table[qian]; P1=0xf7; delay(1);
P0=table[bai]; P1=0xfb; delay(1);
P0=table[shi]; P1=0xfd; delay(1);
P0=table[ge]; P1=0xfe; delay(1); }
voidexter0() interrupt 0 { n++; while(zd==0); }
void init() { wela=0; dula=0; temp=0; TMOD=0x01; TCON|=0X04; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; }
timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; aa++; if(aa==20) { aa=0; temp=20*n; n =0; qian=temp/1000; bai=temp%1000/100; shi=temp%100/10; ge=temp%10; } }
下载:http://www.51hei.com/bbs/dpj-89319-1.html
|