Cantafford
Member
Hello,
I'm trying to interface a 4x3 keypad with the PIC18F2580. I wrote this piece of code:
When I try to run it these errors occur:
the errors are "syntax errors" at char READ_SWITCHES(void) function(last one).
Can someone please explain me how to correct that error? Since it's a simple syntax error I suppose it should be easy to correct it but thus far I wasn't able to figure out what that syntax error was(I'm no god of programming). Thank you for reading!
I'm trying to interface a 4x3 keypad with the PIC18F2580. I wrote this piece of code:
Code:
/*
* File: main.c
* Author: Paul
*
* Created on October 1, 2015, 2:00 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include "config.c"
#define row1 PORTBbits.RB0;
#define row2 PORTBbits.RB1;
#define row3 PORTBbits.RB2;
#define row4 PORTBbits.RB3;
#define col1 PORTBbits.RB4;
#define col2 PORTBbits.RB5;
#define col3 PORTBbits.RB6;
void InitKeypad(void);
char GetKey(void);
char READ_SWITCHES(void);
void main(void)
{
char Key = 'n'; // Variable to store the pressed key value
InitKeypad();
// REMEMBER YOU HAVE TO DISPLAY THE **** ON THE 7SEGMENT DISPLAY
while(1)
{
Key = GetKey();
if(Key=='1')
{
PORTA = 0b00000001;
}
// here put some code to display the key on the lcd
// :D
}
}
// Function: InitKeypad: Initialize Keypad pins(also make 7segment display)
void InitKeypad(void)
{
TRISA = 0; // make portA output(the 7led display is here)
TRISB = 0b01110000; // R(0-3) outputs(rows) | R(4-60 inputs(columns)
INTCON2bits.NOT_RBPU = 1; // pull-ups disabled
}
// Function: GetKey: Get pressed key from keypad
char GetKey(void)
{
char Key = 'n'; // Asume no key was pressed
while(Key == 'n'); // Wait untill a key is pressed
Key = READ_SWITCHES(); // Scan the keys again and again
return Key; // when key's pressed return it's value
}
// Function: READ_SWITCHES
char READ_SWITCHES(void)
{
row1=0; row2=1; row3=1; row4=1; // Test ROW1
if(col1==0) {__delay_ms(250); while (col1==0) return '1';}
if(col2==0) {__delay_ms(250); while (col2==0) return '2';}
if(col3==0) {__delay_ms(250); while (col3==0) return '3';}
row1=1; row2=0; row3=1; row4=1; // Test ROW2
if(col1==0) {__delay_ms(250); while (col1==0) return '4';}
if(col2==0) {__delay_ms(250); while (col2==0) return '5';}
if(col3==0) {__delay_ms(250); while (col3==0) return '6';}
row1=1; row2=1; row3=0; row4=1; // Test ROW3
if(col1==0) {__delay_ms(250); while (col1==0) return '7';}
if(col2==0) {__delay_ms(250); while (col2==0) return '8';}
if(col3==0) {__delay_ms(250); while (col3==0) return '9';}
row1=1; row2=1; row3=1; row4=0; // Test ROW4
if(col1==0) {__delay_ms(250); while (col1==0) return '0';}
if(col2==0) {__delay_ms(250); while (col2==0) return '0';}
if(col3==0) {__delay_ms(250); while (col3==0) return '0';}
return 'n'; // Means no key has been pressed
}
When I try to run it these errors occur:

the errors are "syntax errors" at char READ_SWITCHES(void) function(last one).
Can someone please explain me how to correct that error? Since it's a simple syntax error I suppose it should be easy to correct it but thus far I wasn't able to figure out what that syntax error was(I'm no god of programming). Thank you for reading!