|
- #define uchar unsigned char
- #include<reg51.h>
- #define uint unsigned int
- #define uchar unsigned char
- void delay (uint x);
- sbit A=P1^0;
- sbit B1=P1^1;
- sbit B2=P1^2;
- sbit B3=P1^3;
- sbit dula=P2^1;
- sbit wela=P2^2;
- uchar c,i;
- unsigned char code NumDecode[] ={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,};
- void main()
- {
- TMOD=0x11;
- TH0=(65536-45872)/256;
- TH0=(65536-45872)%256;
- EA=1;
- ET0=1;
- TF0=1;
- TR0=1;
- while(1)
- {
- if(B1==0)
- {
- delay(10);
- if(B1==0)
- {
- while(B1==0)
- {
- if(c==20)//50ms中断20次
- {
- c=0;
- i++;//倒计时总数每秒减1
- }
- if(i<10)
- {
- dula=0;//数码管位选选通
- P0=NumDecode[i];//显示数据
- }
- else //循环计时设置
- {
- i=0;
- }
- }
- TR0=1;
- }
- }
- if(B2==0)
- {
- delay(10);
- if(B2==0)
- {
- while(B2==0)
- TR1=1;
- }
- }
- }
- }
- void t1() interrupt 1
- { char
- TH0=(65536-45872)/256;
- TH0=(65536-45872)%256;
-
- }
复制代码 |
|