#include <REGX51.H>
sfr ldata = 0x90; // port P0 assign 
sbit RS   = P2^0;  // Register Select Pin
sbit EN   = P2^1; //  Enable Pin Of LCD

#define clear LCD_cmd(0x01)

 void ms_delay(unsigned int itime);
 void LCD_STROBE(void);
 void LCD_data(unsigned char c);
 void LCD_cmd(unsigned char c);
 void LCD_string(const char *q);
 void lcd_init();
main()
{
  ms_delay(10);
  LCD_STROBE();
  clear;   

}
 
  void ms_delay(unsigned int itime)    // for delay   do it y using timer later
       {
        unsigned int i,j;
        for(i=0; i<itime; i++)
        for(j=0; j<1275;j++)
           ;
        }

void LCD_STROBE(void)            // For giving a High to Low pulse 
  {
   EN = 1;
   ms_delay(1);    // 1 milli second but needed only 450 nano sec
      EN = 0;
  }

  void LCD_data(unsigned char c)
{
    RS = 1;
    ms_delay(1);
    ldata = (c >> 4);
    LCD_STROBE();
    ldata = (c);
    LCD_STROBE();
    
}
  void LCD_cmd(unsigned char c)
{
    RS = 0;
    ms_delay(1);
    ldata = (c >> 4);
    LCD_STROBE();
    ldata = (c);
    LCD_STROBE();
    
}

void lcd_init()
{
    ms_delay(15);
    LCD_cmd(0x38);
    ms_delay(1);
    LCD_cmd(0x38);
    ms_delay(100);
    LCD_cmd(0x38);
    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(0x01);            // Clear screen
    LCD_cmd(0x6);            // Set entry Mode(auto increment of cursor)
}
 


   void LCD_string(const char *q)
{
    while (*q) {
        LCD_data(*q++);
    }
}


Comments