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 8 years, 6 months ago by justin.
-
AuthorPosts
-
April 6, 2011 at 8:02 pm #3831SaLMAN Ahmed KhanParticipantTHIS 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'); // DATAMSdelay(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 #5915romel emperadoParticipant
can you pls post the error..
April 11, 2011 at 7:31 pm #5944SaLMAN Ahmed KhanParticipantERROR!!!!!::Build target ‘Target 1’compiling lcda.c…LCDA.C(: warning C206: ‘lcd_cmd’: missing function-prototypeLCDA.C(: error C267: ‘lcd_cmd’: requires ANSI-style prototypeTarget not createdApril 11, 2011 at 9:46 pm #5945romel emperadoParticipanthere’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 0x80void 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 #5948SaLMAN Ahmed KhanParticipantbut what specific error it has why it is giving????
April 12, 2011 at 3:29 pm #5949romel emperadoParticipantWARNING 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 #5950romel emperadoParticipantuse my code instead..
April 13, 2011 at 3:59 am #5953piyushParticipantsimply 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);June 30, 2011 at 3:39 am #6396PRATYUSH TRIPATHIParticipanthey 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 #6405SaLMAN Ahmed KhanParticipant@ thripati
ur solution is better
March 31, 2012 at 4:33 pm #7368harpreet khanujaParticipantI AM ENCOUNTER SAME ERROR..PLEASE HELPGOLDITEMP.C(65): warning C206: ‘Lcd_Out’: missing function-prototypeGOLDITEMP.C(65): error C267: ‘Lcd_Out’: requires ANSI-style prototype#include<reg51.h>#include<stdlib.h>//void lcd_data(unsigned char value);// LCD module connectionssbit 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 pinoutsbit 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: 12const 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 negativeif (temp2write & 0x8000) {text[0] = ‘-‘;temp2write = ~temp2write + 1;}// extract temp_wholetemp_whole = temp2write >> RES_SHIFT ;// convert temp_whole to charactersif (temp_whole/100)text[0] = temp_whole/100 + 48;elsetext[0] = ‘0’;text[1] = (temp_whole/10)%10 + 48; // Extract tens digittext[2] = temp_whole%10 + 48; // Extract ones digit// extract temp_fraction and convert it to unsigned inttemp_fraction = temp2write << (4-RES_SHIFT);temp_fraction &= 0x000F;temp_fraction *= 625;// convert temp_fraction to characterstext[4] = temp_fraction/1000 + 48; // Extract thousands digittext[5] = (temp_fraction/100)%10 + 48; // Extract hundreds digittext[6] = (temp_fraction/10)%10 + 48; // Extract tens digittext[7] = temp_fraction%10 + 48; // Extract ones digit// print temperature on LCDLcd_Out(2, 5, text);}void main() {Lcd_Init(); // Initialize LCDLcd_Cmd(_LCD_CLEAR); // Clear LCDLcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor offLcd_Out(1, 1, ” Temperature: “);// Print degree character, ‘C’ for CentigradesLcd_Chr(2,13,223); // different LCD displays have different char code for degree// if you see greek alpha letter try typing 178 instead of 223Lcd_Chr(2,14,’C’);//— main loopdo {//— perform temperature readingOw_Reset(); // Onewire reset signalOw_Write(0xCC); // Issue command SKIP_ROMOw_Write(0x44); // Issue command CONVERT_TDelay_us(120);Ow_Reset();Ow_Write(0xCC); // Issue command SKIP_ROMOw_Write(0xBE); // Issue command READ_SCRATCHPADtemp = Ow_Read();temp = (Ow_Read() << + temp;//— Format and display result on LcdDisplay_Temperature(temp);Delay_ms(500);} while (1);}April 12, 2012 at 3:41 pm #7427lalchandParticipantlalchand 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 #7597Diwanker PandeyParticipant@salman
you are missing function prototype write it before main.
March 18, 2016 at 7:07 pm #13800RahulParticipant#include<regx52.h>#define lcd_databus P1sbit 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 prototypeSLOVE ERROR PLZApril 9, 2016 at 4:00 pm #13869justinParticipant//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');
}
-
AuthorPosts
- You must be logged in to reply to this topic.