|
- #include <reg52.h>
- sbit Button=P2^0;
- sbit LED=P1^1;
- unsigned char Time_Count;
- void Timer0Init(void) //50毫秒@12.000MHz
- {
- TMOD &= 0xF0; //設(shè)置定時(shí)器模式
- TMOD |= 0x01; //設(shè)置定時(shí)器模式
- TL0 = 0xB0; //設(shè)置定時(shí)初始值
- TH0 = 0x3C; //設(shè)置定時(shí)初始值
- TF0 = 0; //清除TF0標(biāo)志
- TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
- EA=1;
- ET0=1;
- }
- void main()
- {
- bit ButtonPrevVal,ButtonNowVal;
- Timer0Init();
- while(1)
- {
- ButtonNowVal=Button;
- if(!ButtonPrevVal && ButtonNowVal)
- {
- if(Time_Count<20){LED=!LED;}
- Time_Count=0;
- }
- ButtonPrevVal=ButtonNowVal;
- }
- }
- void timer0() interrupt 1
- {
- TL0 = 0xB0; //設(shè)置定時(shí)初始值
- TH0 = 0x3C; //設(shè)置定時(shí)初始值
- Time_Count++;
- }
復(fù)制代碼
限時(shí)雙擊.PNG (47.83 KB, 下載次數(shù): 50)
下載附件
2022-10-20 12:44 上傳
|
|