My interest was sparked recently so I thought I'd try some code using an LCD 20X4
displaying Clock and temperature using
LCDRS2 serial driver
http://www.picaxeforum.co.uk/showthread.php?t=16781
Displays on
Line 1 - Time 12 hour format with seconds
Line 2 - Current Temperature Ds18b20 full range 0.1 resolution(125.0 C to -55.0 C)
Line 3 - Daily Maximum Temperature Hi:
Line 4 - Daily Minimum Temperature Lo:
If we push the button it will toggle between Celsius or Fahrenheit.
If we hold the button we can program the time
Push to select digit - Hold to save
when we release on the final minute the Ds3231sn will be programmed.
Default code of I2c is set to 100 kbps so should also work with Ds1307
Time and Temperature is updated every second.
To Do's - add more funtions later like alarms, date
- would make a good temperature controller
- feel freee to comment
Wishlist - Gimme my 20x2 Shield LOL!
displaying Clock and temperature using
LCDRS2 serial driver
http://www.picaxeforum.co.uk/showthread.php?t=16781
Displays on
Line 1 - Time 12 hour format with seconds
Line 2 - Current Temperature Ds18b20 full range 0.1 resolution(125.0 C to -55.0 C)
Line 3 - Daily Maximum Temperature Hi:
Line 4 - Daily Minimum Temperature Lo:
Code:
' -- -- -- -- -- -- -- -- -- -- -- -- --
' | 9 . 5 4 . 1 0 A M |
' | 2 5 . 5 ' C e l s i u s | Picaxe 20x2 ver C.0
' | H i : 2 6 . 8 '|
' | L o : 2 2 . 9 '| marks
' -- -- -- -- -- -- -- -- -- -- -- -- --
' LCDRS2 driver = B.4
' SDA ds3231 = B.5
' SCL ds3231 = B.7
SYMBOL ds18b20 = B.6
SYMBOL pushbutton = PINC.6
SYMBOL character1 = B2
SYMBOL character2 = B3
SYMBOL character3 = B4 : SYMBOL firstdigit = b4
SYMBOL character4 = B5 : SYMBOL programdata = b5
SYMBOL character5 = B6 : SYMBOL totaldigit = b6
SYMBOL character6 = B7 : SYMBOL lineposition = b7
SYMBOL hours = B8
SYMBOL mins = B9
SYMBOL secs = B10
SYMBOL day = B11
SYMBOL date = B12
SYMBOL month = B13
SYMBOL year = B14
SYMBOL PMAM = B15 : SYMBOL menu1 = b15
SYMBOL push = B16
SYMBOL recall = B17
SYMBOL tempMSB = b18 '(W9)
SYMBOL tempLSB = b19 '(W9)
SYMBOL Temperature = W9 '(b18,b19)
SYMBOL Maximum = W10
SYMBOL Minimum = W11
SYMBOL updatetime = W12
SYMBOL totalminutes = W13
SYMBOL displayedtime = W14
SYMBOL hold = W15
Initialise:
SETFREQ M16
owout ds18b20,%1001,($CC,$44) ' reset(send skip rom ,send convert t)
PAUSE 950 ' give time to convert
serout b.4,n9600_16,($FE,$41,$FE,$52,$FE,$51) ' turn on,backlight on,clear screen
serout b.4,n9600_16,($FE,$54,$0,$6,$9,$9,$6,$0,$0,$0,$0) ' load custom character position 8bytes
SETTIMER T1S_16
Maximum = 0 : Minimum = 2880 ' zero temperature
Main:
PAUSE 10
HI2CSETUP I2CMASTER, %11010000, I2Cslow_16, I2CBYTE ' set to 100kbps default /change to I2Cfast_16 for 400kbps
PAUSE 20
HI2CIN 0,(secs,mins,hours,day,date,month,year) ' read time ds3231
HI2CSETUP OFF
low b.5
IF hours =$0 and mins =$0 THEN:Maximum = 0 :Minimum = 2880 :ENDIF 'zero temperature start of day
LET date = BCDTOBIN date 'Date from ds3231 needs converting
LET month = BCDTOBIN month
LET year = BCDTOBIN year
LET secs = BCDTOBIN secs 'Time from ds3231 needs converting
LET totalminutes = BCDTOBIN mins * 60
LET hours = BCDTOBIN hours
PMAM =80 : IF hours < 12 then :PMAM = 65 : ENDIF 'indicate pm or am
IF hours > 12 THEN
LET updatetime = hours - 12 * 3600 + totalminutes + secs '12 hour format
ELSE
LET updatetime = hours * 3600 + totalminutes + secs
ENDIF
LET TIMER = updatetime 'up date time from ds3231
ClockDisplay:
hours = TIMER /3600
LET character1 = hours DIG 1+"0"
LET character2 = hours DIG 0
mins = TIMER //3600/60
LET character3 = mins DIG 1
LET character4 = mins DIG 0
secs = TIMER //3600//60
LET recall = secs DIG 0 : IF character6 = recall THEN clockdisplay 'wait for change in seconds
LET character5 = secs DIG 1
LET character6 = secs DIG 0
IF character1 = "0" THEN : character1 = " " : ENDIF ' zero blanking character1
serout b.4,n9600_16,($FE,$46,character1,#character2,".",#character3,#character4,".",#character5,#character6," ",PMAM,"M")'cursor home
Convert: hold=0
owout ds18b20,%1001,($CC,$44) ' reset(send skip rom ,send convert t)
IF pushbutton = 1 THEN cfselection
owout ds18b20,%0001,($CC,$BE) ' reset(send skip rom ,send read lsb msb)
owin ds18b20,%0000,(tempMSB,tempLSB) ' read in result ds18b20
Temperature = Temperature + 880
IF Temperature > Maximum THEN LET Maximum = Temperature: ENDIF 'Hi:
IF Temperature < Minimum THEN LET Minimum = Temperature: ENDIF 'Lo:
GOSUB Temp
serout b.4,n9600_16,($FE,$45, 1,2,character1,character3,character4,character5,".",character6,0) 'cursor position1 line2,degrees
Let Temperature=Maximum : GOSUB Temp
Hi: serout b.4,n9600_16,($FE,$45,10,3," Hi:",character1,character3,character4,character5,".",character6,0) 'cursor position10 line3,degrees
Let Temperature=Minimum : GOSUB Temp
Lo: serout b.4,n9600_16,($FE,$45,10,4," Lo:",character1,character3,character4,character5,".",character6,0,$FE,$48) 'cursor position10 line4,degrees,cursor off
goto main
cfSelection:
If Hold > 1600 then Menu
inc hold
If pushbutton = 1 THEN cfselection
push = push + 1//2
goto convert
Temp:
If push = 0 THEN
serout b.4,n9600_16,($FE,$45, 9,2," Celsius ")' cursor position9 line2
Temperature=Temperature * 5 / 8 -550
ELSE
serout b.4,n9600_16,($FE,$45, 9,2," Fahrenheit")' cursor position9 line2
Temperature=Temperature * 9 / 8 -670
ENDIF
let character1 =32 ' character1(Signbit) Display + (43) space (32)
IF Temperature > 64865 THEN
Temperature = -Temperature
let character1 =45 ' character1(Signbit) Display - (45)
ENDIF ' resolution to 0.1
BINTOASCII Temperature,character2,character3,character4,character5,character6
IF character3 = "0" THEN : character3 = " " ' zero blanking
IF character4 = "0" THEN : character4 = " " : ENDIF : ENDIF ' zero blanking
RETURN
Menu:menu1=0
serout b.4,n9600_16,($FE,$51,$FE,$46," Set Time") 'clear screen , cursor home
serout b.4,n9600_16,($FE,$45, 7,3," . ") 'cursor position7 line3
Selection:on menu1 goto hour,minute,program
hour: firstdigit=2 : totaldigit=24 :lineposition=7 :goto Selection1'hours entered (00-23) 24 hour format
minute: hours=programdata : firstdigit=6 : totaldigit=60 :lineposition=10:goto Selection1'mins entered (00-59)
Selection1: let recall = 0 :IF pushbutton = 1 THEN Selection1
SelectionDisplay1:hold = 0
LET character1 = recall DIG 1
serout b.4,n9600_16,($FE,$45,lineposition,3,#character1)
IF pushbutton=0 THEN SelectionDisplay1
Select1: IF hold > 600 then Selection2
INC hold : IF pushbutton = 1 THEN Select1
recall = recall + 10 : IF character1 = firstdigit THEN Selection1 : GOTO SelectionDisplay1
Selection2: let programdata = recall : IF pushbutton = 1 THEN Selection2
SelectionDisplay2: hold = 0
LET character1 = programdata DIG 1
LET character2 = programdata DIG 0
serout b.4,n9600_16,($FE,$45,lineposition,3,#character1,#character2)
IF pushbutton=0 THEN SelectionDisplay2
Select2:IF hold > 600 then : inc menu1 : goto Selection :endif
INC hold : IF pushbutton = 1 THEN Select2
INC programdata : IF character2 = 9 OR programdata = totaldigit THEN Selection2 : GOTO SelectionDisplay2
Program: serout b.4,n9600_16,($FE,$51) 'clear screen
IF pushbutton = 1 THEN program 'release to program
mins=programdata
LET date = BINTOBCD date 'convert data going to ds3231
LET month = BINTOBCD month
LET year = BINTOBCD year
LET hours = BINTOBCD hours
LET mins = BINTOBCD mins
PAUSE 10
HI2CSETUP I2CMASTER, %11010000, I2Cslow_16, I2CBYTE 'set to 100kbps default /change to I2Cfast_16 for 400kbps
PAUSE 20
HI2COUT 0, ($00, mins, hours, $00, date, month, year) 'prog time ds3231 (seconds,mins,hour,day,date,month,year)
GOTO initialise
If we hold the button we can program the time
Push to select digit - Hold to save
when we release on the final minute the Ds3231sn will be programmed.
Default code of I2c is set to 100 kbps so should also work with Ds1307
Time and Temperature is updated every second.
To Do's - add more funtions later like alarms, date
- would make a good temperature controller
- feel freee to comment
Wishlist - Gimme my 20x2 Shield LOL!
Attachments
-
70.4 KB Views: 292
-
250.4 KB Views: 403
Last edited: