| #include <pic.h> #define uint unsigned int #define uchar unsigned char __CONFIG(0x3B31); void delay_ms(uint); void init(); void scan(); void main() { init(); while(1) { scan(); } } void delay_ms(uint x) { uint a,b; for(a=x;a>0;x--) for(b=110;b>0;b--); } void scan() { if(RB0==0)//獨立鍵盤KEY0 { delay_ms(10); if(RB0==0) { while(!RB0);//判斷是否松開 PORTD=0x01;//LED燈第一個亮 } } if(RB1==0) { delay_ms(10); if(RB1==0) { while(!RB1); PORTD=0x02; } } if(RB2==0) { delay_ms(10); if(RB2==0) { while(!RB2); PORTD=0x04; } } if(RB3==0) { delay_ms(10); if(RB3==0) { while(!RB3); PORTD=0x08; } } } void init() { TRISB=0xff; //獨立鍵盤引腳配置 TRISD=0; //LED燈引腳配置 PORTD=0; //由于剛上電LED會無次序亮,所以先置低電平熄滅 } 請問各位大神,我這個視頻是看郭天祥視頻里寫的,為什么實現不了按一個獨立按鍵LED燈就隨著亮呢,按鍵按下燈沒反應,請問這是怎么回事,我用的是天祥電子開發板。 |
在路上1324 發表于 2015-10-8 09:13
延時函數寫錯了,無符號整形永遠大于0,進延時出不來,沒細看
在路上1324 發表于 2015-10-8 09:16
還有延時函數都寫錯了,都對傳x進行操作了,不知道你在干啥,a值一直沒變
路人甲111 發表于 2015-10-8 11:09
void delay(uint z)
{
uint i,j;
| 歡迎光臨 (http://www.raoushi.com/bbs/) | Powered by Discuz! X3.1 |