pause 100
setfreq m16
#picaxe 28x2
dirsB=%01011111
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
SETINT %00000000, %00001000
hi2cout $0E, (%00000110)
pause 40
'###################Define Sysmbols for HD44780 pins
symbol LCD_ENABLE=c.7 'Enable pin on HD44780 LCD module
symbol LCD_RS=c.6 'Register Select pin on HD77480, HIGH=Data, LOW=Command
symbol TIME_SET_BUTTON=pinC.0
symbol ALARM_SET_BUTTON=pinA.2
symbol incbutton=pinc.1
symbol decbutton=pinc.5
symbol RTC_INT=pinc.3
symbol outbyte =b0
symbol counter = b1
symbol bcdnum = b2
symbol nibblecount=b3
'Time Variables
symbol seconds = b4
symbol mins = b5
symbol hour = b6
symbol day = b7
symbol date = b8
symbol month = b9
symbol year = b10
symbol temp = b11
symbol hour12=b24
symbol am_pm=b25
symbol bcdmax=b26
symbol bcdmin=b27
symbol work=b28
symbol ampm_bit=b29
symbol digit1=b30
symbol digit2=b31
'Set initial values for date and time
let seconds = $50
let mins = $59
let hour = %01110001
let day = $01
let date = $31
let month = $12
let year = $16
hi2cout 0, (seconds, mins, hour, day, date, month, year)
pause 10
eeprom 0,("Time: ")
eeprom 12,("Date: ")
eeprom 18, ("SET HOUR:")
eeprom 27, ("SET MINUTES:")
eeprom 39, ("SET SECONDS:")
eeprom 51, ("SET MONTH:")
eeprom 61, ("SET DAY:")
eeprom 69, ("SET YEAR:")
eeprom 78, ("SET AM/PM:")
eeprom 88, ("AM")
eeprom 90, ("PM")
eeprom 92, ("SET ALARM (HR):")
LOW LCD_ENABLE
LOW LCD_RS
'############Initialization sequence for HD44780 Module#############
for counter = 0 to 6
lookup counter ,($33, $32, $28, $10, $01, $06, $0C), outbyte
gosub WRITE_LCD_INST
pause 10
next counter
'#####################################################################
main:
if TIME_SET_BUTTON=1 then gosub SET_TIME
if ALARM_SET_BUTTON=1 then gosub SET_ALARM
DISPLAY_TIME:
hi2cin 0, (seconds, mins, hour, day, date, month, year)
hour12 = hour & $1F
ampm_bit = hour & %00100000
if ampm_bit = 32 then
low a.1
high a.0
else
high a.1
low a.0
end if
outbyte=$80
gosub WRITE_LCD_INST
for counter = 0 to 5
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
outbyte=$C0
gosub WRITE_LCD_INST
for counter = 12 to 16
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
bcdtoascii seconds, b12, b13
bcdtoascii mins, b14, b15
bcdtoascii hour12, b16, b17
bcdtoascii date, b18, b19
bcdtoascii month, b20, b21
bcdtoascii year, b22, b23
outbyte=$86 'Move cursor to Line 1 Position 6
gosub WRITE_LCD_INST
outbyte=b16
gosub write_lcd_data
outbyte=b17
gosub write_lcd_data
outbyte=":"
gosub write_lcd_data
outbyte=b14
gosub write_lcd_data
outbyte=b15
gosub write_lcd_data
outbyte=":"
gosub write_lcd_data
outbyte=b12
gosub write_lcd_data
outbyte=b13
gosub write_lcd_data
outbyte=$C6 'Move cursor to Line 2 Position 6
gosub WRITE_LCD_INST
outbyte=b20
gosub write_lcd_data
outbyte=b21
gosub write_lcd_data
outbyte="-"
gosub write_lcd_data
outbyte=b18
gosub write_lcd_data
outbyte=b19
gosub write_lcd_data
outbyte ="-"
gosub write_lcd_data
outbyte=b22
gosub write_lcd_data
outbyte=b23
gosub write_lcd_data
goto main
'############################################################################3
WRITE_LCD_INST: 'Write Commands to LCD
low LCD_RS
outbyte=outbyte * 256 | outbyte / 16
for nibblecount= 1 to 2
'pinsB=outbyte / 16
pinsB=outbyte
pulsout LCD_ENABLE,1
pause 4
outbyte=outbyte / 16 'change to outbyte * 16 for Line 1 method
next nibblecount
return
WRITE_LCD_DATA: 'Write Data to LCD
high LCD_RS
outbyte=outbyte * 256 | outbyte / 16
for nibblecount= 1 to 2
'pinsB=outbyte / 16
pinsB=outbyte
pulsout LCD_ENABLE,1
pause 4
outbyte=outbyte / 16 'change to outbyte * 16 for Line 1 method
next nibblecount
return
'#############################################################################################################
SET_TIME:
outbyte=$01 'Clear display
gosub write_lcd_inst
gosub SET_HOUR
gosub SET_MIN
gosub SET_SECONDS
gosub SET_MONTH
gosub SET_DATE
gosub SET_YEAR
gosub SET_AMPM
do while TIME_SET_BUTTON=1 loop
outbyte=$0C
gosub WRITE_LCD_INST
'goto main
'end
return
'#############################################################################################################
SET_HOUR:
do while TIME_SET_BUTTON=1 loop
for counter = 18 to 26 'Display "Set Hour"
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
outbyte=$0F 'Turn on blinking cursor
gosub write_lcd_inst
bcdtoascii hour12, digit1, digit2 'ADD THIS TO ALL TIME SUBS
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
bcdmax=$12:bcdmin=$01
do
outbyte=$C0 'Move cursor to Line 2 Position 0 ADD THIS TO ALL TIME SUBS
gosub WRITE_LCD_INST
if incbutton=1 then
bcdnum=hour & $1F
gosub bcdinc
hour=hour &$E0 | bcdnum
hi2cout 2, (hour)
hour12=bcdnum
bcdtoascii hour12, digit1, digit2
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
do while incbutton=1 loop
endif
if decbutton=1 then
bcdnum=hour & $1F
gosub bcddec
hour=hour &$E0 | bcdnum
hi2cout 2, (hour)
hour12=bcdnum
bcdtoascii hour12, digit1, digit2
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
do while decbutton=1 loop
endif
if TIME_SET_BUTTON=1 then exit
loop
return
'##############################################################################################################
SET_MIN:
do while TIME_SET_BUTTON=1 loop
outbyte=$01 'Clear display
gosub write_lcd_inst
for counter = 27 to 38 'Display "Set Minute"
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
outbyte=$0F 'Turn on blinking cursor
gosub write_lcd_inst
bcdtoascii mins, digit1, digit2 'ADD THIS TO ALL TIME SUBS
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
bcdmax=$59:bcdmin=$00
do
outbyte=$C0 'Move cursor to Line 2 Position 0 ADD THIS TO ALL TIME SUBS
gosub WRITE_LCD_INST
if incbutton=1 then
bcdnum=mins
gosub bcdinc
mins=bcdnum
hi2cout 1, (bcdnum)
bcdtoascii bcdnum, digit1, digit2
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
do while incbutton=1 loop
endif
if decbutton=1 then
bcdnum=mins
gosub bcddec
mins=bcdnum
hi2cout 1, (bcdnum)
bcdtoascii bcdnum, digit1, digit2
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
do while decbutton=1 loop
endif
if TIME_SET_BUTTON=1 then exit
loop
return
'################################################################################
SET_SECONDS:
do while TIME_SET_BUTTON=1 loop
outbyte=$01 'Clear display
gosub write_lcd_inst
for counter = 39 to 50 'Display "SET SECONDS"
read counter,outbyte
gosub WRITE_LCD_DATA
next counter
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
outbyte=$0F 'Turn on blinking cursor
gosub write_lcd_inst
bcdtoascii seconds, digit1, digit2 'ADD THIS TO ALL TIME SUBS
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
bcdmax=$59:bcdmin=$00
do
outbyte=$C0 'Move cursor to Line 2 Position 0 ADD THIS TO ALL TIME SUBS
gosub WRITE_LCD_INST
if incbutton=1 then
bcdnum=seconds
gosub bcdinc
seconds=bcdnum
hi2cout 0, (bcdnum)
bcdtoascii bcdnum, digit1, digit2
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
do while incbutton=1 loop
endif
if decbutton=1 then
bcdnum=seconds
gosub bcddec
seconds=bcdnum
hi2cout 0, (bcdnum)
bcdtoascii bcdnum, digit1, digit2
outbyte=digit1
gosub write_lcd_data
outbyte=digit2
gosub write_lcd_data
outbyte=$C0 'Move cursor to Line 2 Position 0
gosub WRITE_LCD_INST
do while decbutton=1 loop
endif
if TIME_SET_BUTTON=1 then exit
loop
return