'-------------------------------------------------------------- ' Test EA DOGM204 ' DCF77 - Empfang ' RTC RV3029-C2 ' Tasten-Abfrage mit PCF8574 ' Prozessor: ATmega328 ' Board: Elektor t-Board 28 ' BASCOM Version 2.0.7.8 ' erstellt Jan.2015 H.-W. Hollarek '-------------------------------------------------------------- $regfile = "m328def.dat" $hwstack = 32 $swstack = 32 $framesize = 40 $crystal = 16000000 $baud = 9600 Baud = 9600 Config Portc = Output Config Portb.0 = Output Config Portb.1 = Output Config Portb.2 = Output Portb.0 = 0 'RS Portb.1 = 0 'E Portb.2 = 0 'Reset Waitms 200 Portb.2 = 1 Waitms 50 Portb.2 = 0 Waitms 50 Portb.2 = 1 Waitms 50 Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portb.1 , Rs = Portb.0 Config Lcd = 20 * 4a , Chipset = Ks077 Config Base = 0 Config Dcf77 = Pind.6 , Timer = 1 , Timer1sec = 1 , Debug = 1 Config Date = Dmy , Separator = . Enable Interrupts Dim A As Byte Dim Cmd_byte As Byte Dim Zaehler As Byte , Taste As Byte , Temp1 As Byte , Temp2 As Byte , Temp3 As Byte 'Init lcd Restore Init_werte Do Read Cmd_byte If Cmd_byte = 255 Then Exit Do Gosub Lcd_command Loop Locate 1 , 1 : Lcd "Hello World" Locate 2 , 1 : Lcd "line 2" Locate 3 , 1 : Lcd "line 3" Locate 4 , 1 : Lcd "line 4" Wait 1 Cls $lib "i2c_twi.lbx" Config Scl = Portc.5 Config Sda = Portc.4 Config Twi = 400000 I2cinit I2cstart I2cwbyte &H40 I2cwbyte &B0011_1111 I2cstop Dim Status As Byte 'Waitms 100 I2cstart I2cwbyte &HAC 'slave-adr schreiben I2cwbyte &B00000011 'register-adr I2cstart I2cwbyte &HAD I2crbyte Status , Nack 'register-inhalt; umstellen auf Bank 1 I2cstop Locate 1 , 1 Lcd Bin(status) ; " Status" Status = Status And &B00100000 If Status > 0 Then I2cstart I2cwbyte &HAC 'slave-adr schreiben I2cwbyte &B00000011 'register-adr I2cwbyte &B00000000 'register-adr I2cstop I2cstart I2cwbyte &HAC 'slave-adr schreiben I2cwbyte &B00000000 'register-adr I2cwbyte &B00000001 'register-inhalt I2cstop End If Wait 1 Dim Zaehl As Byte 'Dim Temp As Byte Config Portd.7 = Output Dim Sekunden As Byte , Sekunden_alt As Byte Dim _sec_alt As Byte Dim Minuten As Byte Dim Stunden As Byte Dim Tag As Byte Dim Wochentag As Byte Dim Monat As Byte Dim Jahr As Byte Dim Wt(8) As String * 2 Wt(0) = "--" Wt(1) = "So" Wt(2) = "Mo" Wt(3) = "Di" Wt(4) = "Mi" Wt(5) = "Do" Wt(6) = "Fr" Wt(7) = "Sa" Dim Td(7) As Byte Dim Td_temp(7) As Byte Cls Do Td(0) = &B00001000 ' Page 1 lesen = Datum/Uhrzeit I2creceive &HAC , Td(0) , 1 , 7 Sekunden = Td(0) ' And &H7F Minuten = Td(1) ' And &H7F Stunden = Td(2) ' And &H7F Tag = Td(3) Wochentag = Td(4) Monat = Td(5) Jahr = Td(6) If Sekunden_alt <> Sekunden Then Sekunden_alt = Sekunden Locate 1 , 1 Lcd Hex(stunden) ; ":" ; Hex(minuten) ; ":" ; Hex(sekunden) Locate 2 , 1 Lcd Hex(tag) ; "." ; Hex(monat) ; "." ; Hex(jahr) ; " " ; Wt(wochentag) ' Waitms 100 End If If _sec_alt <> _sec Then _sec_alt = _sec Locate 1 , 11 Lcd Time$ ; " " ; Dcf_status.7 '; " " ; Pind.6 End If ' Locate 4 , 11 ' Lcd Bin(dcf_status) Gosub Taste_get Locate 4 , 1 Lcd Bin(taste) If Taste = &B00011110 Then Incr Temp3 End If If Taste = &B00011101 Then Decr Temp3 End If Locate 3 , 1 Lcd Temp3 ; " " If Taste = &B0000_1111 Then Gosub Menue1 ' Waitms 100 If Taste < &B0001_1111 Then Gosub Taste_nokey Waitms 100 Loop End Menue1: Cls ' Temp1 = Memcopy(td(0) , Td_temp(0) , 7) '( Td(0) = &H00 Td(1) = &H32 Td(2) = &H17 Td(3) = &H31 Td(4) = &H06 Td(5) = &H10 Td(6) = &H14 ') Temp1 = _weekday + 1 Td(0) = Makebcd(_sec) Td(1) = Makebcd(_min) Td(2) = Makebcd(_hour) Td(3) = Makebcd(_day) Td(4) = Makebcd(temp1) Td(5) = Makebcd(_month) Td(6) = Makebcd(_year) I2cstart I2cwbyte &HAC I2cwbyte &B00001000 For Temp1 = 0 To 6 I2cwbyte Td(temp1) Next I2cstop Gosub Taste_nokey Return Lcd_command: Reset Portb.0 'Daten-Modus Temp1 = Cmd_byte And &HF0 'High-Nibble Shift Temp1 , Right , 4 Portc = Temp1 Set Portb.1 Waitus 20 Reset Portb.1 Temp1 = Cmd_byte And &H0F 'Low-Nibble Portc = Cmd_byte Set Portb.1 Waitus 20 Reset Portb.1 Waitms 5 Return 'Tasten abfragen Taste_nokey: Do Gosub Taste_get Loop Until Taste = &B0001_1111 Return Taste_wait: Do Gosub Taste_get Loop Until Taste < &B0001_1111 Gosub Taste_get Return Taste_get: Zaehler = 0 Temp2 = 0 While Zaehler < 20 Gosub Taste_check If Temp1 = Temp2 Then Incr Zaehler ' Temp2 = Temp1 Else Zaehler = 0 Temp2 = Temp1 End If Waitms 1 Wend Taste = Temp1 Temp2 = 0 Return Taste_check: I2cstart I2cwbyte &H41 I2crbyte Temp1 , Nack I2cstop Temp1 = Temp1 And &B0001_1111 Return Init_werte: Data &H33 , &H33 , &H32 Data &H2A , &H09 , &H06 , &H1E , &H29 , &H1B , &H6E , &H57 , &H78 , &H28 , &H0F , &H01 , &HFF