20*4 OLED Alarm Clock

Bill.b

Senior Member
28x2 Clock and temperature on the AXE 134y 20 * 4 OLED serial display

OLEDClock.jpg

Displays - Main Display
Line 1 - Time 12 or 24 hour format time with seconds
Line 2 - Date - Day, Date, Month
Line 3 - Current Temperature DS18B20
Line 4 - Alarm Status (OFF or Alarm time and Day)

All settings are by IR remote control (Philips programable controller)
If a different controller is used the codes numbers in the program may require changing.

Menu button - select settings menu.
buttons 1 to 4 - select menu items
UP / Down arrows - cycle through settings
OK button - select and save settings.

Menu - Settings

Line 1: MENU
Line 2: 1 - Set Clock
Line 3: 2 - Set Date
Line 4: 3 - Set Alarm

Set Clock Menu

Line 1: Time Menu
Line 2: 1 - Hour
Line 3: 2 - Minutes


Set Date Menu

Line 1: Date Menu
Line 2: 1 - Day 2 - Month
Line 3: 3 - Date 4 - Year

Set Alarm Menu

Line 1 : Alarm Menu
Line 2: 1 - Hour
Line 3: 2 - Minutes
Line 4: 3 - Day

Left / Right arrows - switch from 12 hour to 24 hour format.
Pause and Stop Button - select alarm ON/OFF

Alarm settings are held in an external EEPROM

Clockcircuit2.jpg

Bill
 

1968neil

Senior Member
Hi Bill,
Have just built this clock and have found an error in the code.

The date always seems to display as the "th" rather than the "rd" etc so the 22nd day will display as 22th any ideas i've studied your code and must be missing something, great project by the way all works beautifully otherwise :)
Regards
Neil
 

marks

Senior Member
Try changing this bit of code
and i'll 2nd that lol ,Great project!
Code:
displaydate:

	bcdtoascii date,AsciiData2,AsciiData1	'Convert Time and Date To ASCII
	serout OLED,Baud,(254,192)
		'set to display curser to line 2
	DispDay = day
	gosub DisplayDay

	if AsciiData2 = 48 then				'display date and remove leading 0
		serout OLED,Baud,(AsciiData1)
	Else
		serout OLED,Baud,(AsciiData2,AsciiData1)
	endif
'---------------------------------------------------------------------------------------	
'	if date < 4 OR date > 48 then					'add suffex to date
'		if date = 1 or date = 49 then
'	
'			serout OLED,Baud,("st ")
'		endif
'		if date = 2 then
'			serout OLED,Baud,("nd ")
'		endif
'		if date = 3 then
'			serout OLED,Baud,("rd ")
'		endif
'	else
'		serout OLED,Baud,("th ")
'	endif
'--------------------------------------------------------------------------------------

		                                    'add suffex to date
		if date = $1 or date = $21 or date = $31 then 
			serout OLED,Baud,("st ")
		elseif date = $2 or date = $22 then
			serout OLED,Baud,("nd ")
		elseif date = $3 or date = $23 then
			serout OLED,Baud,("rd ")
	      else
		      serout OLED,Baud,("th ")
	      endif
 

hippy

Technical Support
Staff member
My preferred code is ...
Code:
Select Case date
  Case $01, $21, $31 : serout OLED,Baud,("st ")
  Case $02, $22      : serout OLED,Baud,("nd ")
  Case $03, $23      : serout OLED,Baud,("rd ")
  Else               : serout OLED,Baud,("th ")
End Select
 

1968neil

Senior Member
Thanks guys,
will try it tonight, and will post some images of my finished clock. Ive built it into a plexi glass case so all the inards are viewable.

Regards
Neil
 

1968neil

Senior Member
Magic, did the trick :)
One more thing as a note for anyone else attempting this as a project.
Change the baud rate to 1200 if using the AXE133 LCD as i have or the display will look like random obviously because the 28x2 clock speed is doubled from 8 mhz to 16 mhz.
Thanks again all
Regards
Neil
 

Bill.b

Senior Member
Hi Neil

Good to see it working OK.

To display the Deg symbol on the temperatue display, change the value in the routine display temperatrue from 210 to 178 (Hex B2).
The OLED display character set must be different to the LCD set.

Bill
 
Last edited:

1968neil

Senior Member
Hi Neil

