syntax error

Thread Starter

LAAT

Joined May 14, 2015
10
Hello everyone, help me to correct this code ...
I have a syntax error but do not know why, I see nothing wrong with it.
Code:
#include <p18cxxx.h>
#include <delays.h>
#pragma config PLLDIV = 5 // (20 MHz crystal)
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config WDT = OFF
#pragma config LVP = OFF

char buf1[16]="KEYPAD TEST";
char buf2[16]="KEY: ";
char keycodes[]={0,’#’,’0’,’*’,’-’,’9’,’8’,’7’,
’-’,’6’,’5’,’4’,’-’,’3’,’2’,’1’,’-’};

unsigned short kp,ka,led=1,sw=1;
int delay=0;
char keypadread(void);
char scankey(void);
VOID main() {
ADCON1 |= 0x0F;
PORTA = TRISA = 0x00;
PORTB = TRISB = 0x00;
INTCON2 &= ~0x80; //conecta las resistencias pull-up al puerto B
lcd_init();
lcd_clear();
lcd_display(1,1,buf1);
Delay10KTCYx(250);
lcd_clear();
lcd_display(1,1,buf2);
do
{
kp=0;
do
{
kp = keypadread(); // Store key code in kp variable
Delay10KTCYx(12);
}while (!kp);
ka=keycodes[kp];
if(ka==’#’ && led<0x80) led=led<<1;
if(ka==’*’ && led>0x01) led=led>>1;
PORTD=led;
lcd_clear();
lcd_display(1,1,buf2);
lcd_char(ka); // Print key ASCII value on LCD
} while (1);
}
MapLab compile in C18 lite

error line 12 (char keycodes[]={0,’#’,’0’,’*’,’-’,’9’,’8’,’7’,’-’,’6’,’5’,’4’,’-’,’3’,’2’,’1’,’-’};
)
 

bertus

Joined Apr 5, 2008
22,277
Hello,

I do not have any programming experience, but must the keycodes array be declared?
Also the first 0 has no quotes, it this intentional?

Bertus
 

Thread Starter

LAAT

Joined May 14, 2015
10
Hello,

I do not have any programming experience, but must the keycodes array be declared?
Also the first 0 has no quotes, it this intentional?

Bertus
I believe that zero is the space provided to not overwrite within the chain, the code is for a keyboard matrix which yields the values on a LED screen lm016
 

WBahn

Joined Mar 31, 2012
30,058
What have you done to try to find out what there error is and isn't?

Have you tried explicitly stating how large the array is?

Have you tried putting the initialization information all on one line?

Have you tried putting in the line-continuation directive?
 

JohnInTX

Joined Jun 26, 2012
4,787
It's because the character definitions use some goofy char for the apostrophe in the ' x' values. It would not compile for me either and took a bit to figure that out. Here are the lines fixed for you:
Code:
char keycodes[] = {0,'#','0','*','-', '9','8','7','-','6','5','4','-','3','2','1','-',0};

if(ka=='#' && led<0x80) led=led<<1;
if(ka=='*' && led>0x01) led=led>>1;
I have no idea what the char value for the apostrophe in your original code is but its not ASCII. Just for future reference, sometimes goofy or hidden characters get into a statement - I've had to delete lines and retype them to fix it. The teltale is something that looks perfect on the screen but stubbornly refuses to compile. Go figure.

In MPLABX such things are easier to identify because they won't show up in the correct color in the syntax-aware editor. That was the tipoff for me.

BTW: be sure to specify which PIC you are using when you post code. Easier to load into MPLAB for test compiles.
 

WBahn

Joined Mar 31, 2012
30,058
It's hard to tell where the wonky encoding came from. If the TS's code was copied from some place, such as an internet source, then it was very possibly copied in Unicode and pasted into his source code that way. But it is also possible that it is fine in his source code and code converted to Unicode when he copied and pasted it into his post here.

But a good way to make the issue go a way is to do as JohnInTX suggested which is to just delete it and type in in fresh.
 

Thread Starter

LAAT

Joined May 14, 2015
10
It's because the character definitions use some goofy char for the apostrophe in the ' x' values. It would not compile for me either and took a bit to figure that out. Here are the lines fixed for you:
Code:
char keycodes[] = {0,'#','0','*','-', '9','8','7','-','6','5','4','-','3','2','1','-',0};

if(ka=='#' && led<0x80) led=led<<1;
if(ka=='*' && led>0x01) led=led>>1;
I have no idea what the char value for the apostrophe in your original code is but its not ASCII. Just for future reference, sometimes goofy or hidden characters get into a statement - I've had to delete lines and retype them to fix it. The teltale is something that looks perfect on the screen but stubbornly refuses to compile. Go figure.

In MPLABX such things are easier to identify because they won't show up in the correct color in the syntax-aware editor. That was the tipoff for me.

BTW: be sure to specify which PIC you are using when you post code. Easier to load into MPLAB for test compiles.
that was the solution because, very grateful.
 

Thread Starter

LAAT

Joined May 14, 2015
10
thank you, that I
It's hard to tell where the wonky encoding came from. If the TS's code was copied from some place, such as an internet source, then it was very possibly copied in Unicode and pasted into his source code that way. But it is also possible that it is fine in his source code and code converted to Unicode when he copied and pasted it into his post here.

But a good way to make the issue go a way is to do as JohnInTX suggested which is to just delete it and type in in fresh.
 
Top