why does AUXIO command break my real time clock?
I am using the following program and it works just fine on the main IO pins.
I am using a BS2p40. I want to switch to the aux io pins and use the clock on pin 6 and 7 [7th and 8th pin].
Why won't AUXIO work?
I am using a BS2p40. I want to switch to the aux io pins and use the clock on pin 6 and 7 [7th and 8th pin].
Why won't AUXIO work?
' {$STAMP BS2p}
' {$PBASIC 2.5}
' An example program to test I2C-RTC Real-time Clock.
' The program is set of display the current time.
' The program is working directly with I2C-RTC module.
'
'
' NOTE: For BS2P, this program only work with firmware rev. 1.3 or grater.
#IF ($STAMP < BS2P) #THEN
#ERROR "Program requires BS2p, BS2pe, or BS2px."
#ENDIF
'************************************************************
AUXIO
SDA PIN 6 ' I2C SDA pin
SCL PIN SDA+1 ' I2C SCL pin
I2C_WR CON $D0 ' I2C write address
I2C_RD CON $D1 ' I2C read address
Readtime VAR Bit ' Set/Read time flag
Second VAR Byte ' Store second value
Minute VAR Byte ' Store minute value
Hour VAR Byte ' Store hour value
Day VAR Byte ' Store day value
Date VAR Byte ' Store date value
Month VAR Byte ' Store month value
Year VAR Byte ' Store year value
MAIN:
PAUSE 100
' Display menu
DEBUG "What would you like to do?", CR
DEBUG "(0) To set the current time.", CR
DEBUG "(1) To display the current time.", CR, CR
DEBUG "Enter 0 or 1: "
' Get input
DEBUGIN BIN1 Readtime
IF Readtime THEN ' Goto Display time subroutine
GOSUB Displaytime
ELSE ' Goto Set time subroutine
GOSUB Settime
ENDIF
PAUSE 1000 ' Delay 1 second
GOTO MAIN
'**************************************************************
' Display time subroutine
'**************************************************************
Displaytime:
I2COUT SDA, I2C_WR, [0]
I2CIN SDA, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
DEBUG CR, "The current time is ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, " ",HEX2 Hour,":",HEX2 Minute,".",HEX2 Second,CR,CR
RETURN
'**************************************************************
' Set time subroutine
'**************************************************************
Settime:
DEBUG CR, "Enter hours (00-23): "
DEBUGIN HEX2 Hour
Hour = Hour & %00111111 ' Disable century
DEBUG CR, "Enter minutes (00-59): "
DEBUGIN HEX2 Minute
DEBUG CR, "Enter seconds (00-59): "
DEBUGIN HEX2 Second
Second = Second & %01111111 ' Enable oscillator
DEBUG CR, "Enter day (01-07): "
DEBUGIN HEX2 Day
DEBUG CR, "Enter date (01-31): "
DEBUGIN HEX2 Date
DEBUG CR, "Enter month (01-12): "
DEBUGIN HEX2 Month
DEBUG CR, "Enter year (00-99): "
DEBUGIN HEX2 Year
I2COUT SDA, I2C_WR, [0,Second,Minute,Hour,Day,Date,Month,Year]
DEBUG CR, CR, "The current time has been successfully set!", CR, CR
RETURN
RUN(0)
END

Comments