熱門(mén): 51單片機(jī) | 24小時(shí)必答區(qū) | 單片機(jī)教程 | 單片機(jī)DIY制作 | STM32 | Cortex M3 | 模數(shù)電子 | 電子DIY制作 | 音響/功放 | 拆機(jī)樂(lè)園 | Arduino | 嵌入式OS | 程序設(shè)計(jì)
![]() |
發(fā)布時(shí)間: 2023-11-6 01:58
正文摘要:實(shí)現(xiàn)按鍵檢測(cè)功能,0-F按鍵中有一個(gè)按鍵按下,數(shù)碼管顯示對(duì)應(yīng)的字符,并且LED0-7顯示對(duì)應(yīng)的二進(jìn)制字節(jié)。自己寫(xiě)的代碼有問(wèn)題 在2樓 |
man1234567 發(fā)表于 2023-11-6 08:13 感謝大佬指正 |
標(biāo)點(diǎn)錯(cuò)的地方太多了。![]() #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)行修改,可通過(guò)編譯,不保證運(yùn)行。 主要問(wèn)題:符號(hào)錯(cuò)亂,包括但不限于丟失、全角、錯(cuò)用等。 個(gè)人感覺(jué):搞科研的如果不細(xì)心不如不做,不喜歡自己檢查的不如不玩。 |
P0沒(méi)上拉電阻 |
我自己寫(xiě)了個(gè)代碼,但是為什么運(yùn)行出來(lái)不對(duì),有兩個(gè)警報(bào) #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)