LCD C Programming Urgent

I'm currently connecting up a C8051F005 microcontroller from CYGNAL and a lcd from Farnell(JM204A).I have look thru the specs and datasheets for both of them n have written a sourcecode.Im very sure that there are no errors with the connection,as when the power is on the lcd can show 2 lines of full dark charracters,however i have programmed it to show "Height:" without the quotes but it jus show dark characters.Pls Help me and correct my mistakes.


#include


sbit E =P0^4;
sbit RS =P0^6;
sbit RW =P0^7;

void delay(unsigned a,unsigned b)
{
TMOD = 0x01;
TR0 = 0;
TF0 = 0;
TH0 = a;
TL0 = b;
TR0 = 1;
while(TF0==1);
}

void delay_1()
{
int a;
TMOD = 0x01; // Timer Mode Register
for(a=0;a<50;a++)
{
TH0 = 0x00; // Timer 0 High Byte
TL0 = 0x00; // Timer 0 Low Byte
TF0 = 0;
TR0 = 1;
while(TF0==0)
{
TR0 = 0;
}

}
}

void delay_2(unsigned int x)
{
while(x!=0)
{
x--;
}
}

void strobe()
{
E = 1;
delay(0xFF,0x69);
E = 0;
delay(0xFF,0x69);
}

void data_write(unsigned char x)
{
RS = 0;
RW = 0;
P1 = x;
strobe();
}

void control_write(unsigned char x)
{
RS = 1;
RW = 0;
P1 = x;
strobe();
}

void display_init()
{
XBR0 = 0x00;
XBR1 = 0x00;
XBR2 = 0x40;
PRT1CF=0x00;
PRT0CF=0x00;
delay(0x8A,0x00);
RS = 0;
RW = 0;
P1 = 0x38;
strobe();
delay(0xFF,0x00);
RS = 0;
RW = 0;
P1 = 0x0E;
strobe();
delay(0xFF,0x00);
RS = 0;
RW = 0;
P1 = 0x01;
strobe();
delay(0xFA,0x00);
RS = 0;
RW = 0;
P1 = 0x06;
strobe();
}




void main()
{
display_init();
control_write(0x80);
data_write(0x48);
data_write(0x45);
data_write(0x49);
data_write(0x47);
data_write(0x54);
data_write(0x69);
data_write(0x73);
data_write(0x00);
data_write(0x00);
data_write(0x00);
data_write(0x00);
delay(0x8A,0x00);
}

