Realtime clock

Assembler, C/C++ related topics
Site Admin
Posts: 744
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany

Realtime clock

Postby simon » Sun Jul 20, 2014 1:20 pm


here is a Basic program to set the time and date. It's not comfortable yet, but it works. You have to modify lines 80-140 to the actual time.

Code: Select all

10 RTC=$3dfc00 : rem RTC72421 base address
20 S1=0:S10=1*2:MI1=2*2:MI10=3*2:H1=4*2:H10=5*2:D1=6*2:D10=7*2:MO1=8*2:MO10=9*2
30 Y1=10*2:Y10=11*2:W=12*2:CD=13*2:CE=14*2:CF=15*2
40 poke RTC+CF,4 : rem 24h format
50 poke RTC+CD,4 : rem no interrupts
60 gosub 500
80 poke RTC+Y10,1:poke RTC+Y1,4 : rem 20(14)
90 poke RTC+MO10,0:poke RTC+MO1,7 : rem 07 (July)
100 poke RTC+D10,1:poke RTC+D1,5 : rem 15
110 poke RTC+H10,2:poke RTC+H1,0 : rem 20h (20:01:00)
120 poke RTC+MI10,0:poke RTC+MI1,1 : rem 01m
130 poke RTC+S10,0:poke RTC+S1,0 : rem 00s
140 poke RTC+W,2 : rem 02 (Tuesday)
150 poke RTC+CD,4 : rem no interrupts
160 print "Date/Time set"
500 poke RTC+CD,5 : HOLD Bit = 1
510 if (peek(RTC+CD) and 2) <> 0 then poke RTC+CD,4:goto 500
520 return

Attached is a program which prints the current RTC values. EmuTOS already uses the RTC too.

If you are going to read from the RTC keep in mind that only databus lines D0-D3 are connected to the RTC. D4-D7 can have any value and are not valid.
Thus AND the values coming from the RTC with 0xf.

(63.51 KiB) Downloaded 1013 times

Posts: 32
Joined: Tue Jul 08, 2014 2:17 pm

Re: Realtime clock

Postby marvin » Sat Sep 06, 2014 10:28 am

Hi Kiwi users,

the attached program can be used to quickly set and read the Kiwi clock.

Just lrun"date.bas and type "0<ENTER>" for displaying RTC date and time.
Entering date and time instead of "0" will set the Kiwi clock.
The program can be re-run multiple times.

date.bas is using the new gettimeofday() and settimeofday() C-functions, which are now part of the Kiwi-Newlib.

(80.09 KiB) Downloaded 1042 times

Site Admin
Posts: 744
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany

Re: Realtime clock

Postby simon » Mon Sep 08, 2014 9:30 pm

Great Marvin! Thank you for that. It works perfectly. The quick&dirty BASIC program I used was rather terrible compared to this...