Good to see it working OK.

To display the Deg symbol on the temperatue display, change the value in the routine display temperatrue from 210 to 178 (Hex B2).
The OLED display character set must be different to the LCD set.

Bill
I'll do that, Great project Bill enjoyed building it, one thing i would like to do is drop a couple of degrees of the temperature as mine seems to be 2 deg high due to the perspex lid (internal temp) otherwise brilliant :)

Regards
Neil
 

the old fart

Senior Member
I am using a 'SKY' handset with this project.

Set handset code to 1679.

TV button
hold 'select' and 'red button'
led flash twice
1 6 7 9
led flash twice


select TV and point at IR receiver.



gives these values
Code:
Symbol KEY_ALMON    = 76		'IR Alarm ON Buttom 
Symbol KEY_1            = 0		'IR Key 1
Symbol KEY_2            = 1		'IR key 2
Symbol KEY_3            = 2		'IR key 3
Symbol KEY_4            = 3		'IR key 4
Symbol KEY_5            = 4		'IR key 5
Symbol KEY_6            = 5		'IR key 6
Symbol KEY_7            = 6		'IR key 7
Symbol KEY_8            = 7		'IR key 8
Symbol KEY_9            = 8		'IR key 9
Symbol KEY_0            = 9		'IR key 0
Symbol KEY_UP          = 18		'IR Up Arrow
Symbol KEY_DOWN    = 19		'IR Down Arrow
Symbol KEY_LEFT       = 16		'IR Left Arrow   -  24 hour format
Symbol KEY_RIGHT    = 17		'IR Right Arrow  -  12 hour format
Symbol KEY_MENU     = 63		'IR Menu Button  -  Time, Date and Alarm Menus
Symbol KEY_OK       	= 37		'IR OK Button    -  Accept and save settings	
symbol KEY_ALMOFF  = 77		'IR Alarm OFF Button
 

the old fart

Senior Member
Thanks to Neil for initial program.



My 'Final' setup, I hope.

20X2 chip
I2C RTC DS1307 AT24C32 Real Time Clock Module + temperature
Inside and outside temerature.



Code:
' picaxe 20x2 clock calender
' 
#picaxe 20X2
#No_Data
setfreq m16
symbol Piezo		= b.0		'Alarm buzzer Output
symbol tempsensor1 	= pinb.1	'indoor Temperature sensor analogue input
symbol tempsensor2 	= pinb.2	'outdoor Temperature sensor analogue input
symbol irselect 		= pinb.4	'IR Input
symbol OLED			= b.6		'Serial output to display

symbol infracnt 		= b3		'IR variable
symbol Counter   		= B4
symbol seconds 		= b7		'DS1307 seconds
symbol mins 		= b8		'DS1307 minutes
symbol hour 		= b9		'DS1307 Hour
symbol day 			= b10		'DS1307 day
symbol date 		= b11		'DS1307 Date
symbol month 		= b12		'DS1307 Month
symbol year 		= b13		'DS1307 Year
symbol control 		= b14		'DS1307 Control
symbol AsciiData1 	= b17		'Ascii data for display on LCD
symbol AsciiData2 	= b16		'Ascii data for display on LCD
symbol AsciiData3 	= b20		'Ascii data for display on LCD
symbol AsciiData4 	= b19		'Ascii data for display on LCD
symbol AsciiData5 	= b23		'Ascii data for display on LCD
symbol AsciiData6 	= b22		'Ascii data for display on LCD
symbol TempMinutes 	= b6		'Tempory store - minutes
symbol TempHour 		= b24		'Tempory store - Hours
symbol TempDay 		= b25		'Tempory store - Day
symbol TempMonth 		= b26		'Tempory store - Month
symbol tempyear		= b27		'Tempory store - Year
symbol tempdate		= b28		'Tempory store - Date
symbol Selected		= b29		;Menu selected
symbol DispDay		= b30		'Display Day Temp 
symbol loopcount		= b33		'For - next loop counter
symbol format12h		= b34		'12 hour variable set
symbol alarmset         = b35       ;alarm set
symbol temperature	= w18		'temperature variable
symbol temperature2  	= w19		'temporary store - temperaturesymbol alarmmin
symbol readT		= w20		;temperature read
symbol alarmmin		= b42		;alarm minute variable
symbol alarmhr		= b43		'alarm hour variable
symbol bBcdmin		= b44		'BCD convert variable - minute
symbol bBcdhr		= b45		'BCD convert variable - hour
symbol bBcdDay		= b46		'BCD convert variable - Day
symbol alarmDay		= b47		'Alarm Day variable
symbol sign             = b50		;sign + or -
symbol aux			= b51		;waste byte

