Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How do I convert BCD value into integer value?

Status
Not open for further replies.

deepshah3

Junior Member level 1
Joined
Jan 30, 2018
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
161
How do I convert BCD value into integer value

I am making a clock by interfacing RTC ds1307 with PIC16F877A.For the display I am using 4 seven segment LED displays.The data read from RTC is in BCD form.In order to display the value on the 7 segment display,I need it to be an integer value.Can someone provide me the C code to convert the BCD value into integer value?
 

Re: How do I convert BCD value into integer value

Hi,

No. You don´t need a true BCD to integer calculation.

You just need to mask each BCD nibble and use a table to form BCD-7segments.
I assume there are more than 100,000 solutions with code and description in the internet.

Do a forum search.
Do an internet search.

Klaus
 

Re: How do I convert BCD value into integer value

I suspect some misunderstanding. BCD coding of popular RTC chips means that you directly send the tim values to display without any conversion. Conversions may be required if you do calculations with time values, e.g. integer seconds_since_midnight.
 

Re: How do I convert BCD value into integer value

There could be a misunderstanding.I am a beginner in embedded c coding,so forgive me if my questions are silly.But according to the datasheet the values of calender and clock are stored in BCD format.I am using a standard code for displaying values on a 7 segment LED display.But for that I need the values to be in integer form.I know about unpacking the packed BCD numbers.Is it possible to convert those unpacked BCD values to integer form?

- - - Updated - - -

I am a beginner in embedded C coding.So sorry if my questions are silly.
You are right.I did check many posts on the internet before coming here.I was not able to completely understand the codes.I can unpack the packed BCD numbers read from the RTC.But I just want to know if there is a code to convert those unpacked values into integer form,since i am using a standard code to display values on 7 segment display and it requires the value to be in integer form.
 

Re: How do I convert BCD value into integer value

If you are stuck to the "display standard code", you need convert BCD to integer before. But you can avoid it by displaying BCD directly.

You convert to integer by extracting the BCD nibbles and multiplying with the digit value, e.g.
Code:
secs = (bcd_secs >> 4)*10 + (bcd_secs & 0xf);
 
Re: How do I convert BCD value into integer value

Hi,

BCD values are 4 bits only.
range is: 0x00 up to 0x09

In this range BCD and integer values are identical. No need for a conversion.

But you say you want to drive a 7-segment display. What signals does it need? One line per segment - or anything else? If so, then what polarity does it need? 0 = ON or 0 = OFF?

Klaus
 

Re: How do I convert BCD value into integer value

I am using a common anode display,so 0=ON.
 

Re: How do I convert BCD value into integer value

Hi,

it´s not difficult to write a table for the numbers 0..9 that shows which segements need to be ON.
Or you do an internet search - as already recommended.


Klaus
 
Re: How do I convert BCD value into integer value

Thank you very much for your response.I understood now what you are trying to say about displaying the BCD value.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top