+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Full Member level 4
    Points: 2,026, Level: 10

    Join Date
    Nov 2011
    Location
    india
    Posts
    215
    Helped
    2 / 2
    Points
    2,026
    Level
    10

    LCD Display program in C

    Hello
    I am using AT89c51 microcntroller and Keil compiler. when I build code I am getting error
    Code:
    #include<reg51.h>
    #define LCDPORT P1
    #define RS P2_0
    #define RW P2_1
    #define E P2_3
    bit status=0
    #define lcd_delay 60
    void delay(unsigned int j)
    {
    unsigned int i,k;
    for(i=0;i<j;i++);
    
    for(k=0;k<100;k++);
    
    }
    void _lcd_init_write(unsigned char a)
    {
    RS = 0;
    RW = 0;
    LCDPORT=a;
    E=1;
    delay(lcd_delay);
    E=0;
    }
    void lcd_com(unsigned char a){
    unsigned char temp;
    if(status){
    status=0;
    goto a;
    }
    RS=0;
    a:
    RW=0;
    temp=a;
    temp&=0xF0;
    LCDPORT&=0x0F;
    LCDPORT|=temp;
    E=1;
    delay(lcd_delay);
    E=0;
    temp=a<<4;
    temp&=0xF0;
    LCDPORT&=0x0F;
    LCDPORT|=temp;
    E=1;
    delay(lcd_delay);
    E=0;
    }
    void lcd_data(unsigned char a){
    status=1;
    RS=1;
    lcd_com(a);
    }
    void lcd_init(void){
    delay(lcd_delay);
    _lcd_init_write(0x30);
    delay(lcd_delay);
    _lcd_init_write(0x30);
    delay(lcd_delay);
    _lcd_init_write(0x30);
    delay(lcd_delay);
    _lcd_init_write(0x20);
    delay(lcd_delay);
    lcd_com(0x28);
    delay(lcd_delay);
    lcd_com(4);
    delay(lcd_delay);
    lcd_com(0x85);
    delay(lcd_delay);
    lcd_com(6);
    delay(lcd_delay);
    lcd_com(1);
    delay(lcd_delay);
    }
    void lcd_puts(char *aaa)
    {
    unsigned int i=0;
    for(;aaa[i]!=0;i++)lcd_data(aaa[i]);
    }
    Error Message
    compiling display.c...
    display.c(8): error C141: syntax error near 'void'
    display.c(9): error C141: syntax error near '{'
    display.c(11): error C141: syntax error near 'for'
    display.c(11): error C141: syntax error near '=', expected ')'
    display.c(11): error C129: missing ';' before '<'
    display.c - 5 Error(s), 0 Warning(s).
    why I am getting this error. how to remove error ?

    •   Alt15th May 2017, 05:57

      advertising

        
       

  2. #2
    Member level 4
    Points: 1,080, Level: 7
    Altaero's Avatar
    Join Date
    Dec 2013
    Location
    St-Petersburg, Russia
    Posts
    78
    Helped
    24 / 24
    Points
    1,080
    Level
    7

    Re: LCD Display program in C

    This type of errors occurs when you miss syntax (not putting a semicolon, putting it in the wrong place etc). So when you get this error, look for it just BEFORE the error statement, in your case before 'void'.
    At first I thought about reg51.h file, but then I saw the line among the defines:
    Code C - [expand]
    1
    
    bit status=0
    As it's a variable definition, regular c-code, it must ends with a semicolon.

    Although C allows placing #define anywhere in the code, it's a good practise to place them in the beginning, and surely not mix them with c-code. It is more readable.
    And make lcd_delay with capitalized letters, again, it's more readable.



--[[ ]]--