$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 $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 Dim B1 As Byte , Adres As Byte Config Pinb.5 = Output Config Pinb.4 = Output Declare Sub Write_eeprom(byval Adres As Byte , Byval Sekunde As Byte ) Declare Sub Read_eeprom(byval Adres As Byte , Value As Byte ) Portb.3 = 0 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 Write_eeprom(1 , 30) Call Read_eeprom(1 , Sekunde) Minute = 1 Stunde = 0 Timer1 = Timervorgabe Do Portb.4 = 1 If Sekunde = 0 And Minute = 0 And Stunde = 0 Then Goto Countdown_stop 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 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 '----------------------------------------Sub's--------------------------------------------- Sub Write_eeprom(byval Adres As Byte , Byval Sekunde As Byte ) I2cstart 'start condition I2cwbyte Addressw 'slave address I2cwbyte Adres 'asdress of EEPROM I2cwbyte Sekunde 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub 'sample of reading a byte from EEPROM AT2404 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