Comments

  • :
    [code]
    : #include
    :
    :
    : sbit E =P0^4;
    : sbit RS =P0^6;
    : sbit RW =P0^7;
    :
    : void delay(unsigned a,unsigned b)
    : {
    : TMOD = 0x01;
    : TR0 = 0;
    : TF0 = 0;
    : TH0 = a;
    : TL0 = b;
    : TR0 = 1;
    : while(TF0==1);
    : }
    :
    : void delay_1()
    : {
    : int a;
    : TMOD = 0x01; // Timer Mode Register
    : for(a=0;a<50;a++)
    : {
    : TH0 = 0x00; // Timer 0 High Byte
    : TL0 = 0x00; // Timer 0 Low Byte
    : TF0 = 0;
    : TR0 = 1;
    : while(TF0==0)
    : {
    : TR0 = 0;
    : }
    :
    : }
    : }
    :
    : void delay_2(unsigned int x)
    : {
    : while(x!=0)
    : {
    : x--;
    : }
    : }
    :
    : void strobe()
    : {
    : E = 1;
    : delay(0xFF,0x69);
    : E = 0;
    : delay(0xFF,0x69);
    : }
    :
    : void data_write(unsigned char x)
    : {
    : RS = 0;
    : RW = 0;
    : P1 = x;
    : strobe();
    : }
    :
    : void control_write(unsigned char x)
    : {
    : RS = 1;
    : RW = 0;
    : P1 = x;
    : strobe();
    : }
    :
    : void display_init()
    : {
    : XBR0 = 0x00;
    : XBR1 = 0x00;
    : XBR2 = 0x40;
    : PRT1CF=0x00;
    : PRT0CF=0x00;
    : delay(0x8A,0x00);
    : RS = 0;
    : RW = 0;
    : P1 = 0x38;
    : strobe();
    : delay(0xFF,0x00);
    : RS = 0;
    : RW = 0;
    : P1 = 0x0E;
    : strobe();
    : delay(0xFF,0x00);
    : RS = 0;
    : RW = 0;
    : P1 = 0x01;
    : strobe();
    : delay(0xFA,0x00);
    : RS = 0;
    : RW = 0;
    : P1 = 0x06;
    : strobe();
    : }
    :
    :
    :
    :
    : void main()
    : {
    : display_init();
    : control_write(0x80);
    : data_write(0x48);
    : data_write(0x45);
    : data_write(0x49);
    : data_write(0x47);
    : data_write(0x54);
    : data_write(0x69);
    : data_write(0x73);
    : data_write(0x00);
    : data_write(0x00);
    : data_write(0x00);
    : data_write(0x00);
    : delay(0x8A,0x00);
    : }
    :
    [/code]

    First, use code tags. It's a lot nicer that way.


    This looks a little fun. What type is TF0?
    TF0 = 0;
    while(TF0==1);

    If it's an int then the compiler may optimise it away, making never
    finnish.

    Does it work for any character you send it?
    Does it work at all?
  • : :
    : [code]
    : : #include
    : :
    : :
    : : sbit E =P0^4;
    : : sbit RS =P0^6;
    : : sbit RW =P0^7;
    : :
    : : void delay(unsigned a,unsigned b)
    : : {
    : : TMOD = 0x01;
    : : TR0 = 0;
    : : TF0 = 0;
    : : TH0 = a;
    : : TL0 = b;
    : : TR0 = 1;
    : : while(TF0==1);
    : : }
    : :
    : : void delay_1()
    : : {
    : : int a;
    : : TMOD = 0x01; // Timer Mode Register
    : : for(a=0;a<50;a++)
    : : {
    : : TH0 = 0x00; // Timer 0 High Byte
    : : TL0 = 0x00; // Timer 0 Low Byte
    : : TF0 = 0;
    : : TR0 = 1;
    : : while(TF0==0)
    : : {
    : : TR0 = 0;
    : : }
    : :
    : : }
    : : }
    : :
    : : void delay_2(unsigned int x)
    : : {
    : : while(x!=0)
    : : {
    : : x--;
    : : }
    : : }
    : :
    : : void strobe()
    : : {
    : : E = 1;
    : : delay(0xFF,0x69);
    : : E = 0;
    : : delay(0xFF,0x69);
    : : }
    : :
    : : void data_write(unsigned char x)
    : : {
    : : RS = 0;
    : : RW = 0;
    : : P1 = x;
    : : strobe();
    : : }
    : :
    : : void control_write(unsigned char x)
    : : {
    : : RS = 1;
    : : RW = 0;
    : : P1 = x;
    : : strobe();
    : : }
    : :
    : : void display_init()
    : : {
    : : XBR0 = 0x00;
    : : XBR1 = 0x00;
    : : XBR2 = 0x40;
    : : PRT1CF=0x00;
    : : PRT0CF=0x00;
    : : delay(0x8A,0x00);
    : : RS = 0;
    : : RW = 0;
    : : P1 = 0x38;
    : : strobe();
    : : delay(0xFF,0x00);
    : : RS = 0;
    : : RW = 0;
    : : P1 = 0x0E;
    : : strobe();
    : : delay(0xFF,0x00);
    : : RS = 0;
    : : RW = 0;
    : : P1 = 0x01;
    : : strobe();
    : : delay(0xFA,0x00);
    : : RS = 0;
    : : RW = 0;
    : : P1 = 0x06;
    : : strobe();
    : : }
    : :
    : :
    : :
    : :
    : : void main()
    : : {
    : : display_init();
    : : control_write(0x80);
    : : data_write(0x48);
    : : data_write(0x45);
    : : data_write(0x49);
    : : data_write(0x47);
    : : data_write(0x54);
    : : data_write(0x69);
    : : data_write(0x73);
    : : data_write(0x00);
    : : data_write(0x00);
    : : data_write(0x00);
    : : data_write(0x00);
    : : delay(0x8A,0x00);
    : : }
    : :
    : [/code]
    :
    : First, use code tags. It's a lot nicer that way.
    :
    :
    : This looks a little fun. What type is TF0?
    : TF0 = 0;
    : while(TF0==1);
    :
    : If it's an int then the compiler may optimise it away, making never
    : finnish.
    :
    : Does it work for any character you send it?
    : Does it work at all?
    :

  • Oh! Why there are many routines. I think you delay no longer enough. What frequency of your XTAL. If you don't mind please visit this page:

    http://freewebs.com/80x51/articles/lcd.html
    Visit my 8051 homepage:
    http://freewebs.com/80x51
    Free 8051 resources are avaliable.

  • HI, I'm also trying to programme a LCD display using C language. I'm to use a pic16F877 microcontroller. Please help me on this.
    I'm new to this.
    Can you please send me a example programme.

    my mail address is chinthana_raj@yahoo.com.

    Thanx.

    Chinthana_Raj.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories