Code:
'**********************************************************
'Programm : Text aus EEPROM, aus bestimmter Adresse, holen und auf GLCD anzeigen
'By : mat-sche
'Compiler : BASCOM-AVR 1.11.9.3
'Hardware : GLCD 128x64 KS108
'
'
' EEprom 24c65 (64kBit) an Hardware TWI
'Chip type : MEGAm644p
'Date : 29.10.2009
'**********************************************************
$regfile = "m644pdef.dat" ' specify the used micro
$crystal = 10000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
'some routines to control the display are in the glcdKS108.lib file
$lib "glcdKS108.lib"
$lib "i2c_TWI.lib" ' Lib bei Verwendung von Hardware TWI
'First we define that we use a graphic LCD
Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Portd , Ce = 6 , Ce2 = 5 , Cd = 4 , Rd = 3 , Reset = 7 , Enable = 2
'------------------------------------------------------------------------------- Config TWI
Config Twi = 400000 ' Init TWBR und TWSR
' TWI gleich einschalten, das macht Bascom ansonsten erst beim I2CStart !
Twcr = &B00000100 ' nur TWEN setzen
Config Sda = Portc.1 'SDA und SCL als Hardware-TWI definieren
Config Scl = Portc.0
Const E_prom_w = &HAE 'Epromadresse 160 (A1/2/3 auf GND) schreiben
Const E_prom_r = &HAF 'Epromadresse 160+1 für schreiben der Daten
'EEprom 24C32,24C128, 24C256 haben im Gegensatz zu den 24C16'er einen Adressraum von zwei Byte.
'Weil grösserer Speicherbereich im EEprom vorhanden ist Darum muss man den Adressbereich in High und Low Adressbereich
'trennen. (Zuerst High-Adressbereich schreiben und dann Low-Adressbereich)
Dim E_dat As Byte 'Zwischenspeicher der TWI-Daten
Dim E_str1 As String * 25 'String-Daten gefüllt als Adressüberlage beginnend bei E_str(1)
Dim E_str(25) As Byte At E_str1 Overlay 'Bytearray für die Daten aus dem EEPROM
Dim Idx1 As Byte , Str_z As Byte 'Zähler
Dim E_ah As Byte 'höherwertiges Byte der SpeicherAdresse (Adresse=Word)
Dim E_al As Byte 'niederwertiges Byte der SpeicherAdresse (Adresse=Word)
Dim E_addr As Word , Adr_1 As Word , Adr_2 As Word 'SpeicherAdresse EEprom
Dim E_dat_r As Byte 'Daten der zu lesenen Daten aus EEprom
Dim E_dat_w As Byte
Declare Sub E_write(byval E_addr As Word , E_dat_w As Byte) 'Sub zum schreiben in EEprom mit Übergabe einer Kopie der Variable (Eaddr/E_dat_w)
Declare Sub E_read(byval E_addr As Word , E_dat_r As Byte) 'Sub zum lesen aus EEprom
Declare Sub E_red_hilfe(byval Adr_1 As Word , Byval Adr_2 As Word , Byval Line_x As Byte , Byval Line_y As Byte ) 'Sub zum Auslesen des EEPROM:
' Begin Adressbereich , Ende Adressbereich , Anzeigeort für X auf dem LCD, - Y-Ort
Speaker Alias Portc.3
'Dim variables (y not used)
Dim X As Byte , Y As Byte
Do
'specify the font we want to use
Setfont Font8x8
Call E_red_hilfe(&H50 , &H67 , 2 , 3 ) ' Daten aus dem EEPROM ab Adresse &H50 bis &H67 holen und auf Linie X 2, Linie Y 3 schreiben
Call E_red_hilfe(&H68 , &H7F , 3 , 3 )
Call E_red_hilfe(&H80 , &H97 , 4 , 3 )
Call E_red_hilfe(&H98 , &HAF , 5 , 3 )
Call E_red_hilfe(&Hb0 , &HC7 , 6 , 3 )
Wait 1
Print "Cls"
Cls
Wait 1
'specify the font we want to use
Setfont Font8x8
Sound Speaker , 200 , 200
'You can use locate but the columns have a range from 1-128
'When you want to show somthing on the LCD, use the LDAT command
'LCDAT Y , COL, value
Lcdat 1 , 1 , "123"
'lcdat accepts an additional param for inversing the text
Lcdat 2 , 1 , "123" , 1 ' will inverse the text
'Now use a different font
'Setfont Font8x8
'since the 16*16 font uses 2 rows, show on row 3
'Lcdat 1 , 1 , "2345"
'Lcdat 2 , 56 , "2345656"
Wait 1
Line(0 , 0) -(127 , 64) , 1 'make line
Wait 2
Line(0 , 0) -(127 , 64) , 0 'remove line
For Y = 1 To 20
Circle(30 , 30) , Y , 1
Waitms 100
Next
Wait 1
Glcdcmd &H3E , 1 : Glcdcmd &H3E , 2 ' both displays off
Wait 1
Glcdcmd &H3F , 1 : Glcdcmd &H3F , 2 'both on
'GLCDCMD accepts an additional param to select the chip
'With multiple, GLCDCMD statements, it is best to specify the chip only the first time
'show a comnpressed picture
Loop
End 'end program
'////////////////// Subroutinen ////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////////////
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Routine to write the 24C65
Sub E_write(byval E_addr As Word , E_dat_w As Byte )
E_ah = High(e_addr) 'E_ah = EEprom high Adressbyte der jeweiligen Word-Adresse (H&10)
E_al = Low(e_addr) 'E_ah = EEprom low Adressbyte der jeweiligen Word-Adresse (H&10)
I2cstart 'Start I2C
I2cwbyte E_prom_w 'Sende Slave Adresse
I2cwbyte E_ah 'Sende Speicheradresse High
I2cwbyte E_al 'Sende Speicheradresse Low
I2cwbyte E_dat_w 'Sende Daten Werte
I2cstop 'Stop I2C
Waitms 10
End Sub
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Routine to read the 24C65
Sub E_read(byval E_addr As Word , E_dat_r As Byte)
E_ah = High(e_addr)
E_al = Low(e_addr)
I2cstart
I2cwbyte E_prom_w
I2cwbyte E_ah
I2cwbyte E_al
I2cstart
I2cwbyte E_prom_r
I2crbyte E_dat_r , Nack
I2cstop '
End Sub
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Routine to read a String from EEPROM and send to the GLCD
Sub E_red_hilfe(byval Adr_1 As Word , Byval Adr_2 As Word , Byval Line_x As Byte , Byval Line_y As Byte )
Idx1 = 1
For E_addr = Adr_1 To Adr_2 ' Adresse &H.. bis &H..
Call E_read(e_addr , E_dat) ' Daten aus Sub E_READ(BYVAL E_ADDR AS WORD , E_DAT_R AS BYTE) holen
E_str(idx1) = E_dat 'Daten in ein Bytearray schreiben
Incr Idx1 'Bytearray Speicherstelle erhöhen
Next E_addr 'nächste Adresse holen
Incr Str_z 'etwas zählen
Lcdat Line_x , Line_y , E_str1 'Daten auf bestimmten Ort vom GLCD anzeigen lassen
End Sub
'we need to include the font files
'Notice that this is a testfont with only numbers defined !
'$include "smallfont8x8.font"
$include "font8x8.font"
'$include "font16x16.font"
Meine Dienste werden damit gut bedient, vielleicht braucht dies ja mal jemand
Lesezeichen