syntax error

Discussion in 'Programmer's Corner' started by LAAT, May 15, 2015.

  1. LAAT

    Thread Starter New Member

    May 14, 2015
    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 (Text):
    2. #include <p18cxxx.h>
    3. #include <delays.h>
    4. #pragma config PLLDIV = 5 // (20 MHz crystal)
    5. #pragma config CPUDIV = OSC1_PLL2
    6. #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
    7. #pragma config FOSC = HSPLL_HS
    8. #pragma config WDT = OFF
    9. #pragma config LVP = OFF
    11. char buf1[16]="KEYPAD TEST";
    12. char buf2[16]="KEY: ";
    13. char keycodes[]={0,’#’,’0’,’*’,’-’,’9’,’8’,’7’,
    14. ’-’,’6’,’5’,’4’,’-’,’3’,’2’,’1’,’-’};
    16. unsigned short kp,ka,led=1,sw=1;
    17. int delay=0;
    18. char keypadread(void);
    19. char scankey(void);
    20. VOID main() {
    21. ADCON1 |= 0x0F;
    22. PORTA = TRISA = 0x00;
    23. PORTB = TRISB = 0x00;
    24. INTCON2 &= ~0x80; //conecta las resistencias pull-up al puerto B
    25. lcd_init();
    26. lcd_clear();
    27. lcd_display(1,1,buf1);
    28. Delay10KTCYx(250);
    29. lcd_clear();
    30. lcd_display(1,1,buf2);
    31. do
    32. {
    33. kp=0;
    34. do
    35. {
    36. kp = keypadread(); // Store key code in kp variable
    37. Delay10KTCYx(12);
    38. }while (!kp);
    39. ka=keycodes[kp];
    40. if(ka==’#’ && led<0x80) led=led<<1;
    41. if(ka==’*’ && led>0x01) led=led>>1;
    42. PORTD=led;
    43. lcd_clear();
    44. lcd_display(1,1,buf2);
    45. lcd_char(ka); // Print key ASCII value on LCD
    46. } while (1);
    47. }
    MapLab compile in C18 lite

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


    Apr 5, 2008

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

  3. LAAT

    Thread Starter New Member

    May 14, 2015
    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
  4. WBahn


    Mar 31, 2012
    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?
  5. JohnInTX


    Jun 26, 2012
    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 (Text):
    1. char keycodes[] = {0,'#','0','*','-', '9','8','7','-','6','5','4','-','3','2','1','-',0};
    3. if(ka=='#' && led<0x80) led=led<<1;
    4. 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.
    LAAT likes this.
  6. MrChips


    Oct 2, 2009
    For whatever reason your apostrophe is encoded in UTF-8 coding as 226 128 153.
  7. WBahn


    Mar 31, 2012
    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.
  8. LAAT

    Thread Starter New Member

    May 14, 2015
    that was the solution because, very grateful.
  9. LAAT

    Thread Starter New Member

    May 14, 2015
    thank you, that I