RTC 12:00 = 0:00 in 12 hour mode
Posted: Sat Jul 27, 2013 7:21 am
I keep getting a result of 0 when reading the hour from the RTC in 12 hour mode in Virtual Box. According to the wiki I should get 0 at midnight in 24 hour mode, but I should get 12 in 12 hour mode. I could just add 12 to the hour if I get 0, but that feels like a "magic fix"; if I'm doing something wrong or not understanding something correctly that needs to be addressed.
I've tried to strip down the code to the relevant portions:
I've tried to strip down the code to the relevant portions:
Code: Select all
#define rtcRegisterSelect 0x70
#define rtcData 0x71
#define rtcStatus 0xb
//bit2: 0 = bcd, 1 = binary
//bit 1 0 = 12, 1 = 24
#define rtcStatusA 0xa
void initRTC()
{
unsigned char k;
unsigned char s;
k = readRTC(rtcStatus);
k = k & 0xfd; //clear bit 1
k = k | 4; //set bit 2
writeRTC(rtcStatus, k);
return;
}
void waitRTC()
{
//wait until rtc is valid to read
unsigned char k = 0;
while(k ==0)
{k = readRTC(rtcStatusA) & 0x80;}
//now an update is in progress
while(k ==0x80)
{k = readRTC(rtcStatusA) & 0x80;}
//now the update is over
return;
}
unsigned char readRTC(unsigned char index)
{
outb(rtcRegisterSelect, index);
return inb(rtcData);
}
void writeRTC(unsigned char index, unsigned char value)
{
outb(rtcRegisterSelect, index);
outb(rtcData, value);
return;
}
unsigned char readHours()
{
return readRTC(rtcHours);
}