From me reading many SuperH docs and from my testing, I am sure to say that the RTC unit has many registers (constant between many CPU versions), the 64Hz counter, the second, minute, and hour counters, and others. The first 4 (64,s,m,h) are 8 bits long, with 8 bit padding. At R64CNT (0xAxxxFEC0) is the 64 Hz counter, read only. At RSECCNT (0xAxxxFEC2) is a read/write counter for seconds, but packed for 2 digit displaying.
Here is a code demo showing the program running the RTC clock and using the 2 Hz counter in the 64 Hz counter:
Code: #include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <CONVERT_syscalls.h>
#include <color.h>
#include <display.h>
#include <keyboard.hpp>
void main(void) {
int oldsec,sec;
int count = 0;
/** A counter running at 64Hz from the 128Hz counter
*
* This Port is made up of 6 bits
* |x|1|2|4|8|16|32|64|
*
* This port is updated when the 128 Hz timer carries over.
* Therefore, bit 1 is set every 64 Hz, but stays set.
* you must wait for the bit to return to 0 if you want to opperate at 64 Hz.
*/
volatile unsigned char *port64 = 0xA413FEC0;
/** A status register for the RTC unit.
*
* bit 7 is set after a read/write to an RTC register if the 128 Hz timer carries.
* If this happens, any reads or writes are invalid and must be repeated.
* Bit 7 must be manually reset to 0.
*
* Usage:
* - reset bit 7 of RCR1
* - read R64CNT
* - if bit 7 of RCR1 is set, reset bit 7 and reread R64CNT
*/
volatile unsigned char *portRCR1 = 0xA413FEDC;
/** (For all below) Packed digits of 2 digit numbers.
*
* Writing is allowed, but must follow a procedure. See the SH7720 docs for more info.
* RCR1 bit 7 applies to this for both reads and writes.
*
* This register contains a packed 2 digit number in 134 format. Example below
* |7|6 - 4|3 - 0
* ----------------
* |x| 10s | 1s
*
* So, bits 0-4 are the first number from 0-9
* bits 4-6 are the second number from 0-5
*/
volatile unsigned char *ports = 0xA413FEC2;
volatile unsigned char *portm = 0xA413FEC4;
volatile unsigned char *porth = 0xA413FEC6;
*ports = 0;
*portm = 0;
*porth = 0;
char buffer[10];
buffer[0] = ' ';
buffer[1] = ' ';
Bdisp_EnableColor(1);
while (1) {
if(PRGM_GetKey() == 48)
{
int r,c,k;
GetKeyWait_OS(&c,&r,0,0,0,&k);
}
Bdisp_AllClr_VRAM();
while (*port64 & 0b00100000);
while (!(*port64 & 0b00100000));
count++;
itoa(count, buffer+2);
PrintXY(1,1,buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
itoa(((*porth >> 4) * 10) + (*porth & 0b1111), buffer+2);
PrintXY(4,2,buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
buffer[2] = ':';
buffer[3] = 0;
PrintXY(6,2,buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
itoa(((*portm >> 4) * 10) + (*portm & 0b1111), buffer+2);
PrintXY(7,2,buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
buffer[2] = ':';
buffer[3] = 0;
PrintXY(9,2,buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
itoa(((*ports >> 4) * 10) + (*ports & 0b1111), buffer+2);
PrintXY(10,2,buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
Bdisp_PutDisp_DD();
}
return;
}