INT8U Key_Scan()
{
TRISB=0xF8; //
ANSELB=0x00;
PORTB=0xF8; // PORTB &= 0xF8;
nWPUEN=0;
WPUB=0xF8;
TRISA=0x60; //
LATA=0x60;
INT8U temp,the_key=-1;
temp=PORTB;
// LCD_PRINT_NUM(1,5,temp);
if(0xF8!=temp)
{
Delay(800);
// temp=PORTB;
// LCD_PRINT_NUM(1,10,temp);
// if(0xF8!=temp)
// {
LATA=0x6E;
NOP(); NOP();
temp=PORTB;
switch (temp)
{
case 0xF0:the_key=0;break; case 0xE8:the_key=1;break;
case 0xD8:the_key=2;break; case 0xB8:the_key=3;break;
case 0x78:the_key=4;break;
}
LATA=0x6D;
NOP(); NOP();
temp=PORTB;
switch (temp)
{
case 0xF0:the_key=5;break; case 0xE8:the_key=6;break;
case 0xD8:the_key=7;break; case 0xB8:the_key=8;break;
case 0x78:the_key=9;break;
}
LATA=0x6B;
NOP(); NOP();
temp=PORTB;
switch (temp)
{
case 0xF0:the_key=10;break; case 0xE8:the_key=11;break;
case 0xD8:the_key=12;break; case 0xB8:the_key=13;break;
case 0x78:the_key=14;break;
}
// TRISA=0x60; //
LATA=0x67;
NOP(); NOP();
temp=PORTB;
// LCD_PRINT_NUM(1,15,temp);
switch (temp)
{
case 0xF0:the_key=15;break; case 0xE8:the_key=16;break;
case 0xD8:the_key=17;break; case 0xB8:the_key=18;break;
case 0x78:the_key=19;break;
}
while(0xF8!=temp)
{
Delay(800);
LATA=0x60;
NOP(); NOP();
temp=PORTB;
while(0xF8!=temp)
{
Delay(800);
LATA=0x60;
NOP(); NOP();
temp=PORTB;
}
Delay(800);
}
// }
}
return the_key;
}
初学PIC.在LATA=0x67的那一段代码扫描不到按键.其他正常显示.求高手帮忙看看哪里的问题.程序还有别的问题也可以指点一下
|