$regfile = "m8def.dat" $crystal = 4000000 $hwstack = 80 $swstack = 80 $framesize = 80 $baud = 9600 'Config Serialin = Buffered , Size = 20 Config Sda = Portc.4 Config Scl = Portc.5 Config Portc.0 = Output ' bell Config Portc.1 = Output 'SCHOOL DAY Config Portc.2 = Output 'WEEKEND Config Portd.2 = Output ' changes VBATT Declare Sub Init() ' SHOW INFO ON COMPORT VER , HELP , ECT , AT STARTUP Declare Sub Readee() ' READ SETTINGS OF BELL TIME FROM EEPROM Declare Sub Setupbell() ' SETUP NEW BELL TIME OR DATE-TIME Declare Sub Readds1307() ' READ DATE & TIME FROM DS1307 Declare Sub Belltime() ' CHECK FOR BELL RING TIMR Declare Sub Help() 'Help Declare Sub Listday() 'LIST BELL SETTINGS FOR A WEEKDAY Declare Sub Weekday() 'Check week day Declare Sub Vbatt_check() 'Check Vbatt voltage Dim Bb As Byte Dim _weekday As Byte Dim _day As Byte Dim _month As Byte Dim _year As Byte Dim _sec As Byte Dim _min As Byte Dim _hour As Byte Dim Ds1307w As Byte Dim Ds1307r As Byte Dim Buf As String * 14 Dim Aday As String * 2 Dim Amonth As String * 2 Dim Ayear As String * 2 Dim Asec As String * 2 Dim Amin As String * 2 Dim Ahour As String * 2 Dim What As String * 1 Dim Temp As String * 8 Dim Show As Byte , Dday As Byte , Buf1 As Byte , Vbat As Word Dim What1 As Byte , Hu As Byte , Mu As Byte , Erro As Byte Dim U As Byte , S As Byte , K As Byte , K1 As Byte , Ev As Byte Dim A As Byte , A1 As Byte , Sek As Byte , Wd As Byte , Abit As Byte Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc Buf = "" Erro = 0 Show = 1 Ds1307w = &B11010000 Ds1307r = &B11010001 ' Version info Const Vers = " Ver. 1.00 Alfa " Enable Interrupts 'lets see init on comport Call Init() ' set SQWE bit flash led I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 7 ' starting address in 1307 I2cwbyte &B00010000 ' Send Data to SECONDS I2cstop Waitms 1000 ' SHOW CURRENT SETTINGS ON COMPORT (EEPROM SETUP BELL TIMES) 'Call Readee() Call Help() Print Print " Mokyklos skambutis veikia " Print '******************************************************************************* Main: ' THE MAIN PROGRAM Do ' check for setup command S If Ischarwaiting() = 1 Then 'WE HAVE KEY PRESE Buf = Inkey() 'IF KEY PRESS WAS S THEN If Buf = "S" Then Call Setupbell() If Buf = "Z" Then Call Listday() Print Buf = "" Goto Main End If If Buf = "H" Then Call Help() If Buf = "+" Then Show = 1 Print Print " Laiko rodymas ijungtas " Print End If If Buf = "-" Then Show = 0 Print Print " Laiko rodymas isjungtas " Print End If Else 'NO KEY PRESS S READ THE DS1307 TIME Call Readds1307() End If Call Weekday() Call Vbatt_check() Loop End 'END OF MAIN PROGRAM '******************************************************************************* ' HERE IS ALL THE SUBS WE USE IN THIS PROGRAM CALL FROM MAIN OR OTHER SUBS ' READ BELL SETTINGS Sub Readee() Print "*** Skambucio nustatymai ***" Dday = 0 ' list all 18 bell setup For U = 9 To 169 Dday = Dday + 1 Print If Dday = 1 Then Print " Pirmadienis" If Dday = 2 Then Print " Antradienis" If Dday = 3 Then Print " Treciadienis" If Dday = 4 Then Print " Ketvirtadienis" If Dday = 5 Then Print " Penktadienis" Print "" 'Step 40 'U = 9 A = 64 For S = 1 To 18 Ev = S And 1 ' CHECK FOR EVEN ODD A = A + 1 U = U + 1 Readeeprom K , U U = U + 1 Readeeprom K1 , U 'TEST Print Chr(a) ; " = "; If K < 10 Then Print "0" ; Print K ; ":" ; If K1 < 10 Then Print "0" ; Print K1 ; If Ev = 1 Then Print " IN - " ; Else Print " OUT " End If Next S Print Print "********************************" Next U Print Return End Sub '**********************************************************************************************************************' 'IF KEYPRESS WAS S THEN WE DO THIS SETUP THE BELL TIMES & SETUP DS1307 DATE & TIME Sub Setupbell() ' SHOW CURRENT SWTTIMGS ON COMPORT Call Readee() 'show date and time Print "T = " ; ; Bcd(_day) ; "/" ; Bcd(_month) ; "/" ; Bcd(_year) ; " - " ; Bcd(_hour) ; ":" ; Bcd(_min) ; ":" ; Bcd(_sec) ' get new date&time (Txxxxxxx) or bell time (A - R) 'A SMALL HELP TEXT Print Print " Nuo A iki R yra laikrodzio skambejimo laikas" Print " T yra DATA-Laikas" Print " Pavizdys: A0800 + ENTER ** Skambes i pamoka 08:00" Print Print " Datos ir laiko formatas: ddmmyy-hhmmss" Print " Nustatymu meniu automatiskai issijungs po 40 sekundziu..." '*** WE NEED A TIMEOUT HERE IF NO KEYS ARE PRESS AFTER 40 SEC THEN EXIT SETUP '***** WORKING NOW **** $timeout = 10000000 ' this is NOT Sec or mSec but a counter/crystal ABOUT 40 SEC Input "Iveskite savaites dienos numeri nuo 1 iki 5 > " , Buf If Buf = "1" Then A = 8 Print "Pirmadienis" End If If Buf = "2" Then A = 45 Print "Antradienis" End If If Buf = "3" Then A = 82 Print "Treciadienis" End If If Buf = "4" Then A = 119 Print "Ketvirtadienis" End If If Buf = "5" Then A = 156 Print "Penktadienis" End If Input "Iveskite raide nuo A iki R ir XXXX laika > " , Buf Bb = Len(buf) 'store len of data send from comport '****** chek if buf have right len( DDMMYY-HHMMSS ) for date & time else skip this and return to normal What = Mid(buf , 1 , 1) 'get first char in data from com A - R or T What1 = Asc(what) Select Case What1 'select the command (A - R or T) then read the A A1 address for time 'A TO R 'A = 8 A1 = A + 1 Case 65 To 82: For Abit = 65 To 82 A = A + 2 A1 = A + 1 If What1 = Abit Then Exit For Next 'T Case 84 : 'T if date and time (T) is wrong If Len(buf) <> 14 Then 'setup date time Buf = "" Print " Blogi duomenys arba neivyko joks atnaujinimas" Print " ERROR BLOGAS DATOS FORMATAS" Goto Main Else 'if command T data format Tddmmyy-hhmmss is ok then do this Aday = Mid(buf , 2 , 2) : _day = Val(aday) Amonth = Mid(buf , 4 , 2) : _month = Val(amonth) Ayear = Mid(buf , 6 , 2) : _year = Val(ayear) Ahour = Mid(buf , 9 , 2) : _hour = Val(ahour) Amin = Mid(buf , 11 , 2) : _min = Val(amin) Asec = Mid(buf , 13 , 2) : _sec = Val(asec) 'return? _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year) _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' starting address in 1307 I2cwbyte _sec ' Send Data to SECONDS I2cwbyte _min ' MINUTES I2cwbyte _hour ' Hours I2cstop I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 4 ' starting address in 1307 I2cwbyte _day ' Send Data to SECONDS I2cwbyte _month ' MINUTES I2cwbyte _year ' Hours I2cstop 'Show the new date & time on comport Print "NAUJA DATA = " ; Bcd(_day) ; "/" ; Bcd(_month) ; "/" ; Bcd(_year) Print "NAUJAS LAIKAS = " ; Bcd(_hour) ; ":" ; Bcd(_min) ; ":" ; Bcd(_sec) End If ' if comport dataformat is NOT A - R or T then : 'U Case Else : Print " BLOGAS DATOS FORMATAS" Erro = 1 End Select ' check for bad format if bad then skip this If Erro = 0 And Bb > 4 Then Temp = Mid(buf , 2 , 2) K = Val(temp) Temp = Mid(buf , 4 , 2) K1 = Val(temp) Writeeeprom K , A Writeeeprom K1 , A1 Print What ; " = "; If K < 10 Then Print "0" ; Print K ; ":" ; If K1 < 10 Then Print "0" ; Print K1 End If Erro = 0 'reset erro bit Buf = "" End Sub '****************************************************************************************************************** 'READ DS1307 TIME & DATE Sub Readds1307() ' if no S is press then read the time from ds1307 and show it on comport I2cstart I2cwbyte Ds1307w I2cwbyte 0 I2cstart I2cwbyte Ds1307r I2crbyte _sec , Ack I2crbyte _min , Ack I2crbyte _hour , Ack I2crbyte _weekday , Ack I2crbyte _day , Ack I2crbyte _month , Ack I2crbyte _year , Nack I2cstop If Show = 1 Then Print Bcd(_day) ; "/" ; Bcd(_month) ; "/" ; Bcd(_year) ; " - " ; Bcd(_hour) ; ":" ; Bcd(_min) ; ":" ; Bcd(_sec) End If Wd = Makedec(_weekday) Waitms 1000 End Sub '***************************************************************************************************************** 'HERE WE CHECK FOR BELL RING Sub Belltime() ' Set Portd.2 Hu = Makedec(_hour) Mu = Makedec(_min) Sek = Makedec(_sec) Wd = Makedec(_weekday) ' THE WEEKDAY 2,3,4,5,6 MON TO FRI - NOT SCHOOLDAYS 1 = SUN 7 = SAT ' if it is a shoolday then If Wd < 7 And Wd > 1 Then If Wd = 2 Then U = 9 If Wd = 3 Then U = 46 If Wd = 4 Then U = 83 If Wd = 5 Then U = 120 If Wd = 6 Then U = 157 For S = 1 To 18 Ev = S And 1 U = U + 1 Readeeprom K , U U = U + 1 Readeeprom K1 , U If K = Hu And K1 = Mu And Ev = 1 And Sek < 5 Then 'if time is same then check for IN/OUT ring bell IF IN then (RING 2 TIMES) Print " Skambutis i pamoka ijungtas" Set Portc.0 Set Portd.4 Wait 8 Print " Skambutis i pamoka isjungtas" Print "Pakartotinai skambes po 53 sec. Palaukite..." Reset Portc.0 Reset Portd.4 Wait 47 Print " Skambutis i pamoka ijungtas" Set Portc.0 Set Portd.4 Wait 5 Print " Skambutis i pamoka isjungtas" Reset Portc.0 Reset Portd.4 Elseif K = Hu And K1 = Mu And Ev = 0 And Sek < 5 Then ' if OUT then use this 1 RING only Print " Skambutis is pamokos ijungtas" Set Portc.0 Set Portd.4 Wait 8 Print " Skambutis is pamokos isjungtas" Reset Portc.0 Reset Portd.4 End If Next ' check next time in eerpom (1 to 18) End If ' Reset Portd.2 End Sub '************************************************************************************************************** Sub Init() Print " *************************************" Print " * Automatinis mokyklos skambutis *" Print " * " ; Vers ; " *" Print " * " ; Version() ; " *" ' Version() is timestamp of last complied sourcecode Print " * Sukure Matas & Kim *" 'Print " * now 5 day bell setup *" Print " *************************************" Print End Sub '*************************************************************************************************************** Sub Help() Print Print " Pagalbinis meniu:" Print Print " - Isjungti laiko rodyma" Print " + Ijungti laiko rodyma" Print " H Rodyti pagalbini meniu" Print " Z Rodyti skambucio nustatymus" Print " S Ijungti skambucio nustatymo meniu" Print End Sub '******************************************************* Sub Listday() $timeout = 10000000 Input "Savaites dienos numeris nuo 1 iki 5 >" , Buf1 If Buf1 > 0 Then Print If Buf1 = 1 Then Print " Pirmadienis" U = 9 End If If Buf1 = 2 Then Print " Antradienis" U = 46 End If If Buf1 = 3 Then Print " Treciadienis" U = 83 End If If Buf1 = 4 Then Print " Ketvirtadienis" U = 120 End If If Buf1 = 5 Then Print " Penktadienis" U = 157 End If Print "" 'Step 40 'U = 9 A = 64 For S = 1 To 18 Ev = S And 1 ' CHECK FOR EVEN ODD A = A + 1 U = U + 1 Readeeprom K , U U = U + 1 Readeeprom K1 , U 'TEST Print Chr(a) ; " = "; If K < 10 Then Print "0" ; Print K ; ":" ; If K1 < 10 Then Print "0" ; Print K1 ; If Ev = 1 Then Print " IN - " ; Else Print " OUT " End If Next S Print Print "********************************" Print Else Print " Laikas baigesi" End If End Sub '******************************************************************************* Sub Weekday() 'CHECK BELL RING TIME IF ITīS A SCHOOLDAY ELSE WE DONT READ BELL TIMES If Wd < 7 And Wd > 1 Then Call Belltime() If Wd < 7 And Wd > 1 Then Reset Portc.2 Set Portc.1 Else 'if not a schoolday then SETUP LEDS TO WEEKEND Reset Portc.1 Set Portc.2 End If End Sub '******************************************************************************* Sub Vbatt_check() Vbat = Getadc(3) If Vbat < 610 Then '2.98 volt Portd.2 = 1 Print "Pakeisti laikrodzio baterija" 'Print Vbat Else Portd.2 = 0 End If 'WAIT 1 SEC THEN LOOP End Sub '*******************************************************************************