Need assistance _______LCD Program

Status
Not open for further replies.

Thread Starter

triplehdineshbabu

Joined Feb 5, 2009
38
Hi all,

I have written the LCD Display coding in 8051C, Kindly Check and tell me whats error in this program

---------_------

#include<reg52.h>
#include<intrins.h>
sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
sbit busy=P1^7;
unsigned char *L1="Dinesh";
unsigned char *L2="Babu";
void lcd_inz(void);
void address_write(unsigned char);
void data_write(unsigned char);
void delay(unsigned int);
void string_write(char*);
void check();
void main()
{
lcd_inz();
delay(10);
while(1)
{
address_write(0x80);
string_write(L1);
delay(10);
address_write(0xc0);
string_write(L2);
delay(10);
}
}
void delay(unsigned int i)
{
int k;
for(k=0;k<i;k++)
{
_nop_();
}
}
void lcd_inz()
{
address_write(0x01);
address_write(0xc0);
address_write(0xc0);
address_write(0x80);
address_write(0x38);
address_write(0xe0);
}
void address_write(unsigned char x)
{
P1=x;
rs=0;
rw=0;
en=1;
delay(10);
en=0;
check();
}
void check()
{
busy=1;
en=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
delay(10);
en=1;
}
}
void string_write(unsigned char *v)
{
while(*v!='\0');
{
data_write(*v);
v++;
}
}
void data_write(unsigned char y)
{
P1=y;
rs=1;
rw=0;
en=1;
delay(10);
en=0;
check();
}



------------------

thanks In advance

Regards,

Dinesh
 

futz

Joined Dec 14, 2008
23
I have written the LCD Display coding in 8051C, Kindly Check and tell me whats error in this program
Hi Dinesh. I don't use the 8051, but I can tell right away you have a problem in your code.

But first a quick tip: When posting code to the forum, use Code tags. Either click on the # icon just before pasting your code, or type [code] before your code and [/code] after it. This tells the forum software not to strip the formatting off your code and leaves it properly indented. Good looking code is easier for people to read and help you with. :)

Here's your code reformatted and posted correctly:
Rich (BB code):
#include<reg52.h>
#include<intrins.h>

sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
sbit busy=P1^7;

unsigned char *L1="Dinesh";
unsigned char *L2="Babu";

void lcd_inz(void);
void address_write(unsigned char);
void data_write(unsigned char);
void delay(unsigned int);
void string_write(char*);
void check();

void main()
{
    lcd_inz();
    delay(10);
    while(1)
    {
        address_write(0x80);
        string_write(L1);
        delay(10);
        address_write(0xc0);
        string_write(L2);
        delay(10);
    }
}

void delay(unsigned int i)
{
    int k;
    for(k=0;k<i;k++)
    {
        _nop_();
    }
}

void lcd_inz()
{
    address_write(0x01);
    address_write(0xc0);
    address_write(0xc0);
    address_write(0x80);
    address_write(0x38);
    address_write(0xe0);
}

void address_write(unsigned char x)
{
    P1=x;
    rs=0;
    rw=0;
    en=1;
    delay(10);
    en=0;
    check();
}

void check()
{
    busy=1;
    en=1;
    rs=0;
    rw=1;
    while(busy==1)
    {
        en=0;
        delay(10);
        en=1;
    }
}

void string_write(unsigned char *v)
{
    while(*v!='\0');
    {
        data_write(*v);
        v++;
    }
}

void data_write(unsigned char y)
{
    P1=y;
    rs=1;
    rw=0;
    en=1;
    delay(10);
    en=0;
    check();
}
You haven't delayed before initializing the LCD. There should be at least a 15ms "settle time" delay to allow the LCD to initialize itself, before it's ready to receive any commands.

Here's my LCD code (4-bit mode) that I use on PIC, AVR and ARM7. This happens to be the ARM version. Might give you some ideas.
Rich (BB code):
void lcd_string(char *senpoint)
{
    while(*senpoint != '\0')
    {
        lcd_char(*senpoint);
        senpoint++;
    }
}    

void lcd_line1(void){
    lcd_cmd(0x80);
}
void lcd_line2(void){
    lcd_cmd(0xc0);
}        

void lcd_cmd(unsigned char letter)
{
    unsigned char temp;
    temp=letter;
    temp=temp>>4;
    lcd_nybble(temp,0);
    temp=letter;
    temp=temp&0x0f;
    lcd_nybble(temp,0);
}

void lcd_char(unsigned char letter)
{
    unsigned char temp;
    temp=letter;
    temp=temp>>4;
    lcd_nybble(temp,1);
    temp=letter;
    temp=temp&0x0f;
    lcd_nybble(temp,1);
}

void lcd_nybble(unsigned char nyb,unsigned char rs)
{
    int i,dat;
    if(rs)
        IOSET0 = RS;            //set RS pin
    else
        IOCLR0 = RS;            //clear RS pin
    dat = nyb;                  //get the nybble in an int
    IOCLR0 = 0x001e0000;        //clear D4-D7
    IOPIN0 |= dat<<17;          //OR the bits in there
    strobe_e();                 //latch data to LCD
}

void lcd_init(void)
{
    delay_ms(500);              //settle time delay
    lcd_nybble(0x03,0);         //reset LCD
    strobe_e();
    strobe_e();
    lcd_nybble(0x02,0);
    lcd_cmd(0x28);              //set 4-bit mode and 2 lines
    lcd_cmd(0x10);              //cursor move & shift left
    lcd_cmd(0x06);              //entry mode = increment
    lcd_cmd(0x0e);              //display on - cursor blink on
    lcd_cmd(0x01);              //clear display
}

void lcd_busy(void)
{
    IODIR0 &= 0xffefffff;      //D7 is input
    IOCLR0 = RS;               //set RS low
    IOSET0 = RW;               //set R/W high
    IOSET0 = E;                //set E high
    while(IOPIN0 & busyflag);  //wait for busy flag to go low
    IOCLR0 = E;                //set E low
    IOCLR0 = RW;               //set R/W low
    IODIR0 |= 0x00100000;      //D7 is output again
}

void strobe_e(void)
{
    IOSET0 = E;
    delay_us(1);
    IOCLR0 = E;
    lcd_busy();
}
If you don't already have them, these two files are must-reads for character LCD use.
http://www.epemag.wimborne.co.uk/lcd1.pdf
http://www.epemag.wimborne.co.uk/lcd2.pdf
 
Last edited:
Status
Not open for further replies.
Top