標(biāo)題: PIC獨(dú)立鍵盤的程序 各位大俠 幫幫忙 [打印本頁]

作者: 路人甲111    時(shí)間: 2015-9-29 23:08
標(biāo)題: PIC獨(dú)立鍵盤的程序 各位大俠 幫幫忙
#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    時(shí)間: 2015-10-8 09:13
延時(shí)函數(shù)寫錯(cuò)了,無符號整形永遠(yuǎn)大于0,進(jìn)延時(shí)出不來,沒細(xì)看
作者: 在路上1324    時(shí)間: 2015-10-8 09:16
在路上1324 發(fā)表于 2015-10-8 09:13
延時(shí)函數(shù)寫錯(cuò)了,無符號整形永遠(yuǎn)大于0,進(jìn)延時(shí)出不來,沒細(xì)看

還有延時(shí)函數(shù)都寫錯(cuò)了,都對傳x進(jìn)行操作了,不知道你在干啥,a值一直沒變
作者: 路人甲111    時(shí)間: 2015-10-8 11:09
在路上1324 發(fā)表于 2015-10-8 09:16
還有延時(shí)函數(shù)都寫錯(cuò)了,都對傳x進(jìn)行操作了,不知道你在干啥,a值一直沒變

void delay(uint z)
{
        uint i,j;
        for(i=z;i>0;i--)
                for(j=110;j>0;j--);
}
作者: 路人甲111    時(shí)間: 2015-10-8 11:09
路人甲111 發(fā)表于 2015-10-8 11:09
void delay(uint z)
{
        uint i,j;

怎樣子寫也實(shí)現(xiàn)不了




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1