Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/19/03 00:10
Read: times


 
#41821 - LCD code
Here is my c code for LCD that actually worked. It is for a display from a company called EDT. They claimed it has HD44780 built in but the timing in the datasheet was wrong and after long experimentation this code worked best.
It is for pic and hi-tech c compiler the display is set for 4 bit mode and upper 4 bits of port b are actually used for DB3 to DB7 of the LCD controller.
It can easily be converted to 8052 and to assembly.
Hope this helps
Mahmood

<br/>
/******************************************************************************
* Name:    LCDD_Initilise
******************************************************************************/
    void LCDD_Initialise()
    {
        RS = 0;	        // write control bytes
        E  = 0;
        DelayMs(15);	// power on delay
        PORTB = 0x30;	// attention!
        ECLOCK();
        DelayMs(5);
        ECLOCK();
        DelayUs(100);
        ECLOCK();
        DelayMs(5);
        PORTB = 0x20;	// set 4 bit mode
        ECLOCK();
        DelayUs(40);
        LCDD_WriteCommand(0x28);	// 4 bit mode, 1/16 duty, 5x8 font
        LCDD_WriteCommand(0x08);	// display off
        LCDD_WriteCommand(0x0F);	// display on, blink curson on
        LCDD_WriteCommand(0x06);	// entry mode
        DelayMs(5);
        LCDD_WriteCommand(DispCLR);
        LCDD_WriteCommand(RetHome);
        LCDD_WriteCommand(DispON);
    }
/******************************************************************************
* Name:    LCDD_WriteData
******************************************************************************/

void LCDD_WriteData(byte nibbles)
{
    RS = HI;    // indicating data
    PORTB = (PORTB & 0x0f) | (nibbles & 0x0f0);
    ECLOCK();
    DelayMs(1);
    PORTB = (PORTB & 0x0f) | (nibbles << 4);// output lower 4 bits
    ECLOCK();
    DelayMs(1);
}
/******************************************************************************
* Name:    LCDD_WriteString
******************************************************************************/

void LCDD_WriteString(const register byte *s)
{
    while(*s) 
    {
        LCDD_WriteData(*s++);
        DelayMs(1);
    }
}

/******************************************************************************
* Name:    ECLOCK
******************************************************************************/

void ECLOCK(void)
{
    DelayUs(1);			// tas delay 
    E = HI;			// for write cycle only
    DelayUs(2);
    E = LOW;
    DelayUs(1);
}   

/******************************************************************************
*       function that clears the screen
******************************************************************************/
void LCDD_Cls()
{
    LCDD_WriteCommand(DispCLR);
    LCDD_WriteCommand(RetHome);
}

/******************************************************************************
* Name:    LCDD_GotoDispPos
******************************************************************************/

void LCDD_GotoDispPos(unsigned char dd)
{
    LCDD_WriteCommand(dd);
}

p.s LCDD_WriteCommand is same as LCDD_WriteData but with RS = 0;


List of 2 messages in thread
TopicAuthorDate
LCD code            01/01/70 00:00      
   RE: LCD code            01/01/70 00:00      

Back to Subject List