symbol Baud			= N1200	'Set serial output baud rate was N2400 @8mhz


'*****************************************************************************
'* Key codes for the SKY remote controller.                 * 
'* If a different remote is used, the key codes may be different.            * 
'* Test the codes and update the code numbers below to suit your controller. *
'*****************************************************************************

Symbol KEY_ALMON        = 76		'IR Alarm ON Buttom 
Symbol KEY_1            = 0		'IR Key 1
Symbol KEY_2            = 1		'IR key 2
Symbol KEY_3            = 2		'IR key 3
Symbol KEY_4            = 3		'IR key 4
Symbol KEY_5            = 4		'IR key 5
Symbol KEY_6            = 5		'IR key 6
Symbol KEY_7            = 6		'IR key 7
Symbol KEY_8            = 7		'IR key 8
Symbol KEY_9            = 8		'IR key 9
Symbol KEY_0            = 9		'IR key 0
Symbol KEY_UP           = 18		'IR Up Arrow
Symbol KEY_DOWN         = 19		'IR Down Arrow
Symbol KEY_LEFT         = 16		'IR Left Arrow   -  24 hour format
Symbol KEY_RIGHT        = 17		'IR Right Arrow  -  12 hour format
Symbol KEY_MENU         = 63		'IR Menu Button  -  Time, Date and Alarm Menus
Symbol KEY_OK       	= 37		'IR OK Button    -  Accept and save settings	
symbol KEY_ALMOFF		= 77		'IR Alarm OFF Button

init:

	serout OLED,Baud,(254,1)
	pause 12000			'Clear Display wait for display startup		
	let alarmset = 0
	counter=0
 

the old fart

