;************************************************************************** ; ; HD44780 ; LCD 1602 / 2004 ; ---- ; | | ; VCC -- | 1 | VSS ; GND -- | 2 | VDD ; R <-------- | 3 | VEE ; PCF8574 P0 --> | 4 | RS ; PCF8574 P1 --> | 5 | R/W ; PCF8574 P2 --> | 6 | E ; x | 7 | D0 ; x | 8 | D1 ; x | 9 | D2 ; x | 10 | D3 ; PCF8574 P4 --> | 11 | D4 ; PCF8574 P5 --> | 12 | D5 ; PCF8574 P6 --> | 13 | D6 ; PCF8574 P7 --> | 14 | D7 ; PCF8574 P3 --> | 15 | A ; GND -- | 16 | C ; | | ; ---- ; ; ------------------------------------------------------------------------- ; externes DISPLAY .equ DP_RS = 0 .equ DP_RW = 1 .equ DP_E = 2 .equ DP_LED = 3 .equ DP_4 = 4 .equ DP_5 = 5 .equ DP_6 = 6 .equ DP_7 = 7 ; ------------------------------------------------------------------------- .equ LCD_Reset = 0b0011_1000 ; 0b0011_1... : LCD reset .equ LCD_4_Bit_Modus = 0b0010_1000 ; 0b0010_1... : 4-Bit-Modus .equ LCD_Clear = 0b0000_0001 ; Löscht Anzeige und Adresse = 0 .equ LCD_Entry_Mode = 0b0000_0110 ; Eingabemodus: Display rechtsdrehend .equ LCD_Display_On = 0b0000_1100 ; Display On .equ LCD_FunctionSet = 0b0010_1000 ; 4-bit data, 2-line display, 5x8 font .equ LCD_SetCursor = 0b1000_0000 ; set cursor position .equ LCD_Line1 = 0x00 + LCD_SetCursor ; start of line 1 (0x00..0x13) .equ LCD_Line2 = 0x40 + LCD_SetCursor ; start of line 2 (0x40..0x53) ;************************************************************************** Init_LCD_Sklave: ; ------------------------------------------------------------------------- ; LCD_Sklave initialisieren: Befehl muss 3 mal hintereinander gesendet werden ldi Temp1, LCD_Reset ; 1. LCD Reset : 0b0011_1000 rcall LCD_write_Nibble ; sende Nibble an LCD rcall Wait_4_1mS ; warte 4,1 ms rcall LCD_write_Nibble ; 2. LCD Reset : 0b0011_1000 rcall Wait_100uS ; Warte 100us rcall LCD_write_Nibble ; 3. LCD Reset : 0b0011_1000 rcall Wait_100uS ; Warte 100us ldi Temp1, LCD_4_Bit_Modus ; 4_Bit_Modus : 0b0010_1000 rcall LCD_write_Nibble ; sende Nibble an LCD ; ---------------------------------- ldi Temp1, LCD_FunctionSet ; 4-bit data, 2-line display, 5x8 font rcall Slave_LCE_Commando ldi Temp1, LCD_Display_On ; Display ein rcall Slave_LCE_Commando rcall LCD_Clear_Display ; Löscht Anzeige und Adresse = 0 ldi Temp1, LCD_Entry_Mode ; Cursor Auto-Increment rcall Slave_LCE_Commando ret ;************************************************************************** LCD_Clear_Display: ; Löscht Anzeige und Adresse = 0 ; ------------------------------------------------------------------------- ldi Temp1, LCD_Clear ; 0b00000001 rcall Slave_LCE_Commando ; Löscht Anzeige und Adresse = 0 rcall wait_4_1ms ; > 2 ms ret ;************************************************************************** Slave_LCE_Commando: ; RS-BIT = Low ; ------------------------------------------------------------------------- push Temp1 ; speicher Temp1 andi Temp1, 0b1111_0000 ; oberes Nibble cbr Temp1, (1< LCD DB4 ... DB7 pop Temp1 ; hole Temp1 zurück swap Temp1 ; hhhh_llll <=> llll_hhhh andi Temp1, 0b1111_0000 ; unteres Nibble cbr Temp1, (1< LCD DB4 ... DB7 ret ;************************************************************************** Slave_LCE_DATA: ; RS-BIT = High ; ------------------------------------------------------------------------- push Temp1 ; speicher Temp1 push Temp1 ; speicher Temp1 andi Temp1, 0b1111_0000 ; oberes Nibble sbr Temp1, (1< LCD DB4 ... DB7 pop Temp1 ; hole Temp1 zurück swap Temp1 ; hhhh_llll <=> llll_hhhh andi Temp1, 0b1111_0000 ; unteres Nibble sbr Temp1, (1< LCD DB4 ... DB7 pop Temp1 ; hole Temp1 zurück ret ;************************************************************************** LCD_write_Nibble: ; PD4 ... PD7 ==> LCD DB4 ... DB7 ; ------------------------------------------------------------------------- sbr Temp1, (1< PCF8574T cbr Temp1, (1< PCF8574T ret ;************************************************************************** LCD_Byte_Sklave: ; Temp1 ==> PCF8574 ; ------------------------------------------------------------------------- rcall I2C_Star_Address ; I2C initialisieren und Addresse senden rcall I2C_Write ; Temp1 ==> I2C rcall I2C_Stop ; I2C Stop ret ;**************************************************************************