Hi there,
I'm having real difficulty with a binary clock I'm trying to make which should activate when given an instruction on a serial bus.
I'm using an interrupt to tell the clock to check the serial bus for an instruction but I'm using pin C.4 as the interrupt pin (which happens to be the serial in).
I found out about the disconnect command to make pin C.4 a standard input, but it doesn't seem to work properly.
I get a flashing LED (connected to output C.3 which is the Serial Out) about every second and nothing else.
Am I doing something stupid here or can you not use pin C.4 as an interrupt?
Here is my code:
'***** Input/Output Pins *****
symbol min1 = b.7
symbol min2 = c.6
symbol min4 = c.0
symbol min8 = c.2
symbol min16 = b.5
symbol min32 = b.0
symbol hours1 = b.6
symbol hours2 = c.7
symbol hours4 = c.1
symbol hours8 = c.3
symbol serdata = b.3
'input c.4 interrupt (serial data coming)
'***** Variables *****
symbol mins = b0 ' store for minutes value
symbol hours = b1 ' store for hours value
symbol days = b2 ' store for days value
symbol months = b3
symbol year = b4
symbol temp = b5 ' temporary
symbol temp_portb = b6 ' temporary port value
'***** Initialisation *****
init:
' setup portC
' as some inputs are changed to be outputs
let dirsc = %11001111
let dirsb = %11100001
'disconnect the download on c.4 and c.3
disconnect
' setup i2c for DS1307 clock operation
i2cslave %11010000, i2cslow, i2cbyte
'setup interrupt for reading a serial command
'setint %00000000, %00010000, C
'setup on/off flag to be off
let b7 = 1
'***** Main Loop *****
main:
'check on/off flag
if b7=0 then
low hours1,hours2,hours4,hours8,min1,min2,min4,min8,min16,min32
goto main
endif
' read current time from DS1307
readi2c 0,(temp,mins,hours)
'change clock values from BCD to binary
gosub bcd_bin
'optionally display on computer via debug
'debug
'display the hours and minutes
gosub display_mins
gosub display_hours
'debug
goto main
'***** Sub Procedure - convert BCD to binary *****
bcd_bin:
' convert the DS1307 BCD values to binary
temp = mins AND %00001111
mins = mins AND %11110000 * 10 / 16 + temp
temp = hours AND %00001111
hours = hours AND %11110000 * 10 / 16 + temp
' convert 24 hour clock values to 12 hour clock
if hours < 13 then do_return
hours = hours - 12
do_return:
return
'***** Sub Procedure - display the hours/mins *****
display_mins:
let temp= mins AND %00000001
if temp <> 0 then
high min1
else
low min1
endif
let temp= mins AND %00000010
if temp <> 0 then
high min2
else
low min2
endif
let temp= mins AND %00000100
if temp <> 0 then
high min4
else
low min4
endif
let temp= mins AND %00001000
if temp <> 0 then
high min8
else
low min8
endif
let temp= mins AND %00010000
if temp <> 0 then
high min16
else
low min16
endif
let temp= mins AND %00100000
if temp <> 0 then
high min32
else
low min32
endif
return
display_hours:
let temp= hours AND %00000001
if temp <> 0 then
high hours1
else
low hours1
endif
let temp= hours AND %00000010
if temp <> 0 then
high hours2
else
low hours2
endif
let temp= hours AND %00000100
if temp <> 0 then
high hours4
else
low hours4
endif
let temp= hours AND %00001000
if temp <> 0 then
high hours8
else
low hours8
endif
return
'***** Sub Procedure - Interrupt Handler *****
interrupt:
'reinstate the interrupt on return
setint %00000000, %00010000, C
high hours1,hours2,hours4,hours8
serin [500, returnint],serdata, N2400,("device 1")
if b7 = 0 then
let b7 = 1
else
let b7 = 0
endif
return
returnint:
return
I'm having real difficulty with a binary clock I'm trying to make which should activate when given an instruction on a serial bus.
I'm using an interrupt to tell the clock to check the serial bus for an instruction but I'm using pin C.4 as the interrupt pin (which happens to be the serial in).
I found out about the disconnect command to make pin C.4 a standard input, but it doesn't seem to work properly.
I get a flashing LED (connected to output C.3 which is the Serial Out) about every second and nothing else.
Am I doing something stupid here or can you not use pin C.4 as an interrupt?
Here is my code:
'***** Input/Output Pins *****
symbol min1 = b.7
symbol min2 = c.6
symbol min4 = c.0
symbol min8 = c.2
symbol min16 = b.5
symbol min32 = b.0
symbol hours1 = b.6
symbol hours2 = c.7
symbol hours4 = c.1
symbol hours8 = c.3
symbol serdata = b.3
'input c.4 interrupt (serial data coming)
'***** Variables *****
symbol mins = b0 ' store for minutes value
symbol hours = b1 ' store for hours value
symbol days = b2 ' store for days value
symbol months = b3
symbol year = b4
symbol temp = b5 ' temporary
symbol temp_portb = b6 ' temporary port value
'***** Initialisation *****
init:
' setup portC
' as some inputs are changed to be outputs
let dirsc = %11001111
let dirsb = %11100001
'disconnect the download on c.4 and c.3
disconnect
' setup i2c for DS1307 clock operation
i2cslave %11010000, i2cslow, i2cbyte
'setup interrupt for reading a serial command
'setint %00000000, %00010000, C
'setup on/off flag to be off
let b7 = 1
'***** Main Loop *****
main:
'check on/off flag
if b7=0 then
low hours1,hours2,hours4,hours8,min1,min2,min4,min8,min16,min32
goto main
endif
' read current time from DS1307
readi2c 0,(temp,mins,hours)
'change clock values from BCD to binary
gosub bcd_bin
'optionally display on computer via debug
'debug
'display the hours and minutes
gosub display_mins
gosub display_hours
'debug
goto main
'***** Sub Procedure - convert BCD to binary *****
bcd_bin:
' convert the DS1307 BCD values to binary
temp = mins AND %00001111
mins = mins AND %11110000 * 10 / 16 + temp
temp = hours AND %00001111
hours = hours AND %11110000 * 10 / 16 + temp
' convert 24 hour clock values to 12 hour clock
if hours < 13 then do_return
hours = hours - 12
do_return:
return
'***** Sub Procedure - display the hours/mins *****
display_mins:
let temp= mins AND %00000001
if temp <> 0 then
high min1
else
low min1
endif
let temp= mins AND %00000010
if temp <> 0 then
high min2
else
low min2
endif
let temp= mins AND %00000100
if temp <> 0 then
high min4
else
low min4
endif
let temp= mins AND %00001000
if temp <> 0 then
high min8
else
low min8
endif
let temp= mins AND %00010000
if temp <> 0 then
high min16
else
low min16
endif
let temp= mins AND %00100000
if temp <> 0 then
high min32
else
low min32
endif
return
display_hours:
let temp= hours AND %00000001
if temp <> 0 then
high hours1
else
low hours1
endif
let temp= hours AND %00000010
if temp <> 0 then
high hours2
else
low hours2
endif
let temp= hours AND %00000100
if temp <> 0 then
high hours4
else
low hours4
endif
let temp= hours AND %00001000
if temp <> 0 then
high hours8
else
low hours8
endif
return
'***** Sub Procedure - Interrupt Handler *****
interrupt:
'reinstate the interrupt on return
setint %00000000, %00010000, C
high hours1,hours2,hours4,hours8
serin [500, returnint],serdata, N2400,("device 1")
if b7 = 0 then
let b7 = 1
else
let b7 = 0
endif
return
returnint:
return