| ??? 09/23/02 13:42 Read: times |
#29547 - RE: 4 bit LCD initialisation : My C code |
Here is what I wrote for 68HC11 and which may be easily rewritten for 8051
Regards Stephane /* Microcontroller's port or adress used for LCD PORT LCD LCD Connector VDD+VO 1 VSS 2 Px_0 : no conn. 3 Px_1 : RS 4 Px_2 : R/W 5 Px_3 : E 6 Px_4 : DB4 11 Px_5 : DB5 12 Px_6 : DB6 13 Px_7 : DB7 14 Raising edge on E, R/W=0 : x8 Falling edge on E : x0 void HLCD_LcdInit(void) { Pause (); LCD_PORT=0x38; Pause (); LCD_PORT=0x30; Pause (); LCD_PORT=0x38; Pause (); LCD_PORT=0x30; Pause (); LCD_PORT=0x38; Pause (); LCD_PORT=0x30; Pause (); LCD_PORT=0x28; Pause (); LCD_PORT=0x20; Pause (); LcdWrite(2,"x28"); /* Function set : 4 bits interface, no shift */ LcdWrite(2,"x0C"); /* Display control : display on, cursor off, blink off */ LcdWrite(2,"x06"); /* Entry mode set : increment mode, no display shift */ LcdWrite(2,"x02"); /* return home */ LcdWrite(2,"x01"); /* clear display */ Pause (); } /*------------------------------------------------------------------- Send datas or instructions to the LCD display LcdWrite(U8 func,U8 *txt) u8Function = 1 : *txt contains datas u8Function = 2 : *txt contains instructions --------------------------------------------------------------------*/ void LcdWrite(U8 u8Function,U8 *au8String) { U8 u8InstData,u8Upper,u8Lower; /* datas */ if (u8Function == 1) { u8InstData = 0 | RS & ~RW; } /* instructions */ if (u8Function == 2) { u8InstData = 0 & ~RS & ~RW; } /* Send the chain to the LCD display */ while (*au8String !=0) { u8Upper = *au8String & 0xF0 | u8InstData; /* RS=1 */ u8Lower = (*au8String << 4) & 0xF0 | u8InstData; /* RS=1 */ LCD_PORT = u8Upper | E; Pause (); LCD_PORT = u8Upper & E; Pause (); LCD_PORT = u8Lower | E; Pause (); LCD_PORT = u8Lower & E; Pause (); au8String++; /* next character */ } } /*------------------------------------------------------------------- Set the cursor position on the LCD display HLCD_LcdLocate (U8 u8Column, U8 lcd_line) u8Column : column number u8Line : line number --------------------------------------------------------------------*/ void HLCD_Locate (U8 u8Column, U8 u8Line) { U8 u8DD_RAM[2]; u8DD_RAM[0] = 0x80 | (u8Line-1)*0x40 | u8Column-1; u8DD_RAM[1] = 0; LcdWrite(2,u8DD_RAM); } /*------------------------------------------------------------------- Convert a digital value into an ASCII string HLCD_DisplayValue (U32 u32Value, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits) u32Value = 32 bits Value to display u8NumberOfIntegerDigits = Number of interger digits. If this number is higher than the number of integer digits, it will display the non significant '0' u8NumberOfDecimalDigits = Number of decimal digits --------------------------------------------------------------------*/ void HLCD_DisplayValue (U32 u32Value, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits) { U8 u8Size; /* Size of the table */ U8 au8ValueToDisplay[10]; /* String where is converted the value */ S8 s8CharNumber; /* Character number in the string */ /* Check if the dot has to be displayed and change the Size value */ if (u8NumberOfDecimalDigits == 0) { u8Size = u8NumberOfIntegerDigits + u8NumberOfDecimalDigits; } else { u8Size = u8NumberOfIntegerDigits + u8NumberOfDecimalDigits + 1; } /* Last value of the table = 0 */ au8ValueToDisplay[u8Size] = 0; /* Convert the value to an ASCII string */ for(s8CharNumber=u8Size - 1;s8CharNumber>=0;s8CharNumber--) { if ((s8CharNumber == u8Size - 1 - u8NumberOfDecimalDigits) && u8NumberOfDecimalDigits !=0) { au8ValueToDisplay[s8CharNumber] = '.'; } else { au8ValueToDisplay[s8CharNumber] = u32Value % 10 + '0'; u32Value /= 10; } } /* Display the string */ LcdWrite(1,au8ValueToDisplay); } /*------------------------------------------------------------------- Display a text to the LCD to the current location HLCD_DisplayText (U8 *au8Text) *au8Text = pointer to the text to display --------------------------------------------------------------------*/ void HLCD_DisplayText (U8 *au8Text) { /* Display the string */ LcdWrite(1,au8Text); } |
| Topic | Author | Date |
| 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation / Peter | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation / Peter | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation / Peter | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation / Peter | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation / Peter | 01/01/70 00:00 | |
RE: 4 bit LCD initialisation / Peter | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation | 01/01/70 00:00 | |
| RE: 4 bit LCD initialisation : My C code | 01/01/70 00:00 |



