Thread: Initialising LCD with AT89C51 problem

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    3

    Initialising LCD with AT89C51 problem

    Im having problems initialisation an LCD with the AT89C51 uC. The LCD im using is HD44780u.

    The errors im getting are compilation errors, C141: syntax error near ')' and C141: syntax error near 'data'. These are near the writeChar_LCD method.

    However i dont see what the error is, any help would be appreciated. Thanks

    Code:
    /***  Include Files  *******************************************************/
    
    #include <t89c51ac3.h>
    #include "..\lib\phys340libkeil.h"
    #include <string.h>
    
    
    #define RS P4_0                    // Register Select signal
    #define EN P4_2                    // Enable signal
    #define RW P4_1                   // R/W signal
    #define LCD_DATA P0             // Data line
    
    
    /*** Functions ****************************************************/
    
    void LCD_cmd(unsigned char cmd);
    void init_LCD(void);
    void writeChar_LCD(unsigned char data);
    
    /*** Main Function ************************************************/
    
    void main()
     { 
         init_LCD();                   //initialise display
         while(1)
         {
              writeChar_LCD('h');
         }
     }        
    
    
    /*** Send Command to lcd ******************************************/
    
    
    void LCD_cmd(unsigned char cmd)
    {
         RS = 0;
         RW = 0;
         LCD_DATA = cmd;
         EN = 1;
         EN = 0;
         delaya(1000);
    }
    
    
    /*** LCD Initialisation *******************************************/
    
    void init_LCD(void)
    {
         LCD_DATA = (0x38);          //Function set, 16x2 LCD 8bit
         RS = 0;
         RW = 0;
         EN = 1;
         EN = 0;
         delaya(1000);
         
         LCD_DATA = (0x0F);           //Display on, cursor blinking 
         RS = 0;
         RW = 0;
         EN = 1;
         EN = 0;
         delaya(1000);
    
         LCD_DATA = (0x01);         //Clear LCD Screen
         RS = 0;
         RW = 0;
         EN = 1;
         EN = 0;
         delaya(1000);
         
         LCD_DATA = (0x06);         //Entry Mode
         RS = 0;
         RW = 0;
         EN = 1;
         EN = 0;
         delaya(1000);
           
    }
    
    /***  Write a single charachter to LCD  *****************************/
    
    void writeChar_LCD(unsigned char data)       <-----error here
    {
         RS = 1;
         RW = 0;
         LCD_DATA = data;                               <----error here
         EN = 1;
         EN = 0; 
         delaya(1000);
          
    }
    Attached Images Attached Images Initialising LCD with AT89C51 problem-error-1-jpg 

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Please cut and paste your error messages into a post. Your picture is almost impossible to read in my opinion.

    Jim

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    3
    Initialising LCD with AT89C51 problem-error-crop-jpg

    As you may have already see i have commented out some of the code as they were also throwing errors, but i just wanted to get the init lcd method and writeChar working first then go back to the other errors. I will place a copy of my code aswell. Thanks again.
    Attached Files Attached Files
    • File Type: c .c (2.7 KB, 133 views)
    Last edited by RVP711; 05-28-2012 at 06:28 AM.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    If I am reading the manual correctly for the Keil compiler "data" is a data type and can not be used for a variable name. It specifies that a variable should be placed in the "data" segment.

    Jim

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You've made an INCOMPLETE job of commenting out the previous function.
    Code:
    void set_LCDPOS(unsigned char pos)             
    //{
         //RS = 0;
         //if(pos < 32){
    	    //if(pos < 16){
    		   //LCD_cmd((0x80)+pos)
    		   //current_pos = pos;
    		   //}
    		//if(pos > 15){
               //LCD_cmd((0xC0)+(pos-15))
    		   //current_pos = pos;
    		   //}
    	 //}
         //else
             //do nothing
    //}
    
    /***  Write a single charachter to LCD  *****************************/
    
    void writeChar_LCD(unsigned char data)
    {
         RS = 1;
         RW = 0;
    	 LCD_DATA = data;
         EN = 1;
         EN = 0; 
         delaya(1000);
    
         current_pos++;
    
    	 //if(current_pos == 15)
    	    //set_LCDPOS(16);
         //if(current_pos == 32)
            //current_pos = 0;
    	 
    }
    If you want to comment out large blocks in future, use the #if 0 conditional, like so
    Code:
    #if 0
    void set_LCDPOS(unsigned char pos)
    {
         RS = 0;
         if(pos < 32){
            if(pos < 16){
               LCD_cmd((0x80)+pos)
               current_pos = pos;
               }
            if(pos > 15){
               LCD_cmd((0xC0)+(pos-15))
               current_pos = pos;
               }
         }
         else
             //do nothing
    }
    #endif
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    May 2012
    Posts
    3
    Thanks for the replies, i will test it with some alterations hopefully it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 04-26-2011, 03:02 AM
  2. Initialising the structure
    By rajkumarmadhani in forum C Programming
    Replies: 4
    Last Post: 04-15-2010, 04:14 AM
  3. Initialising
    By eeeeej in forum C Programming
    Replies: 24
    Last Post: 01-23-2008, 07:18 AM
  4. Initialising Arrays
    By studiesrule in forum C++ Programming
    Replies: 16
    Last Post: 10-31-2006, 08:01 AM
  5. initialising
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 12-12-2001, 05:36 PM