#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)//獨(dú)立鍵盤KEY0 { delay_ms(10); if(RB0==0) { while(!RB0);//判斷是否松開 PORTD=0x01;//LED燈第一個(gè)亮 } } 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; //獨(dú)立鍵盤引腳配置 TRISD=0; //LED燈引腳配置 PORTD=0; //由于剛上電LED會(huì)無次序亮,所以先置低電平熄滅 } 請問各位大神,我這個(gè)視頻是看郭天祥視頻里寫的,為什么實(shí)現(xiàn)不了按一個(gè)獨(dú)立按鍵LED燈就隨著亮呢,按鍵按下燈沒反應(yīng),請問這是怎么回事,我用的是天祥電子開發(fā)板。 |
在路上1324 發(fā)表于 2015-10-8 09:13
延時(shí)函數(shù)寫錯(cuò)了,無符號整形永遠(yuǎn)大于0,進(jìn)延時(shí)出不來,沒細(xì)看
在路上1324 發(fā)表于 2015-10-8 09:16
還有延時(shí)函數(shù)都寫錯(cuò)了,都對傳x進(jìn)行操作了,不知道你在干啥,a值一直沒變
路人甲111 發(fā)表于 2015-10-8 11:09
void delay(uint z)
{
uint i,j;
歡迎光臨 (http://www.torrancerestoration.com/bbs/) | Powered by Discuz! X3.1 |