![]() |
發(fā)布時間: 2017-8-30 11:46
正文摘要:利用兩個按鍵模擬傳感器計數(shù)為a和b,當(dāng)a大于b是亮一個燈,a等于b時亮另一個燈。 道理我懂,但是為什么程序?qū)懗鰜砗蠓抡鎱s不計數(shù)呢?請各位大神幫忙看一下應(yīng)該怎么改 #include<reg51.h> #define uchar uns ... |
看看3333 |
太感謝了 |
應(yīng)先學(xué)些基礎(chǔ)理論,才能事半功倍。 |
定時器工作模式設(shè)置不對。“TMOD=0x66”,計數(shù)器也沒有設(shè)置初值,即便你的程序其他地方?jīng)]問題,你按按鍵也要按65536次才能產(chǎn)生中斷,a或b才會加1。 大概你是想每按一次按鍵“a”或“b”增加“1”,你可以不用中斷,如:a=TL0 和b=TL1 。 程序還有許多問題,你自己實(shí)踐中提高吧。 |
參與人數(shù) 1 | 黑幣 +50 | 收起 理由 |
---|---|---|
![]() | + 50 | 回帖助人的獎勵! |
上面我改了外部中斷的語句: EX0=1; EX1=1; IT1=1; IT0=1; |
我也沒測試過呀具體不太懂 |
#include<reg51.h> #define uchar unsigned char #define uint unsigned int sbit out1=P1^0; sbit out2=P1^1; uint a=0,b=0; void delay(uchar c) { uchar i; while(c--)for(i=0;i<120;i++); } void int0() interrupt 0 { a++; } void int1() interrupt 2 { b++; } main() { EX0=1; EX1=1; IT1=1; IT0=1; EA=1; while(1) { if(a>b)out1=0; if(a==b) { delay(200); out2=0; } }} |
Powered by 單片機(jī)教程網(wǎng)