$regfile = "m8def.dat" $crystal = 3686400 Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2 Config Lcd = 16 * 2 Cls Cursor Off Noblink Config Sda = Portc.4 Config Scl = Portc.5 $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 Dim Sekunde As Byte , Minute As Byte , Stunde As Byte , Check As Byte , M As Byte , S As Byte Dim B1 As Byte , Adres As Byte Config Pinb.5 = Output Config Pinb.4 = Output Config Pinb.1 = Output Declare Sub Read_eeprom(byval Adres As Byte , Sekunde As Byte ) Declare Sub Read_eeprom3(byval Adres As Byte , Minute As Byte ) Declare Sub Read_eeprom5(byval Adres As Byte , Stunde As Byte ) Declare Sub Read_eeprom7(byval Adres As Byte , Check As Byte ) Declare Sub Read_eeprom8(byval Adres As Byte , M As Byte ) Declare Sub Read_eeprom9(byval Adres As Byte , M As Byte ) Declare Sub Write_eeprom8(byval Adres As Byte , Byval S As Byte ) Declare Sub Write_eeprom9(byval Adres As Byte , Byval S As Byte ) Portb.5 = 0 Portb.1 = 1 Config Timer1 = Timer , Prescale = 64 On Timer1 Timer_irq Enable Timer1 Const Timervorgabe = 7935 Enable Interrupts Config Clock = Soft Const Addressw = 160 'slave write address Const Addressr = 161 'slave read address Call Read_eeprom7(15 , Check) If Check <> 13 Then Goto Karte_fehlt Call Read_eeprom(1 , Sekunde) Call Read_eeprom3(5 , Minute) Call Read_eeprom5(10 , Stunde) Timer1 = Timervorgabe Do Portb.4 = 1 If Sekunde = 59 And Minute = 59 And Stunde = -1 Then Goto Countdown_stop If Sekunde = 59 Then Goto Abzug_m If Minute = 59 And Sekunde = 59 Then Goto Abzug_s Loop Timer_irq: Timer1 = Timervorgabe Sekunde = Sekunde - 1 If Sekunde = -1 Then Sekunde = 59 Minute = Minute - 1 If Minute = -1 Then Minute = 59 Stunde = Stunde - 1 End If End If Cls 'If Sekunde = 59 And Minute = 59 And Stunde = -1 Then Goto Countdown_stop 'If Sekunde = 59 Then Goto Abzug_m 'If Minute = 59 Then Goto Abzug_s Locate 1 , 3 Lcd "Zeitguthaben" Locate 2 , 5 Lcd Time(sekunde) Return '------------------------------------------------------------------------------ Countdown_stop: Stop Timer1 Portb.4 = 0 'Relais AUS Portb.5 = 1 'Alarmton AN (DERZEIT NICHT BENUTZT) Cls ' LCD: Endmeldung angeben Locate 1 , 1 Lcd "Guthaben leer" Locate 2 , 1 Lcd "Bitte aufladen" ' RESET drücken für Anfangszustand Stop End '------------------------------------------------------------------------------ Karte_fehlt: Stop Timer1 Portb.4 = 0 Portb.5 = 1 Cls Locate 1 , 1 Lcd "Karte fehlt" Locate 2 , 1 Lcd "Karte Einfuehren" Stop End '----------------------------------------Sub's--------------------------------- Abzug_m: Call Read_eeprom8(5 , M ) M = M - 1 Call Write_eeprom8(5 , M) '------------------------------------------------------------------------------ Abzug_s: Call Read_eeprom9(10 , S ) S = S - 1 Call Write_eeprom9(10 , S) '--------------------------------------Sekunde--------------------------------- Sub Read_eeprom(byval Adres As Byte , Sekunde As Byte ) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte Sekunde , Nack 'read byte I2cstop 'generate stop End Sub '-------------------------------Minute---------------------------------------------------- Sub Read_eeprom3(byval Adres As Byte , Minute As Byte ) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte Minute , Nack 'read byte I2cstop 'generate stop End Sub '---------------------------------Stunde--------------------------------------------- Sub Read_eeprom5(byval Adres As Byte , Stunde As Byte ) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte Stunde , Nack 'read byte I2cstop 'generate stop End Sub '---------------------------------Check--------------------------------------------- Sub Read_eeprom7(byval Adres As Byte , Check As Byte ) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte Check , Nack 'read byte I2cstop 'generate stop End Sub '---------------------------------Abzug_Minute---------------------------------------- Sub Read_eeprom8(byval Adres As Byte , M As Byte ) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte M , Nack 'read byte I2cstop 'generate stop End Sub Sub Write_eeprom8(byval Adres As Byte , Byval M As Byte ) I2cstart 'start condition I2cwbyte Addressw 'slave address I2cwbyte Adres 'asdress of EEPROM I2cwbyte M 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub '---------------------------------Abzug_Stunde---------------------------------------- Sub Read_eeprom9(byval Adres As Byte , S As Byte ) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte S , Nack 'read byte I2cstop 'generate stop End Sub Sub Write_eeprom9(byval Adres As Byte , Byval S As Byte ) I2cstart 'start condition I2cwbyte Addressw 'slave address I2cwbyte Adres 'asdress of EEPROM I2cwbyte S 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub