'----------------------------------------------------------- ' EADOGM132x32.BAS ' (c) 1995-2009 MCS Electronics ' micro : m328p ' demo : SPI graphical display EADOGM132x32 ' IMPORTANT : SPI only allows the WRITE mode. THis mean that setting pixels is not possible. ' for this reason commands as PSET, LINE and CIRCLE are not supported. ' best option would be to display pictures ' fonts and images are compatible with KS108 '----------------------------------------------------------- $regfile = "m328pdef.dat" ' ATmega328P $crystal = 8000000 $hwstack = 40 $swstack = 40 $framesize = 40 $baud = 4800 '$lib "glcdeadogm128x6.lbx" ' specify the used lib $lib "glcdEADOGM132x32.lib" 'the display was connected with these pins Config Graphlcd = 128 * 64eadogm , Cs1 = Portb.2 , A0 = Portb.1 , Si = Portb.3 , Sclk = Portb.5 , Rst = Portb.0 'the best option is to control the reset line of the LCD with the micro so you can reset it controlled at startup Initlcd Cls Config Portd.5 = Output Set Portd.5 Open "comc.0:19200,8,N,1" For Output As #2 'specify the font we want to use Setfont Font6x8 Declare Function Hex2fs20(byval A As Byte) As Word Declare Function Fs202hex(byval A As Word) As Byte Config Base = 0 Dim Hc1 As Word , Hc2 As Word Dim Zaehl As Word ' Init FS20RX Print Chr(2) ; Chr(2) ; Chr(&Hf1) ; Chr(2); 'FS20 Paket empfangen und speichern Print Chr(2) ; Chr(2) ; Chr(&Hf2) ; Chr(2); 'Wetter Paket empfangen und speichern Dim Fs20_strt As Byte Dim Fs20_len As Byte Dim Fs20_id As Byte Dim Fs20_hc1 As Byte Dim Fs20_hc2 As Byte Dim Fs20_ad As Byte Dim Fs20_bef As Byte Dim Fs20_ext As Byte Dim Wue20_strt As Byte Dim Wue20_len As Byte Dim Wue20_id As Byte Dim Wue20_typ As Byte Dim Wue20_ad As Byte Dim Wue20_temp As Integer 'Temperatur in 0,1°C Dim Wue20_temp_l As Byte At Wue20_temp Overlay Dim Wue20_temp_h As Byte At Wue20_temp + 1 Overlay Dim Wue20_feu As Integer 'Luftfeuchtigkeit in 0,1% Dim Wue20_feu_l As Byte At Wue20_feu Overlay Dim Wue20_feu_h As Byte At Wue20_feu + 1 Overlay Dim Wue20_feu_abs As Integer 'absolute Luftfeuchtigkeit in 0,1% Dim Wue20_wind As Integer 'Windgeschwindigkeit in 0,1 km/h Dim Wue20_wind_l As Byte At Wue20_wind Overlay Dim Wue20_wind_h As Byte At Wue20_wind + 1 Overlay Dim Wue20_regenm As Integer 'Regenmenge in Wippenschlägen Dim Wue20_reg_l As Byte At Wue20_regenm Overlay Dim Wue20_reg_h As Byte At Wue20_regenm + 1 Overlay 'es regnet Dim Wue20_regen As Byte Dim Tempw As Integer Dim Tempb1 As Byte Dim Wetter(9 , 3) As Integer Dim Ort(9) As Eram String * 12 Dim Ort_t As String * 12 '( Ort(0) = "------------" Ort(1) = "Aussen " Ort(2) = "Wohnzimmer " Ort(3) = "Keller " Ort(4) = "Kueche " Ort(5) = "Schlafzimmer" Ort(6) = "------------" Ort(7) = "------------" Ort(8) = "------------" ') Dim Fstr1 As String * 5 Dim Fstr2 As String * 5 Dim Fstr3 As String * 5 Dim Tmps1 As Single Dim Tmps2 As Single Dim Tmps3 As Single Dim Tmps4 As Single Dim Tmps5 As Single Dim Tmps6 As Single Dim Tmps7 As Single Config Portd.6 = Input : Portd.6 = 1 Config Portd.7 = Input : Portd.7 = 1 Print #2 , Chr(27) ; "E"; Do If Pind.6 = 1 Then Gosub Read_fs20_schalt 'Wenn FS20-Message da, dann: If Pind.7 = 1 Then Gosub Read_fs20_wetter 'Wenn FS20 Wetter-Message da, dann: Waitms 100 Loop End ' Umrechnen von FS20 nach hex Function Fs202hex(byval A As Word) As Byte Local B As Word Local C As Word Local D As Byte D = 0 B = A \ 1000 D = B - 1 B = B * 1000 A = A - B Shift D , Left , 2 B = A \ 100 D = D + B D = D - 1 B = B * 100 A = A - B Shift D , Left , 2 B = A \ 10 D = D + B D = D - 1 B = B * 10 A = A - B Shift D , Left , 2 B = A - 1 D = D + B Fs202hex = D End Function ' Umrechnen von hex nach fs20 Function Hex2fs20(byval A As Byte) As Word Local B As Word Local C As Word C = 0 B = A Shift B , Right , 6 B = B And 3 Incr B B = B * 1000 C = C + B B = A Shift B , Right , 4 B = B And 3 Incr B B = B * 100 C = C + B B = A Shift B , Right , 2 B = B And 3 Incr B B = B * 10 C = C + B B = A B = B And 3 Incr B C = C + B Hex2fs20 = C End Function Read_fs20_wetter: Print Chr(2) ; Chr(1) ; Chr(&Hf4) ; 'Wetter-Paket lesen Wue20_strt = Waitkey() 'Vorspann: immer &h02 Wue20_len = Waitkey() 'Anzahl Datenbytes einschl. ID Wue20_id = Waitkey() 'ID Wue20_typ = Waitkey() 'Sensor - Typ Wue20_ad = Waitkey() 'Adresse Wue20_temp_h = Waitkey() 'Temperator Highbyte Wue20_temp_l = Waitkey() 'Temperatur Lowbyte Wue20_feu_h = Waitkey() 'Luftfeuchtigkeit Highbyte Wue20_feu_l = Waitkey() 'Luftfeuchtigkeit Lowbyte Wue20_wind_h = Waitkey() 'Windgeschwindigkeit Highbyte Wue20_wind_l = Waitkey() 'Windgeschwindigkeit Lowbyte Wue20_reg_h = Waitkey() 'Regenmenge in Wippenschlägen Highbyte (295 ml/Quadratmeter) Wue20_reg_l = Waitkey() 'Regenmenge in Wippenschlägen Lowbyte (295 ml/Quadratmeter) Wue20_regen = Waitkey() 'Regnet's ? 0=nein ; 1=ja Wetter(wue20_ad , 0) = Wue20_temp Wetter(wue20_ad , 1) = Wue20_feu Tmps1 = Wue20_temp / 10 Tmps1 = Tmps1 + 237.5 Tmps2 = Wue20_temp / 10 Tmps2 = Tmps2 * 7.5 Tmps3 = Tmps2 / Tmps1 Tmps4 = 10 ^ Tmps3 Tmps5 = Wue20_feu / 1000 Tmps6 = Tmps5 * 6.1078 Tmps6 = Tmps6 * Tmps4 Tmps1 = Wue20_temp / 10 Tmps1 = Tmps1 + 273.15 Tmps2 = Tmps6 / Tmps1 Tmps3 = Tmps2 * 216.7 Wue20_feu_abs = Tmps3 * 10 Wetter(wue20_ad , 2) = Wue20_feu_abs Print #2 , Chr(27) ; "E"; For Tempb1 = 1 To 5 Tempw = Wetter(tempb1 , 0) Fstr1 = Str(tempw) Fstr1 = Format(fstr1 , "00.0") Tempw = Wetter(tempb1 , 1) Fstr2 = Str(tempw) Fstr2 = Format(fstr2 , "00.0") Tempw = Wetter(tempb1 , 2) Fstr3 = Str(tempw) Fstr3 = Format(fstr3 , "00.0") Ort_t = Ort(tempb1) Print #2 , Str(tempb1) ; " " ; Ort_t ; " " ; Fstr1 ; " " ; Fstr2 ; " " ; Fstr3; If Tempb1 = 3 Or Tempb1 = 5 Then If Wetter(1 , 2) < Wetter(tempb1 , 2) Then ' Lcdat 4 , 28 , "auf" Print #2 , " auf" Else ' Lcdat 4 , 28 , "zu " Print #2 , " zu" End If Else Print #2 , "" End If Next Print #2 , "" ' Wait 2 Return Read_fs20_schalt: Reset Portd.5 Print Chr(2) ; Chr(1) ; Chr(&Hf3) ; 'FS20 Paket bereitstellen Fs20_strt = Waitkey() 'Vorspann: immer &h02 Fs20_len = Waitkey() 'Anzahl Datenbytes einschl. ID Fs20_id = Waitkey() 'Holen ID Fs20_hc1 = Waitkey() 'Holen Hauscode 1 Fs20_hc2 = Waitkey() 'Holen Hauscode 2 Fs20_ad = Waitkey() 'Holen Adresse Fs20_bef = Waitkey() 'Holen Befehl Fs20_ext = Waitkey() 'Holen Extention Hc1 = Hex2fs20(fs20_hc1) Hc2 = Hex2fs20(fs20_hc2) Lcdat 1 , 79 , " " ; Str(fs20_hc1) ; " " ; Str(fs20_hc2) ; " " Lcdat 2 , 79 , " " ; Hex(fs20_hc1) ; " " ; Hex(fs20_hc2) Lcdat 3 , 79 , Hc1 ; " " ; Hc2 Lcdat 4 , 79 , Hex(fs20_ad) ; " " ; Hex(fs20_bef) ; " " ; Hex(fs20_ext) Incr Zaehl Lcdat 4 , 1 , Hex(zaehl) Set Portd.5 Return Plaatje: 'include the picture data '$bgf "ks108.bgf" 'include used fonts $include "font6x8.font" '$include "font16x16sajat.font"