Sziasztok!
Olvasgatom a HD44780 adatlapját, de valamit félreértek. Programoznám az LCD-t avr-ből, de i2c portbővítőn keresztül. (mcp23016) Valahol a 26. topicoldalon volt hogy ezt valaki valahogy megoldotta hogy az lcd libet i2csítette (vagymi
) de sajnos a letöltések nem üzemelnek (egy ideje) és én meg nem jövök rá hol rontom el. Mondjuk én a kályhás verziót használom:
Kód: Egész kijelölése
$regfile = "m8def.dat"
$crystal = 8000000
'$sim
$hwstack = 64
$swstack = 32
$framesize = 40
Config Sda = Portc.4
Config Scl = Portc.5
I2cinit
Motor Alias Portb.0
Config Motor = Output
Gomb Alias Pind.3
Config Gomb = Input
Enable Interrupts
Enable Int1
On Int1 Button
Dim Startline As Bit , Startchr As Byte , Send As String * 16 'startline sor, startchr karakter pozició, send szöveg
Dim Gowr As Bit
Dim Lsb As Byte , Msb As Byte , 4bl As Byte , 4bh As Byte
Dim Char As Byte
Dim Lin As Byte , Chpos As Byte
Dim Trans As Byte 'Átvivendő adat
'################# Constansok ######################
Const Waddress = &H40
Const Raddress = &H41
Const Chrwr = &B00110000
Declare Sub Wbutt()
Declare Sub I2c_write(byval Cmd As Byte , Byval Lsb As Byte , Byval Msb As Byte)
Declare Sub I2c_read
Declare Sub Create_char(byval Char As Byte)
Declare Sub I2c_lcd(byval Lin As Byte , Byval Chpos As Byte , Byval Char As Byte)
Declare Sub Stwr()
Declare Sub Endwr()
'########################## Program ###############################
Waitms 250 'Bekapcs várakozás
Call I2c_write(&H02 , &HFF , &HFF)
Call I2c_write(&H06 , &H00 , &HFF) 'inicializálás
Startline = 0
Startchr = 0
Send = "bla"
' LCD Pins
' 7 6 5 4 3 2 1 0
' N N RS E D4 D5 D6 D7
'Call I2c_write(&H02 , &B00000000 , 0) '4 bites lcd üzemmód
Call I2c_write(&H02 , &B00000100 , 0) '4 bites lcd üzemmód
Call I2c_write(&H02 , &B00000000 , 0) 'display on
Call I2c_write(&H02 , &B00000111 , 0) 'display on
Call I2c_write(&H02 , &B00000000 , 0) 'shift cursor
Call I2c_write(&H02 , &B00000000 , 0) 'shift cursor
'Call I2c_write(&H02 , &B00000110 , 0) 'display bekapcsolása
'Goto Wbutt
Main:
' nop
'Call I2c_lcd(0 , 0 , 0)
Waitms 500
If Startchr = 255 Then
Startchr = 0
End If
Startchr = Startchr + 1
' Call Create_char(startchr)
Call I2c_lcd(0 , 0 , Startchr)
'Gowr = 0
Goto Main
Button:
Gowr = 1
Return
Sub Wbutt()
Gowr = 0
Do
'nop
Loop Until Gowr = 1
Gowr = 0
End Sub
Sub I2c_write(byval Cmd As Byte , Byval Lsb As Byte , Byval Data2 As Byte)
' Writes data to the I2C
Toggle Motor
I2cstart 'Generate A Start Condition
I2cwbyte Waddress 'Transmit The "ADDRESS and WRITE" Byte
I2cwbyte Cmd 'Transmit The Command Byte
I2cwbyte Lsb 'Transmit First Data Byte
I2cwbyte Msb 'Transmit Second Data Byte
I2cstop 'Generate a STOP condition
Waitus 50 'Some delay may be necessary for back to back transmitions
End Sub
Sub I2c_read
' Read data from the I2C
I2cstart 'Generate START condition
I2cwbyte Waddress 'Transmit The "ADDRESS and WRITE" Byte
I2cwbyte &H00 'Transmit The Command Byte
I2cstop 'Generate a STOP condition
I2cstart 'Generate a START condition
I2cwbyte Raddress 'Transmit ADDRESS with READ command
I2crbyte Lsb , Ack 'Receive first DATA byte (LSB) and acknowledge
I2crbyte Msb , Nack 'Receive second DATA byte (MSB) and don't acknowledge
I2cstop 'Generate a STOP condition
End Sub
Sub Create_char(byval Char As Byte)
4bh = Char
4bl = Char
Shift 4bh , Right , 4
Shift 4bl , Left , 4
Shift 4bl , Right , 4
4bh = Chrwr Xor 4bh
4bl = Chrwr Xor 4bl
End Sub
Sub I2c_lcd(byval Lin As Byte , Byval Chpos As Byte , Byval Char As Byte)
' LCD Pins
' 7 6 5 4 3 2 1 0
' N N RS E D4 D5 D6 D7
Call Create_char(char)
Call Stwr
Trans = &B00110000 'RS magasan az iráshoz
Trans = Trans Or 4bl 'befüzzük az alsó biteket
Call I2c_write(&H02 , Trans , 0)
Trans = Trans And 11110000 'az alsó biteket töröljük
Trans = Trans Or 4bh 'befüzzük az felső biteket
Call I2c_write(&H02 , Trans , 0)
Call Endwr
End Sub
Sub Stwr()
Trans = &B00100000 'RS magasan az iráshoz
Call I2c_write(&H02 , Trans , 0)
Trans = &B00110000 'RS magasan az iráshoz E odaadva, adat jön.
Call I2c_write(&H02 , Trans , 0)
End Sub
Sub Endwr()
Trans = &B00100000 'RS magasan az iráshoz E elvéve, adat vége
Call I2c_write(&H02 , Trans , 0)
End Sub
Ez egy próbaprogram. Se nem szép se nem jó. De ha jól értelmeztem a leírást ennek működnie kellene. Mégsem teszi.
A programnak elvileg az összes karaktert egymás után ki kell írnia az lcd-re. R/W fixen földön így az azért nem szerepel a programban.