This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Retrieving data from array.

Hi,
I am trying to retrieve data from an array "Buf" to register but am unable to do so.

Below is my code:

>>>>
long T_msec,Div= 360000;
int T_hours;
char Buf[3];
while(1)
{ check_digit();
T_msec = oncount;
T_hours = (int)(T_msec/Div);
sprintf(Buf,"%ud",(int)(T_msec/Div));
hour0digit = Buf[0];
hour1digit = Buf[1];
hour2digit = Buf[2];


// hour3digit = Buf[3];
p07 = 0;
}
<<<<

Please help me..

Aniket

Parents
  • Hi,
    I have a 4byte count which i have to reduce and display it on a 7 segment display in three digits hour0digit,hour1digit & hour2digit respectively. Below i have given an example count which is in miliseconds and i have to convert it to hours.
    Ex: 252000000ul; //700 hours;

    Thanks and regards,

    Aniket

Reply
  • Hi,
    I have a 4byte count which i have to reduce and display it on a 7 segment display in three digits hour0digit,hour1digit & hour2digit respectively. Below i have given an example count which is in miliseconds and i have to convert it to hours.
    Ex: 252000000ul; //700 hours;

    Thanks and regards,

    Aniket

Children
  • hi,

    I am trying to retrieve data from an array "Buf" to register but am unable to do so.

    char Buf[3];
    sprintf(Buf,"%ud",(int)(T_msec/Div));
    
    Ex: 252000000ul; //700 hours;

    You are in trouble here -- you should either make array enough long or limit number of printed chars by %.number modifier for sprintf()
    For example, "700" requires 4 bytes (note null-terminator at the end of string).

    Then look at assembler code generated by compiler. It may be that optimizer ejects some lines then read more about nonvolatile keyword.

    Regards,
    Oleg