Az lenne a kérdésem hogy hol lehet a hiba?
Kód: Egész kijelölése
$regfile = "m644def.dat"
$crystal = 11059200
$baud = 19200
$hwstack = 100
$swstack = 130
$framesize = 100
'I2C____________________________________________________________________________
Config Sda = Portc.1
Config Scl = Portc.0
Config I2cdelay = 10
I2cinit
$lib "#lcd_i2c-bl_mcp23017.lib" 'My compiled i2c driver for the LCD
Const _i2c_lcd_address_w40 = &B01000000 'MCP23017
Const _i2c_lcd_bl = 1 'Backlight yes/no
Config Lcd = 16 * 2
Initlcd
Cls
Initlcd
Cls
Main:
Lcd "Hello world."
End
#lcd_i2c-bl_mcp23017.lib tartalma:
Kód: Egész kijelölése
copyright = Robert Cseh (csehrobert@tavir.hu)
www = avr.tavir.hu
email = csehrobert@tavir.hu
comment = I2C LCD driver for MCP23017
libversion = 1.00
date = 10 feb 2007
statement = You are free to use this code any way you like.
statement = Please inform me any tips via mail about this library.
history = No known bugs.
;define a constant named i2c_lcd_address_w pointing to the i2c address
;_lcd_bl is a backlight switcher.
;
;Connect the following pins from MCP23008 to LCD
;
;P0 - D4
;P1 - D5
;P2 - D6
;P3 - D7
;P4 - RS
;P5 - RW (not used, set to 0 to ground for write)
;P6 - Bl (backlight switch)
;P7 - E1
[_Init_LCD]
_Init_LCD:
*BASIC: I2cinit
*BASIC: I2cstart
*BASIC: I2cwbyte _i2c_lcd_address_w
*BASIC: I2cwbyte &H0A
*BASIC: I2cwbyte &B00001100
*BASIC: I2cstop
*BASIC: I2cstart
*BASIC: I2cwbyte _i2c_lcd_address_w
*BASIC: I2cwbyte 1
*BASIC: I2cwbyte 0
*BASIC: I2cstop
*BASIC: I2cstart
*BASIC: I2cwbyte _i2c_lcd_address_w
*BASIC: I2cwbyte 0
*BASIC: I2cwbyte 255
*BASIC: I2cstop
*BASIC: I2cstart
*BASIC: I2cwbyte _i2c_lcd_address_w
*BASIC: I2cwbyte &H0C
*BASIC: I2cwbyte 255
*BASIC: I2cstop
*BASIC: I2cstart
*BASIC: I2cwbyte _i2c_lcd_address_w
*BASIC: I2cwbyte &H02
*BASIC: I2cwbyte 255
*BASIC: I2cstop
*BASIC: waitms 50
ldi r16,128 ; this is to make the initialization on both halfs of a line LCD
Ldi _temp1, &h03 ; at init-time I call all routines before _lcd_e is loaded into r16
Rcall _Send_to_LCD
*BASIC: waitms 4
Rcall _Send_to_LCD
Rcall _Send_to_LCD
Ldi _temp1, &h02
Rcall _Send_to_LCD
Ldi _temp1, &h28
Rcall _Write_lcd_byte ;RS flag should to be 0, so jump directly to write byte
Ldi _temp1, &h08
Rcall _Write_lcd_byte
Ldi _temp1, &h0c
Rcall _Write_lcd_byte
Ldi _temp1, &h01
Rjmp _Write_lcd_byte
[END]
[_Write_lcd]
_Write_lcd:
ldi r16, 128
sbr r16,&h10 ;set RS flag (4 high bits is used as control)
rjmp _write_lcd_byte
_Lcd_Control:
ldi r16, 128
_write_lcd_byte:
push r24
Swap _temp1
Rcall _Write_lcd_Nibble
pop r24
_Write_lcd_nibble:
Cbr _temp1,&HF0 ; E1, RW, RS low
_Send_to_LCD:
push r26
push r27
ldi r25,3
_send_3_times:
*BASIC: I2cstart
*BASIC: I2cwbyte _i2c_lcd_address_w
*BASIC: I2cwbyte &H15
*BASIC: _temp1.6=_i2c_lcd_bl
*BASIC: I2cwbyte _temp1
*BASIC: i2cstop
eor _temp1,R16 ; Xor E1 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]