Code: Select all
if (UART1_Data_Ready() <> 0) then
UartDataReceived = UART1_read
if UartDataReceived = 72 then 'IF THE CONTROL SOFTWARE SENDS "H" -> "HOURS" ON THE SERIAL ...
for I = 0 to 3
output[I] = UART1_read
next I
SetHr = ((Output[0] - 48) * 10) + Output[1]
SetMin = ((Output[2] - 48) * 10) + Output[3]
SetHr = dec2bcd(SetHr)
SetMin = dec2bcd(SetMin)
I2C2_Start() ' issue start signal
I2C2_Write(0xD0) ' address DS1307
I2C2_Write(0) ' start from word at address
I2C2_Write(0x00) ' write 00 to seconds word
I2C2_Write(SetMin) 'write minutes
I2C2_Write(SetHr) ' write hours
I2C2_Write(0x03) ' write 7 - >Sat
I2C2_Write(0x30) ' write 4 to date word
I2C2_Write(0x03) ' write 11 (nov) to month word
I2C2_Write(0x21) ' write 17 to year word
I2C2_Write(0x00) ' alm1 seconds
I2C2_Write(0x00) ' alm1 minutes
I2C2_Write(0x00) ' alm1 hours
I2C2_Write(0x00) ' alm1 day/date
I2C2_Write(0x00) ' alm2 minutes
I2C2_Write(0x00) ' alm2 hours
I2C2_Write(0x00) ' alm2 day/date
I2C2_Write(0x04) ' turn off the squarewave output pin
I2C2_Write(0x00) ' clear the status registers
I2C2_Stop() ' issue stop signal
VisualTftTime()
end if
end if