'BASCOM-Code
'PCF8574A Pins:
' D7654_3210
' |||| ||||
' &B0000_0000
' |||| ||||
' |||| |||D4
' |||| ||D5
' |||| |D6
' |||| D7
' |||RS
' ||RW
' |E2
' E1
I2cstart
I2cwbyte Pcf8574_lcd
Waitms 250
I2cwbyte &B00010000
I2cwbyte &B11000000 'Display löschen 0000_0001
I2cwbyte &B00010000
Waitms 250
I2cwbyte &B00010001
I2cwbyte &B11000001
I2cwbyte &B00010001
Waitms 250
I2cwbyte &B00010000
I2cwbyte &B11000000 'Cursor Home
I2cwbyte &B00010000
Waitms 250
I2cwbyte &B00010010
I2cwbyte &B11000010
I2cwbyte &B00010010
Waitms 250
I2cwbyte &B00010000
I2cwbyte &B11000000 'Entry Mode Set 0000_0110
I2cwbyte &B00010000
Waitms 250
I2cwbyte &B00010110
I2cwbyte &B11000110
I2cwbyte &B00010110
Waitms 250
I2cwbyte &B00010000
I2cwbyte &B11000000 'Display on, Cursor off, Blink off
I2cwbyte &B00010000
Waitms 250
I2cwbyte &B00011100
I2cwbyte &B11001100
I2cwbyte &B00011100
Waitms 250
I2cwbyte &B00010010
I2cwbyte &B11000010 '4Bit set
I2cwbyte &B00010010
Waitms 250
I2cwbyte &B00011010
I2cwbyte &B11001010 '2/4 Zeilen , Inverter ein
I2cwbyte &B00011010
'I2cwbyte &B00011000
'I2cwbyte &B11001000 '2/4 Zeilen , Inverter aus
'I2cwbyte &B00011000
Waitms 250
I2cwbyte &B00010000
I2cwbyte &B11010000
I2cwbyte &B00010000
Waitms 250
I2cwbyte &B00010000
I2cwbyte &B11010000
I2cwbyte &B00010000
I2cstop
'geänderte ASM-LIB
[_Init_LCD]
_Init_LCD:
*BASIC: waitms 50
ldi r16,&hc0
Rcall _Send_to_LCD
Ldi _temp1, &hc3
Rcall _Send_to_LCD
Ldi _temp1, &h03
Rcall _Send_to_LCD
*BASIC: waitms 2
Ldi _temp1, &hc3
Rcall _Send_to_LCD
Ldi _temp1, &h03
Rcall _Send_to_LCD
*BASIC: waitms 2
Ldi _temp1, &hc3
Rcall _Send_to_LCD
Ldi _temp1, &h03
Rcall _Send_to_LCD
*BASIC: waitms 2
Ldi _temp1, &hc2
Rcall _Send_to_LCD
Ldi _temp1, &h02
Rcall _Send_to_LCD
*BASIC: waitms 2
Ldi _temp1, &h2c
Rcall _Write_lcd_byte
Ldi _temp1, &h0c
Rcall _Write_lcd_byte
Ldi _temp1, &h06
Rjmp _Write_lcd_byte
[END]
[_Write_lcd]
_Write_lcd:
* lds r16,{_lcd_e}
sbr r16,&h10 ;set RS flag (4 high bits is used as control)
rjmp _write_lcd_byte
_Lcd_Control:
* lds r16,{_lcd_e}
_write_lcd_byte:
push r24
Swap _temp1
Rcall _Write_lcd_Nibble
pop r24
_Write_lcd_nibble:
Cbr _temp1,&HF0 ; E1, E2, RW, RS low
_Send_to_LCD:
push r26
push r27
ldi r25,3
_send_3_times:
*BASIC: i2csend pcf8574_LCD,_temp1
eor _temp1,R16 ; Xor E1 and/or E2 to set them
; @genus(250)
ldi r26,0
_LCD_delay:
dec R26
brne _LCD_delay
Dec R25
Brne _send_3_times
eor _temp1,R16 ; Xor to restore to initial state (even number of times)
pop r27
pop r26
ret
[END]
'Beispielcode in C
void lcd_init (void) //LCD I2C initialisation
{
i2c_start_wait(LCD+I2C_WRITE);
i2c_write(0xC3); //* HD44780 initialisation
i2c_write(0x03); //*
_delay_ms(2); //*
i2c_write(0xC3); //*
i2c_write(0x03); //*
_delay_ms(2); //*
i2c_write(0xC3); //*
i2c_write(0x03); //*
_delay_ms(2);
i2c_write(0xC2); //* Enter 4-bit-mode
i2c_write(0x02); //*
_delay_ms(2);
i2c_stop();
sendDATA (C,0x2C,_2); // System set command
sendDATA (C,0x0C,_2); // Display on w/o any cursor
sendDATA (C,0x06,_2); // Entry mode set/increment right,move CRSR
custCHAR (4,0x0A,0x00,0x0E,0x11,0x11,0x1F,0x11,0x11);
custCHAR (5,0x0A,0x00,0x0E,0x11,0x11,0x11,0x11,0x0E);
custCHAR (6,0x0A,0x00,0x11,0x11,0x11,0x11,0x11,0x0E);
custCHAR (7,0x06,0x09,0x09,0x0E,0x09,0x09,0x16,0x00);
init=0;
}
'BASCOM-Code
Waitms 15
I2cstart
I2cwbyte Pcf8574_lcd
I2cwbyte &HC3
I2cwbyte &H03
Waitms 5
I2cwbyte &HC3
I2cwbyte &H03
Waitms 1
I2cwbyte &HC3
I2cwbyte &H03
Gosub Rw_test
I2cwbyte &HC2
I2cwbyte &H02
Gosub Rw_test
I2cstop
'BASCOM-Code
I2cstart
I2cwbyte Pcf8574_lcd
I2cwbyte &HC2 'Set 4 Bit
Gosub Rw_test
I2cwbyte &H12
Gosub Rw_test
I2cwbyte &HCA
Gosub Rw_test
I2cwbyte &H1A
Gosub Rw_test
I2cwbyte &HC0
Gosub Rw_test 'Entry Mode Set 0000_0110
I2cwbyte &H10
Gosub Rw_test
I2cwbyte &HC6
Gosub Rw_test
I2cwbyte &H16
Gosub Rw_test
I2cwbyte &HC0 'Display on, Cursor off, Blink off
Gosub Rw_test
I2cwbyte &H10
Gosub Rw_test
I2cwbyte &HCC
Gosub Rw_test
I2cwbyte &H1C
Gosub Rw_test
I2cwbyte &HC0 'Cursor Home
Gosub Rw_test
I2cwbyte &H10
Gosub Rw_test
I2cwbyte &HC2
Gosub Rw_test
I2cwbyte &H12
Gosub Rw_test
I2cstop
willst du da auch mal HV-Programmierung probieren ?Vielleicht hilft es ja genauso wie bei meinem Mega644p........
Einfach lange liegen lassen und plötzlich funktionieren sie wieder.