![]() |
發(fā)布時間: 2024-11-5 10:34
正文摘要:#include <reg2051.h> void delay(unsigned int cnt) { unsigned int i; while(cnt--) { ... |
謝謝songxia8013提醒,現(xiàn)在修改如下: #include <reg2051.h> const unsigned char P1_arry[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; const unsigned char P3_arry[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07}; void delay(unsigned int cnt) { unsigned int i; while(cnt--) { for(i = 0;i < 227;i++); } } void main() { unsigned char i, j; while(1) { for(i=0;i<8;i++) { P1 = P1_arry[ i]; for(j=0;j<8;j++) { P3 = P3_arry[j]; delay(200); } } } } |
這程序?qū)懙奶L了,可以優(yōu)化下。搞個數(shù)組,然后for循環(huán)調(diào)用,很短的程序應(yīng)該就能搞定。 |
看到樓主的代碼,讓我陷入深深的回憶當(dāng)中——當(dāng)年寫匯編代碼應(yīng)該就是這樣的風(fēng)格,你是不是還沒扭轉(zhuǎn)過來![]() ![]() |
Powered by 單片機教程網(wǎng)