Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************
- File: lcd.c
- Description:
- Driver for an alphanumeric LCD with parallel interface. Only
- 4Bit interface is supported.
- *******************************************/
- /*wenn im c file änderungen vorgenommen werden ohne das das h file included wird, dann überprüft der compiler nicht ob die prototypen
- vorhanden sind*/
- #include "HTLStddef.h"
- #include "lcd.h"
- #include "lcd_constants.h"
- /****************** Declaration of private funktions *******************/
- void LcdOut4Bit (unsigned char aByte);
- void LcdEnable(void);
- TBool LcdCommand(unsigned char);
- TBool LcdCheckBusy(void);
- TBool LcdReadBusyFlag(void);
- TBool LcdReadBusyFlag(void);
- unsigned char LcdReadAddress(void);
- unsigned char LcdRead4Bit(void);
- /****************** Public functions ************************/
- void LcdInit(void) {
- LCD_PORT_DATA &= ~(1 << LCD_DB);
- LCD_DDR_DATA |= (1 << LCD_DB);
- LCD_PORT_RS &= ~(1 << LCD_RS);
- LCD_DDR_RS |= (1 << LCD_RS);
- LCD_PORT_RW &= ~(1 << LCD_RW);
- LCD_DDR_RW |= (1 << LCD_RW);
- LCD_PORT_EN &= ~(1 << LCD_EN);
- LCD_DDR_EN |= (1 << LCD_EN);
- //zeit zum hochfahren geben
- DelayMs(LCD_BOOTUP_MS);
- // Software reset 3 times
- LcdOut4Bit(LCD_SOFT_RESET);
- DelayMs(LCD_SOFT_RESET_MS1);
- LcdOut4Bit(LCD_SOFT_RESET);
- DelayMs(LCD_SOFT_RESET_MS2);
- LcdOut4Bit(LCD_SOFT_RESET);
- DelayMs(LCD_SOFT_RESET_MS3);
- /* Set to 4 bit mode*/
- LcdOut4Bit(LCD_SET_FUNCTION | LCD_FUNCTION_4BIT);
- DelayMs(LCD_SET_4BITMODE_MS);
- /* Initialize 2 lines, 5x7 matrix */
- LcdCommand(LCD_SET_FUNCTION | LCD_FUNCTION_4BIT | LCD_FUNCTION_2LINE | LCD_FUNCTION_5X7);
- /* Initialize cursor */
- LcdCommand(LCD_SET_DISPLAY | LCD_DISPLAY_ON | LCD_CURSOR_OFF | LCD_BLINKING_OFF);
- LcdClear();
- }
- void LcdWriteString(char* aString) {
- unsigned int i;
- for(i = 0; aString[i] != 0; i++){
- LcdWriteChar();
- }
- }
- void LcdWriteChar(char aCharacter) {
- LCD_PORT_RS |= (1 << LCD_RS);
- LCD_PORT_RW &= ~(1 << LCD_RW);
- LcdOut4Bit(aCharacter);
- LcdOut4Bit(aCharacter << 4);
- LcdCheckBusy();
- }
- void LcdClear() {
- LcdCommand(LCD_CLEAR_DISPLAY);
- DelayMs(LCD_CLEAR_DISPLAY_MS);
- }
- void LcdSetPosition(unsigned char aRow, unsigned char aColum) {
- int adr;
- switch(aColum){
- case 0:
- adr = LCD_DDADR_LINE1;
- break;
- case 1:
- adr = LCD_DDADR_LINE2;
- break;
- case 2:
- adr = LCD_DDADR_LINE3;
- break;
- case 3:
- adr = LCD_DDADR_LINE4;
- break;
- default:
- return;
- }
- adr += aRow;
- LcdCommand(LCD_SET_DDADR + adr);
- }
- /*************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement