Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:48 12 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : 4 x 20 LCD IR Clock

Author Message
Bill.b

Senior Member

Joined: 25/06/2011
Location: Australia
Posts: 232
Posted: 05:52pm 04 Aug 2014
Copy link to clipboard 
Print this post

Hi All

This is my uMite version of a PICAXE clock is built some time ago.
The clocked uses a tiny RTC module from china with a DS1307 RTC Chip and a 24C32 EEPROM which I will use for the Alarm.

For setting the time and date, I use a menu system and IR remote.

As you can see, this is only a prototype using one of Big Mick's uMite boards and
a cheep AU$6.68 Chinese 4 x 20 LCDs




Menus














[code]
'MicroMite clock. 4 * 20 LCD Display, and DS1307 RTC.
'Bill Brown 19th June 2014
'This clock program uses an IR remote to set Time and Date and switch from 12 to 24 hour format.
'Alarm function not yet installed.
'Readout also includes temperature via a DS18B20 sensor.
'Controls -
' Menu button to select function.
'Left and right arrows to change from 12 to 24 h display.
'number buttons to select menu items and UP / down keys to set time and date.

LCD init 2,3,4,5,23,24
dim Daycnt$(8)
Dim RTCbuff(8)
Dim MonthCnt$(12)
form12 = 1
daycnt$(1) = "Sun,"
daycnt$(2) = "Mon,"
daycnt$(3) = "Tue,"
daycnt$(4) = "Wed,"
daycnt$(5) = "Thu,"
daycnt$(6) = "Fri,"
daycnt$(7) = "Sat,"
MonthCnt$(1) = "January"
MonthCnt$(2) = "Febuary"
MonthCnt$(3) = "March"
MonthCnt$(4) = "April"
MonthCnt$(5) = "May"
MonthCnt$(6) = "June"
MonthCnt$(7) = "July"
MonthCnt$(8) = "August"
MonthCnt$(9) = "September"
MonthCnt$(10) = "October"
MonthCnt$(11) = "November"
MonthCnt$(12) = "December"
datecode = 1
'Set key code for IR remote used.
Key_1 = 0
Key_2 = 1
Key_3 = 2
Key_4 = 3
Key_5 = 4
Key_6 = 5
Key_menu = 96
Key_OK = 101
Key_UP = 77
Key_down = 79
Key_Left = 76
Key_Right = 78
Key_ALOn = 56
Key_ALOff = 43
Key_Exit = 96
key_Info = 58
IR DevCode,KeyCode,Ir_Int
LCD clear
main:
Do
if keypress = 58 then
gosub Info
endif
if keypress = key_Right then
form12 = 1
endif
if keypress = key_left then
form12 = 0
endif
I2Caddr = &h68 ' DS1307 I2C address
I2C open 100,100 ' Enable I2C
I2C write I2caddr, 0, 1, 0
I2C Read i2caddr, 0, 8, RTCbuff(0)
I2C Close

LCD 3,1,"Temperature- "
temperature = DS18B20(15)
LCD 3,14,STR$(temperature,1,1)
lcd 3,18,chr$(223)
lcd 3,19,"C"
BCDTEMP = RTCBuff(0)
BCDtoDec BCDTEMP
if decimal < 10 then
sec$ = "0"+Str$(decimal)
else
sec$ = Str$(decimal)+" "
endif
sectemp = Decimal
BCDTEMP = RTCBuff(1)
BCDtoDec BCDTEMP
if decimal < 10 then
min$ = "0"+Str$(decimal)
else
min$ = Str$(decimal)
endif
Mintemp = Decimal
TEMPhour = RTCBuff(2)
BCDTemp = TempHour
if form12 = 1 then
if TempHour > 9 then
BCDTemp = TempHour - 6
endif
if Temphour > 18 then
BCDTemp = Temphour - 18
endif
if Temphour > 25 then
BCDTemp = Temphour - 24
endif
if temphour = 0 then
BCDTemp = 12
endif
endif

BCDtoDec BCDTEMP
HRtemp = Decimal
hours$ = Str$(decimal)
BCDTEMP = RTCBuff(3)
rem BCDtoDec BCDTEMP
day$ = daycnt$(BCDTemp)
daytemp = BCDtemp
BCDTEMP = RTCBuff(4)
BCDtoDec BCDTEMP
dattemp = decimal
Date1$ = Str$(decimal)
Dateend$ = "th "
if decimal = 1 or decimal = 21 or decimal = 31 then
Dateend$ = "st "
endif
if decimal = 2 or decimal = 22 then
Dateend$ = "nd "
endif
if decimal = 3 or decimal = 23 then
Dateend$ = "rd "
endif
bcdtemp = rtcbuff(5)

BCDtoDec BCDTEMP
montemp = decimal
month$ = monthCnt$(decimal)

bcdtemp = rtcbuff(6)
BCDtoDec BCDTEMP
Yrtemp = Decimal+2000
year$ = Str$(decimal+2000)
t$ = hours$+":"+min$+":"+sec$
D$ = date1$
Time$ = T$
LCD 1,6,T$
LCD 2,1,Day$
LCD 2,6,Month$
LCD 2,14,D$
if form12 = 1 then
if temphour > 17 then
LCD 1,15,"pm"
Else
LCD 1,15,"am"
endif
else
LCD 1,15, " "
endif
LCD 2, 16, dateend$
Loop Until keypress = key_menu
gosub menu
goto main
'Convert to Decimal
Sub BCDtoDec (BCDTEMP)
Decimal = Fix(BCDTemp / 16) * 10
Decimal = Decimal + (BCDTEMP And &hF)
End Sub

Menu: 'use IR remote to select menu items that are displayed on the LCD
Do
keypress =255
LCD 1,1, " Main Menu "
LCD 2,1, " 1- Time 2- Date "
LCD 3,1, " 3- Alarm "
LCD 4,1, " OK to SAVE "
If keypress = Key_1 Then GoSub SetTime1
If keypress = Key_2 Then GoSub SetDate
If keypress = Key_3 Then GoSub SetAlarm

Loop Until keypress = Key_OK

gosub SetDS1307

Keypress = 255
LCD clear
Return

ir_Int:
Keypress = Keycode
Pause 10
IReturn

SetTime1:
keypress = 255
Do
LCD 1,1, " Set Time Menu "
LCD 2,1, " 1- Min "
LCD 3,1, " 2- Hour "
LCD 4,1, " "
If keypress = Key_1 Then
LCD 1,2, "Set Minuit 0 to 60 "
mincode = tempdata(0,60,mintemp)
EndIf
If keypress = Key_2 Then
LCD 1,2, " Set Hour 0 to 24 "
HRcode = tempdata(0,24,hrtemp)
EndIf
Loop Until keypress = Key_OK
keypress = 255
LCD 4,1," "
Return

SetDate:
keypress = 255
Do
LCD 1,1, " Set Date Menu "
LCD 2,1, " 1- Day 2-Date "
LCD 3,1, " 3- Month 4-Year "
LCD 4,1, " "
If keypress = Key_1 Then
LCD 1,2, " Set Day 1 to 7 "
daycode = tempdata(1,7,daytemp)
EndIf

If keypress = Key_2 Then
LCD 1,2, " Set Date 1 to 31 "
datecode = tempdata(1,31,dattemp)

EndIf
If keypress = Key_3 Then
LCD 1,2, " Set Month 1 to 12 "
monthcode = tempdata(1,12,montemp)

EndIf
If keypress = Key_4 Then
LCD 1,1, "Set Year 2010 - 2060"
yearcode = tempdata(2010,2060,yrtemp)
EndIf
Loop Until keypress = Key_OK
keypress = 255
LCD 4,1," "
Return

Function tempdata (Min,max,value) 'Use IR remot to set Time and Date
keypress = 255
tempdata = value
LCD 2,5," "
LCD 3,1," "
LCD 4,1," "
Do
LCD 2,1," "
LCD 3,8,Str$(tempdata)
If keypress = key_up Then
tempdata = tempdata + 1
keypress = 255
If tempdata > max Then
tempdata = Min
EndIf
EndIf
If keypress = key_down Then
tempdata = tempdata - 1
keypress = 255
If tempdata < Min Then
tempdata = Max
EndIf
EndIf
Pause 100
Loop Until keypress = key_OK

keypress = 255
End Function

SetAlarm: 'TBA
keypress = 255
LCD 4,2, "set Alarm"
Return

SetDS1307: ' Get time from time$ and date$
tempdec = HrCode
DECtoBCD tempdec
hours = hex

tempdec = MinCode
DECtoBCD tempdec
minutes = hex

tempdec =0
DECtoBCD tempdec
seconds = hex

tempdec =daycode
DECtoBCD tempdec
rtcwday = hex

tempdec = datecode
DECtoBCD tempdec
day = hex

tempdec = monthcode
DECtoBCD tempdec
month = hex

tempdec = yearcode
DECtoBCD tempdec
year = hex
rtcctrl = &h10
' Write Time to RTC
i2caddr = &h68 ' DS1307 I2C address
i2c open 100,100 ' Enable I2C
i2c Write i2caddr, 0, 9, &h0, seconds, minutes, hours, rtcwday, day, month, year, rtcctrl
i2c Close

? "0=ok 1=nack 2=timeout"; mm.i2c
? "RTC has been set to ";hours;minutes;seconds;" ";Day;month,year
return

' Convert to Hex
Sub DECtoBCD (tempdec)
hex = fix(tempdec / 10) * 16
hex = hex OR ((tempdec / 10) - (fix(tempdec / 10))) * 10
End Sub

info:
do
lCD 1,1,"Clock program ver 1 "
LCD 2,1," for the Micomite "
LCD 3,1,"Bill Brown (Bill.b) "
LCD 4,1," June 20th 2014 "
loop until keypress = key_OK
LCD clear
return
[/code]

OOps Just noticed the spelling error on the menu screen!!

Bill
Edited by Bill.b 2014-08-06
In the interests of the environment, this post has been constructed entirely from recycled electrons.
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2946
Posted: 08:49pm 04 Aug 2014
Copy link to clipboard 
Print this post

Hi Bill, All,

A little bit more comprehensive than my feeble test I did to test my new (PCBs are ordered, hope to have them in about 2 week) IO-Panel and 20x4 display.

Excuse the poor quality, it is a screen grab of a video clip I did and I tried to enhance it a bit to show the IO-Panel (You can just make out the LEDs above the LCD). The LCDs brightness made everything else look black. I might see how to upload these things to YooToob as everyone else does.





Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2946
Posted: 08:52pm 04 Aug 2014
Copy link to clipboard 
Print this post

Hi All,

Whilst we are talking about clocks. I noticed that whilst the PCF8563 PCB I have attached via I2C keeps pretty good time (about 1 second loss every two days).. If I dont regularly check the time from the RTC and let the uMite keep pace the time is out by 4minutes (faster) per day.

Regards,

Mick

Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2946
Posted: 09:07pm 04 Aug 2014
Copy link to clipboard 
Print this post

Lads, Lasses,


Hey posting on YooToob was easier than I thought.

Here are my two Vid Clips.

Backlight Control

Clock

Mick

PS. Sorry to hijack your Thread Bill.

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025