Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD display C program

Status
Not open for further replies.

Parth86

Member
Hello everyone
here is code which display message " ELECTRO-TECH" on screen

C:
// Program for LCD Interfacing with 8051 Microcontroller

#include<reg51.h>
#define display_port P1      //Data pins connected to port 2 on microcontroller
sbit rs = P2^0;  //RS pin connected to pin 2 of port 3
sbit rw = P2^1;  // RW pin connected to pin 3 of port 3
sbit e =  P2^2;  //E pin connected to pin 4 of port 3

void msdelay(unsigned int time)  // Function for creating delay in milliseconds.
{
    unsigned i,j ;
    for(i=0;i<time;i++) 
    for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command)  //Function to send command instruction to LCD
{
    display_port = command;
    rs= 0;
    rw=0;
    e=1;
    msdelay(1);
    e=0;
}

void lcd_data(unsigned char disp_data)  //Function to send display data to LCD
{
    display_port = disp_data;
    rs= 1;
    rw=0;
    e=1;
    msdelay(1);
    e=0;
}

 void lcd_init()    //Function to prepare the LCD  and get it ready
{
    lcd_cmd(0x38);  // for using 2 lines and 5X7 matrix of LCD
    msdelay(10);
    lcd_cmd(0x0F);  // turn display ON, cursor blinking
    msdelay(10);
    lcd_cmd(0x01);  //clear screen
    msdelay(10);
    lcd_cmd(0x81);  // bring cursor to position 1 of line 1
    msdelay(10);
}
void main()
{
    unsigned char a[15]="ELECTRO-TECH";    //string of 14 characters with a null terminator.
    int l=0;
    lcd_init();
    while(a[l] != '\0') // searching the null terminator in the sentence
    {
        lcd_data(a[l]);
        l++;
        msdelay(50);
    }
}
I show message with cursor. when message display I don't want to see the cursor in message. Is it possible ? how to do it ?
 
Change,

lcd_cmd(0x0F); // turn display ON, cursor blinking

to

lcd_cmd(0x0d); // turn display ON, cursor OFF

Mike.
For an explanation see attached datasheet.
 

Attachments

  • LCD Module data sheet.pdf
    587 KB · Views: 390
Change,

lcd_cmd(0x0F); // turn display ON, cursor blinking

to

lcd_cmd(0x0d); // turn display ON, cursor OFF

Mike.
For an explanation see attached datasheet.
Thanks. Now I don't see the cursor but I see the black symbol at the starting of every characters. what is that? Is it cursor position. I am trying to see message without black symbol.
 
Last edited by a moderator:
Try changing it to 0xc0. Not at computer at moment so might be wrong.

Mike.
 
Change this.
unsigned char a[15]="ELECTRO-TECH";

to this..
unsigned char a[15]={"ELECTRO-TECH",0};

And change this..
lcd_cmd(0x0F); // turn display ON, cursor blinking

to this..
lcd_cmd(0x0C); // turn display ON, cursor blinking
 
thanks. now it works just two changes
unsigned char a[15]="ELECTRO-TECH";
lcd_cmd(0x0C); // turn display ON, cursor blinking
 
I thought that double quotes always created a null terminated string. What compiler is this? Is there some rule for when no null is added?

Mike.
 
I thought that double quotes always created a null terminated string. What compiler is this? Is there some rule for when no null is added?
Not so much the double quotes... The curly brackets were missing..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top