Senior Member
program pt2, (can't post in one go)


Code:
'*****************************	
'*main program starts hear   *
'*****************************

start:

main:

	irin [300],b.4,infracnt		' get input from IR receiver if menu selected then goto menu
	
	if infracnt = KEY_MENU then 	
		tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 30
		gosub MENU
	
	endif
	
	
	if infracnt = Key_ALMON then		'turn alarm ON
	tune Piezo, 5,($40)
	let alarmset = 1

	endif	
	
	
	if infracnt = Key_ALMOFF then		'turn alarm OFF
	tune Piezo, 5,($40)
	let alarmset = 0
	let counter=0
	endif	
	
	
	if infracnt = Key_left then		'Select 24 hour format ON
	tune Piezo, 5,($40)
	let format12h = 1
	endif 
	if infracnt = Key_Right then		'Select 12 hour format ON
	tune Piezo, 5,($40)
	let format12h = 0
	endif 
	 serout OLED,Baud,(254,128)		'set display curser to line 1
	infracnt = 200
	if format12h = 1 then
		gosub TimeDate24		'display time in 24 h format
	else
		gosub TimeDate12		'display time in 12 h format
	endif
	  if alarmset = 1 then 
	 	gosub alarm  		'set alarm On of Off
	 else
	   	;serout OLED,Baud,(254,212)	'set display curser to line 4
		;serout OLED,Baud,("  Alarm  -  OFF    ")
	endif
	 if counter=0 then gosub displaydate 'update Date every 256 cycles
				
	 if counter=1 or counter=128 then gosub Displaytemp			
				
inc counter
	goto main
'************************************************************************
'*   Display time in 12 hour format                                     *
'* This operation was selected because it was easier to switch between  *
'* 12 and 24 hour formats.                                              *
'************************************************************************

TimeDate12:

	;
	gosub readtime			'get current time form DS1307
	serout OLED,Baud,(254,128)    'calculate 12 hour display from 24h data
	Temphour = hour
	if hour >9 then let Temphour = hour - 6:endif
	if hour >18 then let Temphour = hour - 18:endif
	if hour >25 then let Temphour = hour - 24:endif
	if hour =0 then let Temphour = 12:endif
	
	bintoascii Temphour,b31,AsciiData2,AsciiData1	'Convert Time  To ASCII for display
	bcdtoascii mins,AsciiData4,AsciiData3
	bcdtoascii seconds,AsciiData6,AsciiData5
	if AsciiData2 = 48 then					'remove leading 0
		serout OLED,Baud,("     ",AsciiData1,":",AsciiData4,AsciiData3,":",AsciiData6,AsciiData5)
	else
		serout OLED,Baud,("    ",AsciiData2,AsciiData1,":",AsciiData4,AsciiData3,":",AsciiData6,AsciiData5)
		endif
				'display am or pm 
	if hour > 17 then
		serout OLED,Baud,(" pm    ")
	else
		serout OLED,Baud,(" am    ")
	endif
	
	if mins = 21 and seconds < 2 then
		gosub chime15
	endif
		if mins = 48 and seconds < 2  then
		gosub chime30
	endif
		if mins = 69 and seconds < 2  then
		gosub chime45
	endif
		if mins = 0 and seconds < 5  then
		gosub chimehour
	endif
	
	serout OLED,Baud,(254,192)
	return
	
	
'**************************************
'*   Display time in 24 hour format   *
'**************************************

	
TimeDate24:

	;
	gosub readtime					'get current time form DS1307
	serout OLED,Baud,(254,128)
	serout OLED,Baud,("      ")
	bcdtoascii hour,AsciiData2,AsciiData1	'Convert Time  To ASCII
	bcdtoascii mins,AsciiData4,AsciiData3
	bcdtoascii seconds,AsciiData6,AsciiData5
	serout OLED,Baud,(AsciiData2,AsciiData1,":",AsciiData4,AsciiData3,":",AsciiData6,AsciiData5,"    ")
	return
	
'****************************
'*   Display current Date   *
'****************************
	

displaydate:

	bcdtoascii date,AsciiData2,AsciiData1	'Convert Time and Date To ASCII
	serout OLED,Baud,(254,192)
		'set to display curser to line 2
	DispDay = day
	gosub DisplayDay
	
	
	

	if AsciiData2 = 48 then				'display date and remove leading 0
		serout OLED,Baud,(" ",AsciiData1)
	Else
		serout OLED,Baud,(AsciiData2,AsciiData1)
	endif
	Select Case date
  		Case $01, $21, $31 : serout OLED,Baud,("st ")
 		 Case $02, $22      : serout OLED,Baud,("nd ")
  		Case $03, $23      : serout OLED,Baud,("rd ")
 	 Else               : serout OLED,Baud,("th ")
	End Select





	select case month					'Display Month
		case 1
			serout OLED,Baud,("Jan. ")
		case 2
			serout OLED,Baud,("Feb. ")
		case 3
			serout OLED,Baud,("March")
		case 4
			serout OLED,Baud,("April")
		case 5
			serout OLED,Baud,("May  ")
		case 6
			serout OLED,Baud,("June ")
		case 7
			serout OLED,Baud,("July ")
		case 8
			serout OLED,Baud,("Aug. ")
		case 9
			serout OLED,Baud,("Sept.")
		case 16
'untitled

			serout OLED,Baud,("Oct. ")
		case 17
			serout OLED,Baud,("Nov. ")
		case 18
			serout OLED,Baud,("Dec. ")
	endselect

	return


'************************************************************
'*   Read Temperature in 12 bit mode and convert to deg C   *
'************************************************************

	
Displaytemp:

      readtemp12 b.1,ReadT				'Read Temperature sensor DS18B20
      if ReadT>32767 then let sign="-":else:let sign=" ":endif
  	temperature = ReadT * 10
  	temperature = temperature/16			'format temp data for deg C 
	serout OLED,Baud,(254,148)			'set to display curser to line 3
	bintoascii temperature,AsciiData5,AsciiData4,AsciiData3,AsciiData2,AsciiData1
	serout OLED,Baud,(" Inside Temp.",sign,AsciiData3,AsciiData2,".",AsciiData1,210,"C ")

if alarmset=1 then return:endif
	readtemp12 b.2,ReadT
	
	
	if ReadT>32767 then let sign="-":else:let sign=" ":endif
      temperature = ReadT * 10
  	temperature = temperature/16			'format temp data for deg C 
	serout OLED,Baud,(254,212)			'set to display curser to line 3
	bintoascii temperature,AsciiData5,AsciiData4,AsciiData3,AsciiData2,AsciiData1
	serout OLED,Baud,("Outside Temp.",sign,AsciiData3,AsciiData2,".",AsciiData1,210,"C ")

	return
	
'**************************************
'*   Read time from DS1307            *
'**************************************
	
readTime:

	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte   	' set DS1307 slave address
	hi2cin 0,(seconds,mins,hour,day,date,month,year)  	'Read date and Time

	return
	
' .---------------------------------------------.
' |     Compare alarm setting with actual time  |
' |     if alarm in set ON, sound alarm         |
' `---------------------------------------------' 	 	
alarm:
i2cslave %10100000, i2cfast, i2cWORD
	
	  'get alarm settings from EEPROM
	pause 10
	hi2cin 0,(alarmmin,alarmhr,alarmDay)
		
	bBcdmin = alarmmin / 10 * 16				'convert ON time setting to BCD format
       bBcdmin = alarmmin // 10 | bBcdmin
       bBcdhr = alarmhr / 10 * 16
       bBcdhr = alarmhr // 10 | bBcdhr
       bBcdDay = alarmDay / 10 * 16
       bBcdDay = alarmDay // 10 | bBcdDay
	if hour <> bBcdhr then goto Notset			'compare current Time and Day settings to value
	if mins <> bBcdmin then goto Notset			'stored in EEPROM
	if alarmDay = 8  and Day >1 and Day < 7 then alarmON
	if alarmday = 9 then alarmON
	if alarmday = 10 and Day = 1 or Day = 7 then alarmON
	if Day <> bBcdDay then goto Notset
	
alarmON:								'If Alarm setpoint = current time then sound alarm
	
	if Seconds= $00 or Seconds < $3 then
							'Play alarm song 3 times unless cancelled
		;irin [100],b.4,infracnt
		;if  infracnt >0 and infracnt <200 then exit
			tune Piezo, 5,($40,$05,$49,$05,$40,$2B,$C7,$45,$04,$47,$04,$64,$29,$C5,$40,$05,$49,$05,$40,$2B,$C7,$45,$04)
			;if  infracnt >0 and infracnt <200 then exit
			;tune Piezo, 5,($40,$02,$44,$85,$40,$42,$44,$45,$AC,$42,$44,$46,$47,$AC,$42,$44,$46,$47,$2C,$42,$44,$46,$47,$2C,$00,$44,$85)
			;if  infracnt >0 and infracnt <200 then exit	
		
	endif
Notset:		'Display alarm settings on row 8 of display only when alarm is set to ON

	bintoascii alarmhr,AsciiData3,AsciiData2,AsciiData1	'Convert Time and Date To ASCII
	bintoascii alarmmin,AsciiData6,AsciiData5,AsciiData4
	serout OLED,Baud,(254,212)
	serout OLED,Baud,("Alm ")
	serout OLED,Baud,(AsciiData2,AsciiData1,":",AsciiData5,AsciiData4," ")
	DispDay = alarmday
	gosub displayDay

	return
	
'**************************************************************
'*  The following menu is for setting Time, Date and Alarms.  *
'**************************************************************
	
menu:
 	
 	
 	
 	
	irin [100],b.4,infracnt			'get selection from IR input
  	serout OLED,Baud,(254,128)		'set to display curser to line 1
	serout OLED,Baud,("     MENU ") 	' Display Menu 1
	serout OLED,Baud,(254,192)
	serout OLED,Baud,("1 - Set Clock ")
	serout OLED,Baud,(254,148)
	serout OLED,Baud,("2 - Set Date  ")
	serout OLED,Baud,(254,212)
	serout OLED,Baud,("3 - Set Alarm ")
	pause 20
	if infracnt = KEY_1 then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 Selected = 1
		 infracnt = 200
		 gosub SetTime
	 endif
	 
	if infracnt = KEY_2 then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 Selected = 2
		 infracnt = 200
		gosub SetnewDate
	endif
	
	if infracnt = KEY_3 then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 Selected = 3
		 infracnt = 200
		gosub SetTime
	endif
	
	if infracnt = KEY_OK then
	tune Piezo, 5,($40)		'Return to normal clock
		serout OLED,Baud,(254,1)
		counter = 0
		infracnt =200
		Return
	endif
	
	infracnt =200
	goto menu
	
	
updatetime:		'Write new Time to DS1307

	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte 
	mins = TempMinutes / 10 * 16					'convert menutes to BCD format
  	mins = TempMinutes // 10 | mins
  	seconds = $00
  	hour = TempHour / 10 * 16					'convert Hours to BCD format
  	hour = TempHour // 10 | hour
  	hi2cout 0,(seconds,mins,hour,255)				'write to DS1307
  	pause 20
  	return
    	
updateAlarm:

	i2cslave %10100000, i2cfast, i2cWORD			'Set I2C for EEPROM
	hi2cout 0,(tempminutes,temphour,tempday)		'Write Alarm settings to EEPROM
  	pause 20
  	return
  	
SetnewDate:							'Menu 2 - Set new Date Data
	 
	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
	hi2cin 3,(tempday,tempdate,tempmonth,tempyear)	
	for aux=10 to 30 step 10
	if tempdate>aux then let tempdate=tempdate-6:endif
	next aux
	
	if tempmonth>10 then let tempmonth=tempmonth-6:endif
		
	if tempyear>10 then let tempyear=tempyear-6:endif
 

the old fart

Senior Member
part 3
Code:
setnewdatex:


	serout OLED,Baud,(254,212,"D ",#tempday,",M ",#tempmonth,",D ",#tempdate,",Y 20",#tempyear)

	irin [100],b.4,infracnt
	serout OLED,Baud,(254,128)
	serout OLED,Baud,("      DATE MENU     ")
	serout OLED,Baud,(254,192)
	serout OLED,Baud,("1 - Day    2 - Month")
	serout OLED,Baud,(254,148)
	serout OLED,Baud,("3 - Date   4 - Year  ")
	pause 20
	 serout OLED,Baud,(254,128)
	if infracnt = KEY_1 then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 b29=6
		gosub setDay
	 endif
	 
	if infracnt = KEY_2 then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		gosub SetMonth
	endif
	
		if infracnt = KEY_3 then
		tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		gosub SetDate2
		endif
		
	if infracnt = KEY_4 then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		gosub SetYear
	endif
	
	if infracnt = KEY_OK then
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		gosub updateDate
		pause 100
		counter = 0
		Return
	endif
	
	infracnt =200
	goto SetnewDatex
		
SetMonth:




	serout OLED,Baud,(254,128)
	serout OLED,Baud,(" MONTH   ",179,180)
	irin [100],b.4,infracnt
	if infracnt = KEY_UP then
	tune Piezo, 5,($40)
		TempMonth = TempMonth + 1
	endif
	
 	if infracnt = KEY_DOWN then
 	tune Piezo, 5,($40)
		TempMonth = TempMonth -1
	 endif
	 
	 	if TempMonth > 12 then
		TempMonth = 1
	endif
	
	if TempMonth <1 then 
		TempMonth = 12
	endif	
	
	serout OLED,Baud,(254,192)
	select case TempMonth
		case 1
			serout OLED,Baud,(" January   ")
		case 2
			serout OLED,Baud,(" February  ")
		case 3
			serout OLED,Baud,(" March     ")
		case 4
			serout OLED,Baud,(" April     ")
		case 5
			serout OLED,Baud,(" May       ")
		case 6
			serout OLED,Baud,(" June      ")
		case 7
			serout OLED,Baud,(" July      ")
		case 8
			serout OLED,Baud,(" August    ")
		case 9
			serout OLED,Baud,(" September ")
		case 10
			serout OLED,Baud,(" October   ")
		case 11
			serout OLED,Baud,(" November  ")
		case 12
			serout OLED,Baud,(" December  ")
	endselect
	if infracnt = KEY_OK then
	tune Piezo, 5,($40)
	 	infracnt = 200
		 serout OLED,Baud,(254,1)
	 	pause 1000
		 return
	 endif
	 infracnt = 200
	 goto setMonth
setDate2:

	serout OLED,Baud,(254,128)
	serout OLED,Baud,("SET DATE ",179,180)
	irin [100],b.4,infracnt
	if infracnt = KEY_UP then
	tune Piezo, 5,($40)
		TempDate = TempDate + 1
	 endif
	 if infracnt = KEY_DOWN then
	 tune Piezo, 5,($40)
		TempDate = TempDate -1
	 endif
 	 if TempDate > 31 then
		TempDate = 1
	endif
	if TempDate <1 then 
		TempDate = 31
	endif
	 BINtoascii TempDate,AsciiData3,AsciiData2,AsciiData1
	 serout OLED,Baud,(254,192)
	 serout OLED,Baud,("Date -  ",AsciiData2,AsciiData1)
	 if infracnt = KEY_OK then
	 tune Piezo, 5,($40)
		 infracnt = 200
		 serout OLED,Baud,(254,1)
		 pause 1000
		  return
	 endif
	 infracnt = 200
	 goto setDate2
	 
SetYear:
	 
	irin [100],b.4,infracnt
	serout OLED,Baud,(254,128)
	serout OLED,Baud,(" SET YEAR ",179,180)
	if infracnt = KEY_UP then
	tune Piezo, 5,($40)
		TempYear = TempYear +1
	endif
	if infracnt = KEY_DOWN then
	tune Piezo, 5,($40)
		TempYear = TempYear -1
	 endif
	 if TempYear > 20 then
		TempYear = 20
	endif
	if TempYear <1 then 
		TempYear = 1
	endif
	 BINtoascii TempYear,AsciiData3,AsciiData2,AsciiData1
	 serout OLED,Baud,(254,192)
	 serout OLED,Baud,("year -  20",AsciiData2,AsciiData1)
	 if infracnt = KEY_OK then
		 infracnt = 200
		 serout OLED,Baud,(254,1)
		 pause 1000
		 return
	 endif
	 infracnt = 200
	 goto setYear
		 
UpdateDate:					'Write new Date data to DS1307 

	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte 	'Set I2C address for DS1307
	month = TempMonth / 10 * 16				'convert OFF time setting to BCD format
     	month = TempMonth // 10 | month
     	date = tempdate / 10 * 16				'convert OFF time setting to BCD format
     	date = tempdate // 10 | date
	day = TempDay / 10 * 16					'convert OFF time setting to BCD format
	day = TempDay // 10 | day
	year = tempyear / 10 * 16				'convert OFF time setting to BCD format
	year = tempyear // 10 | year
	let control = %00010000 				' Enable output at 1Hz
	hi2cout 3,(day,date,month,year,control,255)	'Write new data to DS1307
	pause 20
  	return
   	 
' .------------------------------------------.
' |     Update Clock, Date and Menu          |
' `------------------------------------------'  
 
SetTime:			'Menu 3  Set Alarm Time or Clock Time depending on the value of B29


hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
	
	hi2cin 1,(tempminutes,temphour)
	if temphour>10 then let temphour=temphour-6:endif
	
	for aux= 10 to 50 step 10
	if tempminutes>aux then let tempminutes=tempminutes-6:endif
	next aux





settimex:	
	irin [100],b.4,infracnt
	
	serout OLED,Baud,(254,128)
	if Selected = 3 then
	
	
		 serout OLED,Baud,("ALARM MENU ")
		 serout OLED,Baud,(254,212)
		 serout OLED,Baud,("3 - Set Day ")
	else
		serout OLED,Baud,(254,128)
		serout OLED,Baud,(" TIME MENU ")
	 endif
	serout OLED,Baud,(254,192)
	serout OLED,Baud,("1 - Set Hour ")
	serout OLED,Baud,(254,148)
	serout OLED,Baud,("2 - Set Minute  ")
		select case infracnt
		
	Case KEY_1 
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 gosub sethour
	 
	case KEY_2 
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 gosub Setmin
	
	Case KEY_3
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		 pause 300
		 gosub SetDay
	
	Case KEY_OK 
	tune Piezo, 5,($40)
		serout OLED,Baud,(254,1)
		if Selected = 1 then
			gosub updatetime		'Update DS1307
		endif
		if Selected = 3 then
			gosub updateAlarm		'Update EEPROM
		endif
		pause 100
		counter = 0
		Return
	endselect
	infracnt =200
	goto SetTimex
	
sethour:


	irin [100],b.4,infracnt
	
	gosub TimeDate24
	serout OLED,Baud,(254,192,179,180)
	if infracnt = KEY_UP then
	tune Piezo, 5,($40)
		TempHour = TempHour + 1
	 endif
	 if infracnt = KEY_DOWN then
	 tune Piezo, 5,($40)
		TempHour = TempHour -1
	 endif
	 	 if TempHour > 23 then
		TempHour = 0
	endif
	if TempHour =0 and infracnt =KEY_DOWN then let TempHour = 23:endif
	BINtoascii TempHour,AsciiData3,AsciiData2,AsciiData1
	serout OLED,Baud,(254,195)
	serout OLED,Baud,("hour -  ",AsciiData2,AsciiData1)
	if infracnt = KEY_OK then
	tune Piezo, 5,($40)
		infracnt = 200
		serout OLED,Baud,(254,1)
	 	pause 1000
		return
	 endif
	 infracnt = 200
	 goto sethour
	 
setmin:


	irin [100],b.4,infracnt
	
	gosub TimeDate24
	serout OLED,Baud,(254,192,179,180)
	if infracnt = KEY_UP then
	tune Piezo, 5,($40)
		TempMinutes = TempMinutes + 1
	 endif
	 if infracnt = KEY_DOWN then
	 tune Piezo, 5,($40)
		TempMinutes =TempMinutes -1
	 endif
	 if TempMinutes > 59 then
		TempMinutes = 0
	endif
	if TempMinutes =0 and infracnt =key_down then	let TempMinutes = 59:endif
	 BINtoascii TempMinutes,AsciiData3,AsciiData2,AsciiData1
	 serout OLED,Baud,(254,195)
	 serout OLED,Baud,("Minute -  ",AsciiData2,AsciiData1)
	 if infracnt = KEY_OK then
	 tune Piezo, 5,($40)
	 	infracnt = 200
		serout OLED,Baud,(254,1)
	 	pause 1000
		return
	 endif
	 infracnt = 200
	 goto setmin
	 
setDay:

	hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
	hi2cin 3,(tempday)	
setdayx:
	serout OLED,Baud,(254,128)
	serout OLED,Baud,(254,192,179,180)
	 irin [100],b.4,infracnt
	if infracnt = KEY_UP then tune Piezo, 5,($40) let Tempday = Tempday + 1: endif
	 if infracnt = KEY_DOWN then  tune Piezo, 5,($40) let Tempday =Tempday -1: endif
	 
	 if Selected = 6 then
	    	if tempday > 7 then
	         tempday = 1
	  	endif 
	  	if Tempday <1 then 
		Tempday = 7
	endif
	 endif 
	 if Selected = 3 then    
		 if Tempday > 10 then
			Tempday = 1
		endif
		if Tempday <1 then 
		Tempday = 10
	endif
	endif

	serout OLED,Baud,(254,195)
	DispDay = Tempday
	gosub DisplayDay
	 
	 if infracnt = KEY_OK then
	 tune Piezo, 5,($40)
	 	infracnt = 200
		 serout OLED,Baud,(254,1)
	 	pause 1000
		 return
	 endif
	 infracnt = 200
	 goto setDayx
	 
DisplayDay:

	select case DispDay
		case 1
			serout OLED,Baud,("   Sunday ")
		case 2
			serout OLED,Baud,("   Monday ")
		case 3
			serout OLED,Baud,("   Tueday ")
		case 4
			serout OLED,Baud,("Wednesday ")
		case 5 
			serout OLED,Baud,(" Thursday ")
		case 6
			serout OLED,Baud,("   Friday ")
		case 7
			serout OLED,Baud,(" Saturday ")
		case 8
			serout OLED,Baud,("Week Days ")
		case 9
			serout OLED,Baud,("Every Day ")
		case 10
			serout OLED,Baud,("Week Ends ")
	endselect
	return

Chime15:	'15 min chime

	tune Piezo, 8,($07,$05);,$04,$AB
	pause 10000
	return
	
Chime30:	'30 min chime

	tune Piezo, 8,($04,$07);,$05,$AB,$04,$05,$07,$84
	pause 10000
	return
	
Chime45:  '45 min chime

	tune Piezo, 8,($07,$04) ;,$05,$AB,$2B,$05,$07,$84,$07,$05,$04,$AB
	pause 10000
	return
	
chimehour: ' hour chime 

	 ;tune Piezo, 8,(04,$07,$05,$AB,$04,$05,$07,$84,$07,$04,$05,$AB,$2B,$05,$07,$84)
	 ;pause 200
	 for counter = 1 to temphour
 		tune Piezo, 8,($19)
 		pause 2000
 	next counter
	return
 
Top