'----------------------------------------------------------- ' Test EADOGXL240-7 ' FS20 Empfang '----------------------------------------------------------- $regfile = "m328pdef.dat" ' ATmega328P $crystal = 8000000 $hwstack = 40 $swstack = 40 $framesize = 40 $baud = 4800 Config Scl = Portc.5 ' we need to provide the SCL pin name Config Sda = Portc.4 ' we need to provide the SDA pin name $lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI Config Twi = 400000 ' speed 400 KHz I2cinit $lib "glcdEADOGMXL240-7-I2C.lib" ' override the default lib with this special one #if _build < 2078 Dim ___lcdrow As Byte , ___lcdcol As Byte #endif Config Graphlcd = Custom , Cols = 240 , Rows = 128 , Lcdname = "EADOGXL240-7" Cls 'specify the font we want to use Setfont Font6x8 '( Setfont Font6x8 Lcdat 1 , 1 , "11111111" Lcdat 2 , 1 , "88888888" Lcdat 12 , 64 , "MCS Electronics" , 1 Showpic 60 , 0 , Plaatje Circle(30 , 30) , 20 , 255 Line(0 , 0) -(239 , 127) , 255 ' diagonal line Line(0 , 127) -(239 , 0) , 255 ' diagonal line Wait 5 Cls ') Config Portd.5 = Output 'Beeper Set Portd.5 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 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 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) Lcdat Tempb1 , 1 , Str(tempb1) ; " " ; Ort_t ; " " ; Fstr1 ; " " ; Fstr2 ; " " ; Fstr3 If Tempb1 = 3 Or Tempb1 = 5 Then If Wetter(1 , 2) < Wetter(tempb1 , 2) Then Lcdat Tempb1 , 180 , "auf" Else Lcdat Tempb1 , 180 , "zu " End If Else End If Next 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 10 , 1 , "Hauscode dezimal: " ; Fs20_hc1 ; " " ; Fs20_hc2 ; " " Lcdat 11 , 1 , "Hauscode hex : " ; Hex(fs20_hc1) ; " " ; Hex(fs20_hc2) Lcdat 12 , 1 , "Hauscode FS20 : " ; Hc1 ; " " ; Hc2 Lcdat 13 , 1 , "Adresse hex : " ; Hex(fs20_ad) Lcdat 14 , 1 , "Befehl hex : " ; Hex(fs20_bef) Lcdat 15 , 1 , "Erweiterung hex ; " ; Hex(fs20_ext) Incr Zaehl Lcdat 16 , 1 , "Zaehler dezimal : " ; Zaehl ; " " Set Portd.5 Return 'include used fonts $include "font6x8.font" 'include the picture data 'Plaatje: ' $bgf "ks108.bgf" 'include the picture data