Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] lcd 4 bit error .. trying to interfcing with 8051 in single port

Status
Not open for further replies.
For lcd_data()
Code:
LCDPORT = c & 0xf0 | 0x4;

There's no need to set RS before DB bits, by the way.
 
But sir some thing wrong not working


Code:
    #include <REGX51.H>
    #define LCDPORT P2
    sbit RS = LCDPORT ^ 2;
    sbit E = LCDPORT ^ 3;
     
    void delay(unsigned int itime)
    {
    unsigned int i, j;
    for (i = 0; i < itime; i++)
    for (j = 0; j < 1275; j++);
    }
     
     
     
    void latch(void)
    {
    E = 1;
    delay(10);
    E = 0;
    }
     
    void lcd_cmd(unsigned char c)
    {
    RS = 0;
    delay(1);
    LCDPORT = c & 0xf0;
    latch();
    delay(1);
    LCDPORT = (c << 4);
    latch();
    }
     
    void lcd_data(unsigned char c)
    {
    //RS =1;
    delay(1);
    LCDPORT = c & 0xf0 | 0x4;
    delay(1);
    latch();
     
    LCDPORT = (c << 4) | 0x4;;
    latch();
    }
     
    void lcd_init()
    {
    delay(50);
    lcd_cmd(0x30);
    delay(20);
    lcd_cmd(0x30);
    delay(4);
    lcd_cmd(0x30);
    delay(4);
    lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x0c); // Make cursorinvisible
    lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
    }
     
     
     
     
     
    void main()
    {
    P2 = 0x00;
    lcd_init();
    lcd_cmd(0x80);
    lcd_data(1); // just send "1" to lcd to display ;
    P3 = 0xf0;
    while (1);
    }

- - - Updated - - -

thanks working sir really help full
changed as
lcd_data('2');

thanks to all
 

Greetings,
Sorry thannara for late reply but I am so busy with my project, here is a working 4 bit program but the read, write enable pins are at different ports. So you have to edit it according to your needs.
Code:
#include<reg52.h>
#define ldata P1          //16x2 lcd data pins to port p1
sbit en = P2^2;              
//sbit busy = P1^7;          //remove comment tags if lcdready() function is used
sbit rs = P2^0;
sbit rw = P2^1;
void lcdcmd(unsigned char l);
void lcddata(unsigned char l);
void MSDelay(unsigned int t);
//void lcdready();
void callmsg();
void callme();
void main()
{
 while(1)
 {
 lcdcmd(0x28);
 lcdcmd(0x0C);
 lcdcmd(0x01);
 lcdcmd(0x06);
 lcdcmd(0x0C0);              // force cursor to begin with 2nd row
// lcddata('1');          // display single numeric or character
 callmsg();                  // to display string 
 MSDelay(255);
 MSDelay(255);
 MSDelay(255);
 MSDelay(255);
 //lcdcmd(0x01);
 //lcdcmd(0x06);
 lcdcmd(0x80);              // force cursor to begin with 1st row
 callme();
 MSDelay(255);
 MSDelay(255);
 }
 }
 void callmsg()
 { 
 unsigned char message[] = "www.edaboard.com";
 unsigned char z,l;
    
for(z=0;z<16;z++)
 {
  l = message[z];
  lcddata(l);
 // MSDelay(100);
 }
}
void callme()
{
 unsigned char message[] = "Happy New Year";
 unsigned char z,l;
 

for(z=0;z<15;z++)
 {
  l = message[z];
  lcddata(l);
//  MSDelay(100);
 }
}

void lcdcmd(unsigned char l)
 { 

//  lcdready();
 ldata = l & 0xf0;
 rs = 0;
 rw = 0;
 en = 1;
  MSDelay(1);
 en = 0; 
//  lcdready();
 l = (l << 4);
 ldata = l;
 rs = 0;
 rw = 0;
 en = 1;
 MSDelay(1);
 en = 0;  
 return;
 }

 void lcddata(unsigned char l)
 {       
 //    lcdready();
 ldata = l & 0xf0;
 rs = 1;
 rw = 0;
 en = 1;
 MSDelay(1);
 en = 0; 
//lcdready();
 l = (l << 4);
 ldata = l;
 rs = 1;
 rw = 0;
 en = 1;
  MSDelay(1);
 en = 0;
return;
 }
/*
 void lcdready()
 {
  busy = 1;
  rs = 0;
  rw = 1;
  while(busy==1)
  {
   
   en = 0;
   MSDelay(1);
   en = 1;
  
  }
  
  return;
 
 } 
          */
  void MSDelay(unsigned int t)
 {
  
  unsigned int i,j;
  for(i=0;i<t;i++)
   {
    for(j=0;j<255;j++)
       {}
   }
 }

Good Luck :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top