News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

PCF8523 RTC 'Funny' with reading date

Started by Clayton, Apr 21, 2024, 07:27 AM

Previous topic - Next topic

RGV250

Hi Clayton,
Just for future reference (and your own fault finding), when posting code on here to try to get help, as Frizie mentioned in post #5 it is always best to try to isolate the issue. You will probably get a lot more assistance and quicker help, there are a lot of clever people here on lots of different subjects but do not understand the other code irrelevant to the issue.
In your code I looked at it several times and almost gave up, it was very long and had EEPROM, logging routines etc and it was only when I decided to strip all that out I found the issue.

This is the code I ended up with, I changed it for a different device and serial output but the core is the same.
Obviously need to post the INC file as well but it was the lengthy main code that may put people off looking.
$define PCF8523T_SCL_Pin PORTB.4
$define PCF8523T_SDA_Pin PORTB.1
Include  "Amicus18.inc"
Include "PCF8523T.inc"

TRISA = %10111111
TRISB = %11000001

Symbol SDApin = PORTB.1
Symbol SCLpin = PORTB.4
Output PORTB.4
Symbol RTC_Read = $D1              '%11010001
Symbol RTC_Write = $D0              '%11010000

'RTC
Dim Control1 As Byte
Dim Control2 As Byte
Dim Control3 As Byte
Dim pDay As Byte
Dim pMonth As Byte
Dim pYear As Byte
Dim pHour As Byte
Dim pMinute As Byte
Dim pSecond As Byte
Dim pWeekDay As Byte
'pWeekDay = 0    'Not currently used

PCF8523T_WriteRegister($00,%10000001)      'Control 1 Register - Correction Enabled (b0)
PCF8523T_WriteRegister($01,%00000000)      'Control 2 Register
PCF8523T_WriteRegister($02,%00000000)      'Control 3 Register
DelayMS 10
PCF8523T_WriteRegister($0E,%10000000)      'Mode 1 RTC Correction

'************************************************************************************
' MAIN
'************************************************************************************
Main:
    GetTimeAndDate()
   
    HRSOut1  Dec2 RTC_Day, "/", Dec2 RTC_Month, "/", Dec2 RTC_Year, " - ", Dec2 RTC_Hour, ":", Dec2 RTC_Minute, ":", Dec2 RTC_Second, 10,13   

    DelayMS 1000
GoTo Main   

Proc GetTimeAndDate()
    PCF8523T_ReadDate()
    PCF8523T_ReadTime()
EndProc

Bob
 

Clayton

Hi Bob,

Understood Sir.
I guess I worked on the idea that too much information is better than not enough information :)

Still, most grateful for the assist.

Thanks.
Clayton