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);
}