|
- #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++;//倒計(jì)時(shí)總數(shù)每秒減1
- }
- if(i<10)
- {
- dula=0;//數(shù)碼管位選選通
- P0=NumDecode[i];//顯示數(shù)據(jù)
- }
- else //循環(huán)計(jì)時(shí)設(shè)置
- {
- 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;
-
- }
復(fù)制代碼 |
-
捕獲.PNG
(123.09 KB, 下載次數(shù): 31)
下載附件
2018-6-3 11:07 上傳
|