Hi all,
I am writing a header file to scan a keypad to determine what number has been pressed, see code below;
I am getting some errors to do with the (PORTbits.RB0==0).
Error [255] C:\Program Files (x86)\Microchip\xc8\v1.33\include\KeypadScan.h; 14.18 not a member of the struct/union ""
Error [207] C:\Program Files (x86)\Microchip\xc8\v1.33\include\KeypadScan.h; 14.21 simple type required for "=="
I am using MPLAB v8.92 with a XC8 complier (FYI)
Any ideas?
Cheers
JSwale
I am writing a header file to scan a keypad to determine what number has been pressed, see code below;
Code:
#include <xc.h>
#define _XTAL_FREQ 31250
int numberpressed;
int Scan()
{
numberpressed = 12;
while (numberpressed==12) //Starting point, there is no number 12, means its polling
{
PORTB=0b11101111; //B4 is 0, scans for 1,4,7,*
if (PORTBbits.RB0==0)
{
__delay_ms(100); //used for de-bounce purposes
while (PORTBbits.RB0==0); //waits for switch to be released
__delay_ms(100); //used for de-bounce purposes
numberpressed=1;
return numberpressed;
}
if (PORTBbits.RB1==0)
{
__delay_ms(100);
while (PORTBbits.RB1==0);
__delay_ms(100);
numberpressed=4;
return numberpressed;
}
if (PORTBbits.RB2==0)
{
__delay_ms(100);
while (PORTBbits.RB2==0);
__delay_ms(100);
numberpressed=7;
return numberpressed;
}
if (PORTBbits.RB3==0)
{
__delay_ms(100);
while (PORTBbits.RB3==0);
__delay_ms(100);
numberpressed=10;
return numberpressed;
}
PORTB=0b11011111; //B5 is 0, scans for 2,5,8,0
if (PORTBbits.RB0==0)
{
__delay_ms(100);
while (PORTBbits.RB0==0);
__delay_ms(100);
numberpressed=2;
return numberpressed;
}
if (PORTBbits.RB1==0)
{
__delay_ms(100);
while (PORTBbits.RB1==0);
__delay_ms(100);
numberpressed=5;
return numberpressed;
}
if (PORTBbits.RB2==0)
{
__delay_ms(100);
while (PORTBbits.RB2==0);
__delay_ms(100);
numberpressed=8;
return numberpressed;
}
if (PORTBbits.RB3==0)
{
__delay_ms(100);
while (PORTBbits.RB3==0);
__delay_ms(100);
numberpressed=0;
return numberpressed;
}
PORTB=0b10111111; //B6 is 0, scans for 3,6,9,#
if (PORTBbits.RB0==0)
{
__delay_ms(100);
while (PORTBbits.RB0==0);
__delay_ms(100);
numberpressed=3;
return numberpressed;
}
if (PORTBbits.RB1==0)
{
__delay_ms(100);
while (PORTBbits.RB1==0);
__delay_ms(100);
numberpressed=6;
return numberpressed;
}
if (PORTBbits.RB2==0)
{
__delay_ms(100);
while (PORTBbits.RB2==0);
__delay_ms(100);
numberpressed=9;
return numberpressed;
}
if (PORTBbits.RB3==0)
{
__delay_ms(100);
while (PORTBbits.RB3==0);
__delay_ms(100);
numberpressed=11;
return numberpressed;
}
}
}
Error [255] C:\Program Files (x86)\Microchip\xc8\v1.33\include\KeypadScan.h; 14.18 not a member of the struct/union ""
Error [207] C:\Program Files (x86)\Microchip\xc8\v1.33\include\KeypadScan.h; 14.21 simple type required for "=="
I am using MPLAB v8.92 with a XC8 complier (FYI)
Any ideas?
Cheers
JSwale