I'm just starting out and trying to create a very simple clock as a first project. I'm using a PIC16F628A and a DS1307 Real Time Clock. For some reason I'm unable to get any input response from a switch. I checked the wiring with a volt meter and it shows the correct voltage change when the switch is pressed so I assume I have overlooked something in the code. At this point I am just trying to have my display read 12:30 if the LeftButton is pressed. Any help is appreciated. My code follows.
Thanks,
Jeff
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 7
DEFINE DEBUG_BAUD 19200
define DEBUG_MODE 0 ' 1 = inverted, 0 = true
' DS1307 control pins
SDA VAR PORTB.1 ' DS1307 SDA pin #5
SCL VAR PORTB.2 ' DS1307 SCL pin #6
TRISA = %11111111
LeftButton var PORTA.1 ' Control Button
RghtButton var PORTA.2
second var byte
minute var byte
hour var byte
tock var byte
PAUSE 1000 ' Allow power to stabilize on power-up
GOSUB Blink_1200 ' Blink 12:00 time on entry
Tick:
gosub Read_1307 ' Read the time from the DS1307 Clock
tock = second // 2 ' Get the Mod of second
If tock = 0 then
High PORTB.0 ' Turn on LED connected to PORTB.0
debug "P",12,"~" ' Turn on colon
else
Low PORTB.0 ' Turn off LED connected to PORTB.0
debug "P",0,"~" ' Turn off colon
endif
' Display time
DEBUG "D",hour DIG 1,hour DIG 0,minute DIG 1, minute DIG 0
Goto Tick ' Go back to Tick
Read_1307:
' Read time Seconds,Minutes,Hours
I2CREAD SDA,SCL,$D0,$00,[second,minute,hour] ' Read time from DS1307
return
Write_1307:
' Set time to 12:00
I2CWRITE SDA,SCL,$D0,$00,[$00,$1E,$C,$01,$01,$01,$00,$90] ' Write to DS1307
RETURN ' Sec Min Hr Day D M Y Control
Blink_1200:
' Write 12:00 on display
DEBUG "D",1,2,0,0
debug "P",12,"~" ' Turn on colon
pause 1000
debug "C","~" ' Clear Display
debug "P",0,"~" ' Turn off colon
pause 1000
if LeftButton = 1 then
gosub Write_1307
goto Tick
endif
Goto Blink_1200
End
Bookmarks