Hallo Wolf!
Hier noch schnell die Bilder und der Programmcode!
Die LIB hast du wieder einmal per PN "bekommen".
Programmcodebeispiel:
Code:
'
$regfile = "m16def.dat"
$crystal = 8000000 'intern !
$hwstack = 128
$swstack = 128
$framesize = 128
' ATmega16
' +---v---+
' (XCK/T0) PB0 |1 40| PA0 (ADC0)------Taster1
' (T1) PB1 |2 39| PA1 (ADC1)------Taster2
' (INT2/AIN0) PB2 |3 38| PA2 (ADC2)
' (OC0/AIN1) PB3 |4 37| PA3 (ADC3)
' (SS) PB4 |5 36| PA4 (ADC4)
' (MOSI) PB5 |6 35| PA5 (ADC5)
' (MISO) PB6 |7 34| PA6 (ADC6)
' (SCK) PB7 |8 33| PA7 (ADC7)
' RESET |9 32| AREF
' VCC |10 31| GND
' GND |11 30| AVCC
' XTAL2 |12 29| PC7 (TOSC2)
' XTAL1 |13 28| PC6 (TOSC1)
' (RXD) PD0 |14 27| PC5 (TDI)
' (TXD) PD1 |15 26| PC4 (TDO)
' (INT0) PD2 |16 25| PC3 (TMS)
' (INT1) PD3 |17 24| PC2 (TCK)
' (OC1B) PD4 |18 23| PC1 (SDA)-------I2C
' (OC1A) PD5 |19 22| PC0 (SCL)-------I2C
' (ICP1) PD6 |20 21| PD7 (OC2)-------LED
' +-------+
'
' ================================================
' Bestimme die Ein- und Ausgänge
Ddra = &B_0000_0000 '1 ist Ausgang 0 ist Eingang
Porta = &B1111_1111
Ddrb = &B_0000_0000 '1 ist Ausgang 0 ist Eingang
Portb = &B1111_1111
Ddrc = &B_1111_1111 '1 ist Ausgang 0 ist Eingang
Portc = &B0000_0000
Ddrd = &B_1111_1111 '1 ist Ausgang 0 ist Eingang
Portd = &B0000_0000 'auf Hi oder Low setzen
Led Alias Portd.7
Taster Alias Pina.0
Taster2 Alias Pina.1
' ==============================================================================
' I2C-Config
Config Scl = Portc.0 'I2C SCL
Config Sda = Portc.1 'I2C SDA
Config I2cdelay = 1
I2cinit
'**************************************************************
' modifizierte I2C-LCD-LIB von Kent Andersson----------------------------------
$lib "Lcd_arduino.lib" 'LIB für ein Arduino-I2C-LCD
Const Pcx8574_lcd = &H70 'I2C-Adresse des PCx8574(A)
'!rcall _init_LCD
Dim _hbl As Byte 'HBL= HintergrundBeleuchtung
Const Ein = 8 'HBL-Pin High
Const Aus = 0 'HBL-Pin Low
' PCx8574(A)
' __
' A0 -o|1 |o- Vdd
' A1 -o| |o- SDA
' A2 -o| |o- SCL
' RS -o| |o- n.c. (INT)
' RW -o| |o- DB7
' E -o| |o- DB6
' BL -o| |o- DB5
' GND -o|_9|o- DB4
' LCD 4x16
' ---------------o Vss----------+
' | o Vdd |
' | o Vo |
' | o RS |
' | o R/W----------+
' | LCD o E |
' | o DB0----------+
' | 4x16 o DB1----------+
' | o DB2----------+
' | o DB3----------+
' | o DB4 |
' | HD44780 o DB5 ===
' | o DB6 GND
' | o DB7
' | o LED+
' | o LED-
' | |
' | |
' | |
' | |
' | |
' | |
' | |
' | |
' | |
' ---------------
' ==============================================================================
Dim I As Byte 'Indexzähler
Dim Tb As Bit 'Toggle-Bit
Dim Ab As Bit 'Anzeige-Bit
Dim Licht As Bit 'Beleuchtungsbit
' #############################################################################
' Anfangswerte:
Cls
Tb = 0
Ab = 0
_hbl = Aus
' ################################################
' # #
' #---------------Arbeitsschleife----------------#
' # #
' ################################################
Do 'Hauptschleife-Beginn
If Taster = 0 Then 'Displayanzeige wechseln
Toggle Tb
Reset Ab
Waitms 100
Bitwait Taster , Set
Else
End If
If Taster2 = 0 Then
Toggle Licht
If Licht = 0 Then
Reset Led
Else
Set Led
End If
Waitms 100
Bitwait Taster2 , Set
Reset Ab
Else
End If
If Tb = 0 Then
If Ab = 0 Then
If Licht = 0 Then
_hbl = Aus
Else
_hbl = Ein
End If
' !rcall _init_LCD
Locate 1 , 1
Lcd "AVR-Praxis Forum"
Locate 2 , 1
Lcd "-----Cassio-----"
Locate 1 , 17
Lcd "I2C-LCD Arduino!"
Locate 2 , 17
Lcd "****05.06.11****"
Set Ab
Else
End If
Else
If Ab = 0 Then
If Licht = 0 Then
_hbl = Aus
Else
_hbl = Ein
End If
' !rcall _init_LCD
Locate 1 , 1
Lcd "12345678901234563456789012345678"
Locate 2 , 1
Lcd "23456789012345674567890123456789"
Set Ab
Else
End If
End If
Loop 'Hauptschleife-Ende
End 'end program
Nun noch die Bilder.........
Einmal mit "Text 1" und eingeschalteter Beleuchtung:
Anhang anzeigen 3401
Dann umgeschaltet auf "Text 2" und Beleuchtung:
Anhang anzeigen 3403
Zum Schluss wieder "Text 1" OHNE Hintergrundbeleuchtung:
Anhang anzeigen 3402
Ich hoffe, es funktioniert bei dir nun auch!
Grüße,
Cassio