![]() |
發(fā)布時間: 2019-1-4 23:02
正文摘要:用數(shù)碼管顯示兩位數(shù),個位數(shù)顯示不出來,能幫我看看錯在哪里了 程序如下 #include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar temp,shi,ge; uch ... |
你的延時函數(shù)寫錯了。死在for循環(huán)里出不來。仔細看看 |
wulin 發(fā)表于 2019-1-5 06:54 非常感謝 |
小兄弟真是個新手,問題不少,首先你while(1)循環(huán)最后加個break,循環(huán)就跳出了,那你還加while循環(huán)干什么,白白增加程序閱讀難度; 第二,所有程序都是順序執(zhí)行的,加上紅色部分count==0時應(yīng)該沒問題,因為一個命令就回到循環(huán)了;為1時LED=0,然后等Dis2執(zhí)行一遍再循環(huán),應(yīng)該問題也不大,雖然不是正常程序?qū)懛,但?yīng)該滿足你的要求;但為2時就無法滿足了,首先執(zhí)行dis1,輸出一個脈沖后,要去執(zhí)行dis2這時LED一直是高電平,也就是你dis2執(zhí)行多長時間LED就多長時間的高電平,然后返回來繼續(xù),這樣LED和EN兩個口是交替操作的,當然不能滿足你的要求; 第三,你要在switch(count)的程序執(zhí)行完了才能回到上面的按鍵檢測,當然要等dis2執(zhí)行完才能檢測到按鍵。 |
你的U2和U3的D0~D7是不是并一起接在單片機的P0口上。 |
你的延時函數(shù)寫錯了。死在for循環(huán)里出不來。另外段碼和位碼公用P0的動態(tài)數(shù)碼管顯示要增加消隱語句,否則仿真出亂碼,實際電路有鬼影。給你改了,你試試。 #include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar temp,shi,ge; uchar code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 }; sbit dula=P2^0; sbit wela=P2^1; void delay (uint z); void main() { temp=25; while(1) { shi=temp/10; ge=temp%10; dula=1; P0=0x00; //消隱 dula=0; wela=1; P0=0xfe; wela=0; dula=1; P0=table[shi]; dula=0; delay(5); dula=1; P0=0x00; //消隱 dula=0; wela=1; P0=0xfd; wela=0; dula=1; P0=table[ge]; dula=0; delay(5); } } void delay(uint z) { uint i,j; for(i=z;i>0;i--) for(j=110;j>0;j--); } |
參與人數(shù) 1 | 黑幣 +2 | 收起 理由 |
---|---|---|
![]() | + 2 | 回帖助人的獎勵! |
Powered by 單片機教程網(wǎng)