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

How can i convert BCD data to real value?

I am doing a project which will get a time data from external Real time clock chip.
The data format of the RTC is in BCD form.

How can i convert BCD data to real value?
is there can built-in function to do that?
pls help

Parents
  • void showTime (void) {     // 24 Hour clock
      unsigned long cTime;     // RTC Value
      int  cSeconds = 0;	   // cTime/1
      int  cMinutes = 0;	   // cTime/60
      int  cHours   = 0;	   // cTime/3600
      char cBuffer [8];	   // Stores formatted string
    
      cTime = RTC_RTCH * 0x10000 + RTC_RTCL;   // Get value of RTC
      cHours   = (int) (cTime / 3600) - ((int) (cTime / 86400) * 24);
      cMinutes = (int) ((cTime / 60) - ((cTime / 3600) * 60));
      cSeconds = (int) (cTime - ((cTime / 60) * 60));
    
      sprintf (cBuffer, "%02u:%02u:%02u", cHours, cMinutes, cSeconds);
      printf ("      %s  \r", cBuffer);
    }
    

Reply
  • void showTime (void) {     // 24 Hour clock
      unsigned long cTime;     // RTC Value
      int  cSeconds = 0;	   // cTime/1
      int  cMinutes = 0;	   // cTime/60
      int  cHours   = 0;	   // cTime/3600
      char cBuffer [8];	   // Stores formatted string
    
      cTime = RTC_RTCH * 0x10000 + RTC_RTCL;   // Get value of RTC
      cHours   = (int) (cTime / 3600) - ((int) (cTime / 86400) * 24);
      cMinutes = (int) ((cTime / 60) - ((cTime / 3600) * 60));
      cSeconds = (int) (cTime - ((cTime / 60) * 60));
    
      sprintf (cBuffer, "%02u:%02u:%02u", cHours, cMinutes, cSeconds);
      printf ("      %s  \r", cBuffer);
    }
    

Children