dim
I2CWriteByte as WriteByte,
I2CReadByte as ReadByte,
I2CInitialize as Initialize,
I2CStart as Start,
I2CStop as Stop,
I2CRestart as Restart
.......
{
****************************************************************************
* Name : RTCStartWrite (PRIVATE) *
* Purpose : Starts a RTC write *
****************************************************************************
}
sub RTCStartWrite(Address as byte)
I2CStart
I2CWriteByte(RTC_DEV_ADDR)
I2CWriteByte(Address)
end sub
{
****************************************************************************
* Name : RTCStartRead (PRIVATE) *
* Purpose : Starts a RTC read *
****************************************************************************
}
sub RTCStartRead(Address as byte)
RTCStartWrite(Address)
I2CRestart
I2CWriteByte(RTC_DEV_ADDR + 1)
end sub
{
****************************************************************************
* Name : RTCStop (PRIVATE) *
* Purpose : Stops RTC read or write *
****************************************************************************
}
sub RTCStop()
Acknowledge(I2C_NOT_ACKNOWLEDGE)
Stop
end sub
{
****************************************************************************
* Name : ReadRegister (PRIVATE) *
* Purpose : Read DS1307 register ($00..$3F) *
****************************************************************************
}
function ReadRegister(pAddress as byte) as byte
RTCStartRead(pAddress)
Result = I2CReadByte(I2C_NOT_ACKNOWLEDGE)
RTCStop
end function
{
****************************************************************************
* Name : WriteRegister (PRIVATE) *
* Purpose : Write to DS1307 register ($00..$3F) *
****************************************************************************
}
sub WriteRegister(pAddress as byte, pData as byte)
RTCStartWrite(pAddress)
I2CWriteByte(pData)
RTCStop
end sub
{
****************************************************************************
* Name : ReadControl *
* Purpose : Returns the RTC control byte ($07) *
* : See the control constants RTC_SQWXXXX above *
****************************************************************************
}