K1K2分别控制定时器T0
#includesbit Beep = P1^0;sbit Led = P1^1;sbit K1 = P2^0;sbit K2 = P2^1;void ConfigTimer(){TMOD = 0x11;TH1 = 0xFC;TL1 = 0c18;TH0 = 0xFC;TL0 = 0x18;ET0 = 1;ET1 = 1;EA = 1;}void delay(int z){int i,j;for(i=0; i= 1000){Led = ~Led;t = 0;}}我刚写出来,,没有试验,你编译下,更改引脚定义,试试,,应该是可以的 #includesbit Beep = P1^0;sbit ...全部
#includesbit Beep = P1^0;sbit Led = P1^1;sbit K1 = P2^0;sbit K2 = P2^1;void ConfigTimer(){TMOD = 0x11;TH1 = 0xFC;TL1 = 0c18;TH0 = 0xFC;TL0 = 0x18;ET0 = 1;ET1 = 1;EA = 1;}void delay(int z){int i,j;for(i=0; i= 1000){Led = ~Led;t = 0;}}我刚写出来,,没有试验,你编译下,更改引脚定义,试试,,应该是可以的 #includesbit Beep = P1^0;sbit Led = P1^1;sbit K1 = P2^0;sbit K2 = P2^1;void ConfigTimer(){ TMOD = 0x11; TH1 = 0xFC; TL1 = 0x18; TH0 = 0xFC; TL0 = 0x18; ET0 = 1; ET1 = 1; TR0 = 0; TR1 = 0; EA = 1;}void key1_scan()//按键扫描函数{ static unsigned int uiKeyTimeCnt1 = 0; static bit ucKeyLock1 = 0; if(K1==1) { ucKeyLock1=0; uiKeyTimeCnt1=0; } else if(ucKeyLock1==0) { uiKeyTimeCnt1; if(uiKeyTimeCnt1>500) { uiKeyTimeCnt1=0; ucKeyLock1=1; TR0 =~TR0; } }}void key2_scan()//按键扫描函数{ static unsigned int uiKeyTimeCnt2 = 0; static bit ucKeyLock2 = 0; if(K2==1) { ucKeyLock2=0; uiKeyTimeCnt2=0; } else if(ucKeyLock2==0) { uiKeyTimeCnt2; if(uiKeyTimeCnt2>500) { uiKeyTimeCnt2=0; ucKeyLock2=2; TR1 =~TR1; } }}void main(){ ConfigTimer(); while(1) { key2_scan(); key1_scan(); }}仿真通过了,你拿到程序有问题,自己也可以改改啊,又不是大问题。
。。 中断服务程序没有变,按键程序更改了一下,。收起