- #include<reg51.h>
- #include<stdio.h>
- unsigned int tim;
- unsigned int num=0,num0=0;
- unsigned int b,s,g;
- unsigned char code a[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- /*延时函数*/
- void delayms(unsigned int x)
- {unsigned char y;
- for(;x>0;x--)
- {for(y=0;y<128;y++)
- {;}
- }
- }
- /*子函数*/
- void gewei()
- {
- g=num%10;
- P0=0x04;
- P2=a[g];
- }
- void shiwei()
- {
- s=num/10%10;
- P0=0x02;
- P2=a[s];
- }
- void baiwei()
- {
- b=num/100%10;
- P0=0x01;
- P2=a[b];
- }
- /*主函数*/
- void main(void)
- {
- tim=65536-50000;
- EA=1;
- ET0=1;
- TMOD=0x01;
- TH0=tim/256;
- TL0=tim%256;
- TR0=1;
- IT0=1;
- IT1=1;
- EX0=1;
- EX1=1;
- while(1)
- {
- gewei();
- delayms(10);
- shiwei();
- delayms(10);
- baiwei();
- delayms(10);
- }
- }
- /*定时中断*/
- void time() interrupt 1
- {
- TH0=tim/256;
- TL0=tim%256;
- if(++num0>=20)
- {
- num0=0;
- num++;
- if(num>999)
- num=0;
- }
- }
- /*清零*/
- void int0() interrupt 0
- {
- num0=0;
- num=0;
- }
复制代码
|