Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:06 28 Oct 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : RP2350-Touch-LCD-2.8

     Page 2 of 2    
Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2787
Posted: 09:38pm 23 Oct 2025
Copy link to clipboard 
Print this post

  Quote  It seems to be a problem with the RTC-chip implemented to the board (that mmBasic officially does not support)
The issue may not only be writing the year to the RTC but also reading it back with RTC GETTIME if it is using different registers to the regular RTCs.

I guess there are a number of ways forward.
1) As the months and days appear ok the easiest and crudest method is to substitute the correct year at bootup with something like:-
Sub MM.STARTUP
  RTC GETTIME
  Date$ = Left$(Date$,6) + "2025"
End Sub
  Quote  The command OPTION RTC AUTO ENABLE can also be used to set an automatic update of the TIME$ and DATE$ read only variables from the real time clock chip on boot and every hour.
So to avoid the year being overwritten don't use OPTION RTC AUTO ENABLE.

2) The Waveshare example programs presumably manage to set the PCF85063A RTC correctly so see if you can convert that section to MMBasic Subs for writing and reading the chip.

3) From the PCF85063A datasheet create your own RTC Subs.

4) If enough people use this chip perhaps it can be added to the firmware.

Edit.
Haven't got a PCF85063A but have been having a play with a DS3231 to see if there is a simple way to set and read the year.
This might work for the PCF85063A
RTC SetReg &H0A, &H25 'first nibble is BCD decade, second is BCD year

Sub MM.STARTUP
  Local year%
  RTC GETTIME
  RTC GetReg &H0A, year% 'read the year register
  year% = (year%>>4)*10 + (year% and 7) 'convert BCD nibbles to decimal
  Date$ = Left$(Date$,8) + Str$(year%) 'add the year to the date.
End Sub


The DS3231 test. change the register address from &h06 to &h0A to try on the PCF85063A
> Dim year%, newYear%
> newYear%=&h42 : RTC SetReg &H06, newYear% 'set year to 2042
> RTC GetReg &H06, year% : year% = (year%>>4)*10 + (year% and 7) : date$ = Left$(Date$,8) + Str$(year%)
> ? date$
24-10-2042
>

Edited 2025-10-24 12:55 by phil99

Footnote added 2025-10-26 17:46 by phil99
Red Face Time!
Did not test long enough, replace BCD to decimal converter with this.
year% = (year%>>4)*10 + (year% and 15) 'convert BCD nibbles to decimal
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8232
Posted: 06:57am 24 Oct 2025
Copy link to clipboard 
Print this post

It wouldn't be so bad if there was a good reason to use that particular RTC chip other than cost. :(  It's not as if you can rely on its accuracy. Setting the year seems to be a bit superfluous on a chip that will need to be corrected monthly (if you're lucky).
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2787
Posted: 07:20am 28 Oct 2025
Copy link to clipboard 
Print this post

  Quote  3) From the PCF85063A datasheet create your own RTC Subs.
In case the RTC SetReg and RTC GetReg method of setting/getting the year doesn't work here are two RTC Subs to do the job.

Not tested on a PCF85063A but with appropriate adjustments work on a DS1307, DS2321 and simulated PCF85063A in a EEPROM (was too wet to go out to play yesterday).
Sub PCF85063A.Get 'Load Date$ and Time$ with values from the RTC
 Local integer dt(6), n
 Local D.o.W$(7)=("Day-of-Week not set. ","Sun ","Mon ","Tue ","Wed ","Thu ","Fri ","Sat ")
 I2C WRITE &H51,0,1,4 : I2C READ &h51,0,7,dt() 'set register address pointer to 4 then read registers
 For n=0 To 6 : dt(n)=(dt(n)>>4)*10+(dt(n)And 15) : Next 'convert BCD byte to integer
 Time$ = Str$(dt(2),2,0,"0")+":"+Str$(dt(1),2,0,"0")+":"+Str$(dt(0),2,0,"0") 'assemble time
 Date$ = Str$(dt(3),2,0,"0")+"-"+Str$(dt(5),2,0,"0")+"-20"+Str$(dt(6),2,0,"0") 'assemble date
 Print "Date$ and Time$ have been updated from the RTC to  "+T$+"  "+D.o.W$(dt(4)) ' : Math v_print dt()
End Sub

'To update the Day-of-Week after setting the RTC run this at the command prompt:-
'I2C write &h51,0,2,7,DoW 'DoW = 1 for Sunday to 7 for Saturday

Sub PCF85063A.Set 'Set Date$ and Time$ first then call PCF85063A.Set to set the RTC
 Local T$=Time$+" "+Date$ ' "hh:mm:ss dd-mm-20yy"
 Local integer dt(7), n
 dt(0)=0 : dt(1)=Val(Mid$(T$,7,2)) : dt(2)=Val(Mid$(T$,4,2)) : dt(3)=Val(Left$(T$,2))
 dt(4)=Val(Mid$(T$,10,2)) : dt(5)=0 : dt(6)=Val(Mid$(T$,13,2)) : dt(7)=Val(Right$(T$,2))
 'Start at register address 4, seconds, minutes, hours, day, DoW=0, month, year (2 digit)
 For n = 2 To 7 : dt(n) = (dt(n)\10 << 4)+(dt(n) Mod 10) : Next 'convert integer byte to BCD
 I2C WRITE &H51,0,9,dt() 'send data to RTC
 Print "PCF85063A RTC time and date have been set to "+T$ ' : Math v_print dt()
End Sub

As most people have no use for these Subs (see Mick's comment), except those who have bought a module with one on it, they are quite rudimentary and there is no error detection built in.
To minimize operator error they don't accept any parameters.
Sub PCF85063A.Set
Just takes the values from Time$ and Date$ and loads them into the RTC.
Sub PCF85063A.Get
Does the reverse.
You can manually set the Day-of-Week register if you wish but it isn't needed as MMBasic has the  DAY$() Function.
Edited 2025-10-28 21:27 by phil99
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025