CMOS time

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
slacker

CMOS time

Post by slacker »

for some reason i can only read the hour and min from CMOS once and then i cant retrieve any data from those ports. why is this? i can read the DAY over and over again...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:CMOS time

Post by Pype.Clicker »

i don't see a particular reason for this ... maybe something wrong in your code, i know that the CMOS chip behaves a bit differently from the other component of the PC ...
slacker

Re:CMOS time

Post by slacker »

yea i found the problem but im not sure why it occurs.
i change the number i get to ascii code.

char a=CHANGETOASCII(cmoshours&f); low
char b=CHANGETOASCII(cmoushours>>4) high

when i put the ascii codes in a pointer like:
char *temp;
temp[0]=a;
temp[1]=b;
temp[2]=0;
print(temp);
.....it doesnt work...nothing prints

so i have to do:
char temp[3];
temp[0]=a;
temp[1]=b;
temp[2]=0;

WHY DOES THIS HAPPEN?
Tim

Re:CMOS time

Post by Tim »

Because you don't understand C strings. The first piece of code doesn't allocate any memory for the string. Your temp pointer points nowhere, so you're writing to a random memory address. In your second piece of code, you access temp as an array. The compiler allocates three elements for it, and everything works.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:CMOS time

Post by df »

also remember the cmos timmer outputs BCD numbers which need to be converted.
-- Stu --
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:CMOS time

Post by distantvoices »

BCD Numbers: a nibble of a byte represents a number? also known as packed numbers in mainframe asm?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Post Reply