![]() |
發(fā)布時間: 2023-11-6 01:58
正文摘要:實現(xiàn)按鍵檢測功能,0-F按鍵中有一個按鍵按下,數(shù)碼管顯示對應(yīng)的字符,并且LED0-7顯示對應(yīng)的二進(jìn)制字節(jié)。自己寫的代碼有問題 在2樓 |
man1234567 發(fā)表于 2023-11-6 08:13 感謝大佬指正 |
標(biāo)點(diǎn)錯的地方太多了。![]() #include<reg51.h> #define uchar unsigned char sbit L1=P1^0; sbit L2=P1^1; sbit L3=P1^2; sbit L4=P1^3; uchar dis[16]={0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; unsigned int time; void delay(time) { unsigned int j; for(j=0;j<time;j++); } main() { uchar temp; uchar i; while(1) { P1=0xef; for(i=0;i<=3;i=i++) { if (L1==0) P0= dis[i*4+0]; if (L2==0) P0= dis[i*4+1]; if (L3==0) P0= dis[i*4+2]; if (L4==0) P0= dis[i*4+3]; delay(500); temp=P1; temp=temp|0x0f; temp=temp<<1; temp=temp|0x0f; P1=temp; } } } |
把
改為
|
#include<reg51.h> #define uchar unsigned char sbit L1=P1^0; sbit L2=P1^1; sbit L3=P1^2; sbit L4=P1^3; uchar dis[16]={0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; unsigned int time; void delay(time) { unsigned int j; for(j=0;j<time;j++) {} } void main() { uchar temp; uchar k,i; while(1) { P1=0xef; for(i=0;i<=3;i=i++) { if (L1==0) P0= dis[i*4+0]; if (L2==0) P0= dis[i*4+1]; if (L3==0) P0= dis[i*4+2]; if (L4==0) P0= dis[i*4+3]; delay(500); temp=P1; temp=temp|0x0f; temp=temp<<1; temp=temp|0x0f; P1=temp; } } } 已進(jìn)行修改,可通過編譯,不保證運(yùn)行。 主要問題:符號錯亂,包括但不限于丟失、全角、錯用等。 個人感覺:搞科研的如果不細(xì)心不如不做,不喜歡自己檢查的不如不玩。 |
P0沒上拉電阻 |
我自己寫了個代碼,但是為什么運(yùn)行出來不對,有兩個警報 #include<reg51.h>, #define uchar unsigned char sbit L1=P1^0; sbit L2=P1^1; sbit L3=P1^2; sbit L4=P1^3; uchar dis[16]={0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,oxa1,0x86.0x8e}; unsigned int time; delay(time) { unsigned int j; for(j=0;j<time;j++) {} } main() { uchar temp; uchar k,i; while(1) { P1=0xef; for(i=0;i<=3;i=i++) { if (L1==0) P0= dis[i*4+0]; if (L2==0) P0= dis[i*4+1]; if (L3==0) P0= dis[i*4+2]; if (L4==0) P0= dis[i*4+3]; delay(500) temp=P1; temp=temp|0x0f; temp=temp<<1; temp=temp|0x0f; P1=temp; } } } |
Powered by 單片機(jī)教程網(wǎng)