EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / CHECK OUT MY C PROGRAM ON LCD AS THERE IS LITTLE MISTAKE

CHECK OUT MY C PROGRAM ON LCD AS THERE IS LITTLE MISTAKE

|

Microcontroller › 8051 › CHECK OUT MY C PROGRAM ON LCD AS THERE IS LITTLE MISTAKE

  • This topic has 14 replies, 9 voices, and was last updated 9 years, 2 months ago by justin.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • April 6, 2011 at 8:02 pm #3831
    SaLMAN Ahmed Khan
    Participant
    THIS IS MY PROG THAT I HAVE MAKE FOR MY OWN PRACTICE BUT KEIL IS GIVING ERROR THAT I HAVE MENTIONED IN THE LAST KINDLY PLEASE QUOTE ME MY MISTAKE THAT IM DOING IN THIS PROGRAM
     
     
    #include <reg51.h>
    sfr ldata=0x90;
    sbit rs=P2^0;
    sbit rw=P2^1;
    sbit en=P2^2;
    void main()
    {
    lcd_cmd(0x38);
    MSdelay(250);
    lcd_cmd(0x0E);
    MSdelay(250);
    lcd_cmd(0x1);
    MSdelay(250);
    lcd_cmd(0x06);
    MSdelay(250);
    lcd_cmd(0x86);
    MSdelay(250);
    lcd_data('M');  // DATA 
    MSdelay(250);
    lcd_data('D');
    MSdelay(250);
    lcd_data('E');
    }
    void lcd_cmd(unsigned char value)
    {
    ldata=value;
    rs=0;
    rw=0;
    en=1;
    MSdelay(1);
    en=0;
    return;
    }
     
    void lcd_data(unsigned char value)
    {
    ldata=value;
    rs=1;
    rw=0;
    en=1;
    MSdelay(1);
    en=0;
    return;
    }
    void MSdelay(unsigned int itime)
    {
    unsigned int i,j;
    for(i=0; i<itime; i++)
    for (j=0; j<1275; j++);
    }
     
     
     
     
     
     
     

     

    April 7, 2011 at 2:10 am #5915
    romel emperado
    Participant

    can you pls post the error.. :)

    April 11, 2011 at 7:31 pm #5944
    SaLMAN Ahmed Khan
    Participant

     

     
    ERROR!!!!!::
     
    Build target ‘Target 1’
    compiling lcda.c…
    LCDA.C(8): warning C206: ‘lcd_cmd’: missing function-prototype
    LCDA.C(8): error C267: ‘lcd_cmd’: requires ANSI-style prototype
    Target not created
     
    April 11, 2011 at 9:46 pm #5945
    romel emperado
    Participant

    here’s working example of code I am using..

     

     

    // 4 bit example

    #include<reg51.h>

    #define LCD P1
    #define LCD_EN        0x80
    #define LCD_RS        0x20
                        
    //LCD Commands       

    #define LCD_SETMODE       0x04
    #define LCD_SETVISIBLE       0x08
    #define LCD_SETFUNCTION       0x28
    #define LCD_SETDDADDR       0x80

    void delayms(unsigned char);
    void delayus(unsigned char);
    void lcd_init();
    void lcd_reset();
    void lcd_cmd (char);
    void lcd_data(unsigned char);
    void lcd_str (unsigned char*);

    void  main (void)
    {
    lcd_init();
    lcd_cmd(0x80);            // ist line address
    lcd_str(”     i love  “);
    lcd_cmd(0xC0);              // 2nd line address
    lcd_str(“romel”);
    while(1);
    }

    void delayus(unsigned char delay){
        while(delay–);
    }

    void delayms(unsigned char delay){
        while(delay–)
            delayus(149);
    }

    void lcd_reset()
    {
        LCD = 0xFF;
        delayms(40);
        LCD = 0x03+LCD_EN;
        LCD = 0x03;
        delayms(40);
        LCD = 0x03+LCD_EN;
        LCD = 0x03;
        delayms(5);
        LCD = 0x03+LCD_EN;
        LCD = 0x03;
        delayms(5);
        LCD = 0x02+LCD_EN;
        LCD = 0x02;
        delayms(5);
    }

    void lcd_init ()
    {
        lcd_reset();
        lcd_cmd(LCD_SETFUNCTION);                    // 4-bit mode – 1 line – 5×7 font.
        lcd_cmd(LCD_SETVISIBLE+0x04);                // Display no cursor – no blink.
        lcd_cmd(LCD_SETMODE+0x02);                   // Automatic Increment – No Display shift.
        lcd_cmd(LCD_SETDDADDR);                      // Address DDRAM with 0 offset 80h.
     }

     void lcd_cmd (char cmd)
    {
        LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
        LCD = ((cmd >> 4) & 0x0F);

        LCD = (cmd & 0x0F)|LCD_EN;
        LCD = (cmd & 0x0F);

        delayus(250);
        delayus(250);
    }

    void lcd_data (unsigned char dat)
    {
        LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
        LCD = (((dat >> 4) & 0x0F)|LCD_RS);
       
        LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
        LCD = ((dat & 0x0F)|LCD_RS);

        delayus(250);
        delayus(250);
    }

    void lcd_str (unsigned char *str)
    {
        while(*str){
            lcd_data(*str++);
        }
    }

    April 12, 2011 at 3:19 pm #5948
    SaLMAN Ahmed Khan
    Participant

    but what specific error it has why it is giving????

     

    April 12, 2011 at 3:29 pm #5949
    romel emperado
    Participant
    WARNING 206: MISSING FUNCTION PROTOTYPE

    ANSWER

    The called function is unknown because no prototype declaration exists. Calls to unknown functions risk that the number of parameters may not correspond to the actual requirements. If this is the case, the function is called incorrectly.

    The compiler has no way to check for missing or excessive parameters and their types. Include prototypes of the functions used in your program. Prototypes must be specified before the functions are actually called. The definition of a function automatically produces a prototype.

     

     

     

    Error C267: 'function': requires ANSI-style prototype

    What does this message mean?

    ANSWER

    This error message indicates that the function you are defining was prototyped with an empty parameter list but the definition includes parameters. Your function prototypes must match your function definitions. Find the prototype and either remove it or update it so that its arguments match that of the definition and everything will work OK.

    April 12, 2011 at 3:30 pm #5950
    romel emperado
    Participant

    use my code instead.. :)

    April 13, 2011 at 3:59 am #5953
    piyush
    Participant

     

    simply copy and paste below three function above main

     

    void lcd_cmd(unsigned char value);

    void lcd_data(unsigned char value);
    void MSdelay(unsigned int itime);
     
     
    smiley
    June 30, 2011 at 3:39 am #6396
    PRATYUSH TRIPATHI
    Participant

    hey i have got a very simple solution……

    just copy and paste the following statements(ANSI prototype)…….

     

    lcdcmd(unsigned char value);
    MSDelay(unsigned int value);
    lcddata(unsigned char value);
    but make sure that the function you have defined must include the contents of prototype statement.
    example:
    #include<reg51.h>
    lcdcmd(unsigned char value);
    MSDelay(unsigned int value);
    lcddata(unsigned char value);
    void main()
    {
    .
    .
    .
    .
    .
    .
    }
    functions:
    lcdcmd(unsigned char value);
    {
    rs=0;
    rw=0;
    en=1;
    MSDelay(200);
    en=0;
    }
    lcddata(unsigned char value);
    {
    …..
    }
    MSDelay(unsigned int value);
    {
    ………….
    }
     
    July 1, 2011 at 11:30 am #6405
    SaLMAN Ahmed Khan
    Participant

    @ thripati 

     

    ur solution is better :)

    March 31, 2012 at 4:33 pm #7368
    harpreet khanuja
    Participant

     

    I AM ENCOUNTER SAME ERROR..PLEASE HELP
     
     
     
    GOLDITEMP.C(65): warning C206: ‘Lcd_Out’: missing function-prototype
    GOLDITEMP.C(65): error C267: ‘Lcd_Out’: requires ANSI-style prototype
     
     
     
     
    #include<reg51.h>
    #include<stdlib.h>
     
     
    //void lcd_data(unsigned char value);
     
    // LCD module connections
    sbit LCD_RS = P2^0;
    sbit LCD_EN = P2^1;
     
    sbit LCD_D4 = P2^2;
    sbit LCD_D5 = P2^3;
    sbit LCD_D6 = P2^4;
    sbit LCD_D7 = P2^5;
    // End LCD module connections
     
    // OneWire pinout
    sbit OW_Bit = P1^2;
    // end OneWire definition
     
     
    //  Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
    //  18S20: 9  (default setting; can be 9,10,11,or 12)
    //  18B20: 12
    const unsigned short TEMP_RESOLUTION = 9;
     
    char *text = “000.0000”;
    unsigned temp;
     
    void Display_Temperature(unsigned int temp2write) {
      const unsigned short RES_SHIFT = TEMP_RESOLUTION – 8;
      char temp_whole;
      unsigned int temp_fraction;
     
      // check if temperature is negative
      if (temp2write & 0x8000) {
        text[0] = ‘-‘;
        temp2write = ~temp2write + 1;
      }
     
      // extract temp_whole
      temp_whole = temp2write >> RES_SHIFT ;
     
      // convert temp_whole to characters
      if (temp_whole/100)
         text[0] = temp_whole/100  + 48;
      else
         text[0] = ‘0’;
     
      text[1] = (temp_whole/10)%10 + 48;             // Extract tens digit
      text[2] =  temp_whole%10     + 48;             // Extract ones digit
     
      // extract temp_fraction and convert it to unsigned int
      temp_fraction  = temp2write << (4-RES_SHIFT);
      temp_fraction &= 0x000F;
      temp_fraction *= 625;
     
      // convert temp_fraction to characters
      text[4] =  temp_fraction/1000    + 48;         // Extract thousands digit
      text[5] = (temp_fraction/100)%10 + 48;         // Extract hundreds digit
      text[6] = (temp_fraction/10)%10  + 48;         // Extract tens digit
      text[7] =  temp_fraction%10      + 48;         // Extract ones digit
     
      // print temperature on LCD
      Lcd_Out(2, 5, text);
    }
     
    void main() {
     
      Lcd_Init();                                    // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR);                           // Clear LCD
      Lcd_Cmd(_LCD_CURSOR_OFF);                      // Turn cursor off
      Lcd_Out(1, 1, ” Temperature:   “);
      // Print degree character, ‘C’ for Centigrades
      Lcd_Chr(2,13,223);  // different LCD displays have different char code for degree
                          // if you see greek alpha letter try typing 178 instead of 223
     
      Lcd_Chr(2,14,’C’);
     
      //— main loop
      do {
        //— perform temperature reading
        Ow_Reset();                                  // Onewire reset signal
        Ow_Write(0xCC);                              // Issue command SKIP_ROM
        Ow_Write(0x44);                              // Issue command CONVERT_T
        Delay_us(120);
     
        Ow_Reset();
        Ow_Write(0xCC);                              // Issue command SKIP_ROM
        Ow_Write(0xBE);                              // Issue command READ_SCRATCHPAD
     
        temp =  Ow_Read();
        temp = (Ow_Read() << 8) + temp;
     
        //— Format and display result on Lcd
        Display_Temperature(temp);
     
        Delay_ms(500);
      } while (1);
    }
     
    April 12, 2012 at 3:41 pm #7427
    lalchand
    Participant

    lalchand oad 10ES30 Quaid e awam university of engineering science and technology nawabshah sindh pakistan           

     

    First define funtions befor void main() as  :

     

    #include <reg51.h>
    void lcd_cmd(unsigned char value);
    void MSdelay(unsigned int itime);
    void lcd_data(unsigned char value);
    sfr ldata=0x90;
    sbit rs=P2^0;
    sbit rw=P2^1;
    sbit en=P2^2;
    void main()
    {
    lcd_cmd(0x38);
    MSdelay(250);
    lcd_cmd(0x0E);
    MSdelay(250);
    lcd_cmd(0x1);
    MSdelay(250);
    lcd_cmd(0x06);
    MSdelay(250);
    lcd_cmd(0x86);
    MSdelay(250);
    lcd_data(‘M’);  // DATA
    MSdelay(250);
    lcd_data(‘D’);
    MSdelay(250);
    lcd_data(‘E’);
    }
    void lcd_cmd(unsigned char value)
    {
    ldata=value;
    rs=0;
    rw=0;
    en=1;
    MSdelay(1);
    en=0;
    return;
    }
     
    void lcd_data(unsigned char value)
    {
    ldata=value;
    rs=1;
    rw=0;
    en=1;
    MSdelay(1);
    en=0;
    return;
    }
    void MSdelay(unsigned int itime)
    {
    unsigned int i,j;
    for(i=0; i<itime; i++)
    for (j=0; j<1275; j++);
    }

     

     

     

    May 6, 2012 at 7:26 am #7597
    Diwanker Pandey
    Participant

    @salman

    you are missing function prototype write it before main.

    March 18, 2016 at 7:07 pm #13800
    Rahul
    Participant
    #include<regx52.h>
    #define lcd_databus P1
    sbit lcd_en=P2^2;
    sbit lcd_rs=P2^0;
    void display_title();
    void printline(unsigned char cmd,const unsigned char *dstr,unsigned char count);
    void sendlcdCommand(unsigned char cmd);
    void sendlcddata(unsigned char dcyte);
    void intilcd();
    void delay_ms(unsigned int mscount);
    void delay_us(unsigned char uscount);
    //void displaytemp(unsigned char addr,unsigned char tval);
    //void toascii(unsigned char hval); 
    code const unsigned char megtitle1[]="W.I.T";
    code const unsigned char megtitle2[]="Digital Portalbal Deivce";
    code const unsigned char megtitle3[]="cloth lenth=";
    code const unsigned char megtitle4[]="cm=0 mm=0";
    void main()
    {
      intilcd();
     display_title();
    }
     
    void display_titel()
    {
    printline(0x80,&megtitle1[0],16);
    printline(0xc0,&megtitle2[0],16);
    delay_ms(3000);
    printline(0x80,&megtitle3[0],16);
    printline(0xc0,&megtitle4[0],16);
      }
     
    void printline(unsigned char cmd,const unsigned char*dstr,unsigned char count)
    {
    unsigned char ch;
    sendlcdcommand(cmd);
    for(;count>0;count–)
    {
    ch=*dstr;
    sendlcddata(ch);
    dstr++;
    }
    }
     
     void sendlCdcommand(unsigned char cmd)
     {
     lcd_rs=0;
     lcd_databus=cmd;
     lcd_en=1;
     delay_us(5);
     lcd_en=0;
    delay_us(200);
    }
      void sendlcddata(unsigned char dcyte)
      {
      lcd_rs=1;
     lcd_databus=dcyte;
     lcd_en=1;
     delay_us(5);
     lcd_en=0;
    delay_us(200);
    }
     
    void initlcd()
    {
    delay_ms(20);
    sendlcdCommand(0x38);
    delay_ms(20);
    sendlcdCommand(0x38);
    delay_ms(20);
    sendlcdCommand(0x38);
    sendlcdCommand(0x06);
    sendlcdCommand(0x0c);
    sendlcdCommand(0x14);
        sendlcdCommand(0x01);
    delay_ms(5);
     
    }
     void delay_ms(unsigned int mscount)
     {
      unsigned char i;
      for(;mscount>0;mscount++)
      {
      for(i=250;i>0;i–)
      {
      }
      }
     
     }
    void delay_us(unsigned char uscount)
       {
       for(;uscount>0;uscount++)
       {
       }
    }
     
    //ALSO LCD.C(36): error C267: 'sendlcdcommand': requires ANSI-style prototype
    SLOVE ERROR PLZ
     
    April 9, 2016 at 4:00 pm #13869
    justin
    Participant

    //rearrange the program like this..

    //interfacing using c
    #include <reg51.h>
    sfr ldata= 0x90;
    sbit rs=P2^0;
    sbit rw=P2^1;
    sbit en=P2^2;
    void MSDelay(unsigned int itime)
    {
        unsigned int i,j;
        for(i=0;i<itime;i++)
        for(j=0;j<1275;j++);
    }
    void lcdcmd(unsigned char value)
    {
        ldata=value;
        rs=0;
        rw=0;
        en=1;
        MSDelay(1);
        en=0;
        return;
    }
    void lcddata(unsigned char value)
    {
        ldata = value;
        rs=1;
        rw=0;
        en=1;
        MSDelay(1);
        en=0;
        return;
    }

    void main()
    {
        lcdcmd(0x38);
        MSDelay(250);
        lcdcmd(0x0E);
        MSDelay(250);
        lcdcmd(0x01);
        MSDelay(250);
        lcdcmd(0x06);
        MSDelay(250);
        lcdcmd(0x86);
        MSDelay(250);
        lcddata('m');
    }
     

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Siemens large industrial PLC parts June 16, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 16, 2025
  • Curved lines in PCB design June 16, 2025
  • using a RTC in SF basic June 15, 2025
  • Parts required for a personal project June 15, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise