binary to BCD to for 7 segment display, pseudo code

chupa

Member
Join Date
Jan 2013
Location
Clearwater, FL
Posts
14
I have an application where I am converting a binary 2 digit number (00-99) to BCD to display on a 7 segment display. Unfortunately I don't have the ladder here to post as I left it at work today.

I am currently doing this by converting the binary number to BCD.
To get the least significant digit I mask to only show the first 4 bits, then just use a lookup table to set the outputs to the correct value.


I am drawing a blank on how to do the most significant digit. I guess the main problem is the 2nd BCD value is not "right justified" in the word. If it were I would just do the same thing as above. I have thought about bit shifting it 4 bits to the right then just doing that but I'm not sure exactly how to achieve that. Would I just use a timer to give me 4 pulses? is there an easier way to do it?
 
Now tell us where the input data comes from, and where the output data has to go to... it does make a difference !
 
The input data is from a "Days till" count down timer. This applciation is a large display board for "Days till _________" .

I am just wanting to display that 'days' binary value on the board.

The output is a 16 chan relay card.
 
There is an instruction "built-in" that does Binary to BCD conversion for you....

It's called TOD

Code:
83 in binary is 01010011
83 in BCD is    10000011 (1000_0011)

the TOD instruction does the conversion for you
 
I am using TOD.

Where I am running into trouble is when the BCD value is sitting in the 2nd nibble of the TOD resulting word. I need it to be in the first one or approach the problem a different way.
 
I do not understand your problem....

I assumed you had an 8-bit binary number (0-255) that you needed converting to 2 BCD nibbles to output to your (decoded) seven-segment display.....
 
I mask to show only the least significant nibble of the TOD result and call a routine that looks up the display value for that number and sends it to the relay output card which displays it to the least significant digit on the board. The lookup table is just for the display values only holds the values for 0-9. NOT 0-99.

I want to call the same routine again for the most significant nibble of the TOD result but I would have to bit shift 4 bits right to do so. Which I can do and it will work but I was wondering if there are other (simpler) options.
 
So you've converted the binary number to BCD, and you apply a mask to output the LSD 4-bits to a relay card....

Then you want to output the MSD 4-bits... where to???
 
No the relay card is driving the 7 segment displays. chans 0-7 are for the LSD, and 8-15 are the MSD.

The BCD values are fed to a look-up table which then sets the relay card to the correct value to display that number.
 
So you are saying that there is a separate output for each segment of the display?

I now understand why you have a look-up table, to "decode" the nibble to the outputs needed for the seven-segment display.

Since the SLC does not have the BTD instruction, I'd suggest you just divide the converted number by 16 - this will "shift" 4-bits, discarding the lower 4 bits
 

Similar Topics

hello anyone can help me to do the convention from BCD to Binary ?? plc model s7-300 siemens.. Thank...
Replies
3
Views
3,341
  • Poll
Hello everyone I'm having a problem with purchased surplus 1771-IFC cards that will not work with our system. Apparently, the chip in it is...
Replies
4
Views
3,000
how can i convert a decimal number from an external device to bcd or binary for use in the plc . the incoming decimal value will be between 400...
Replies
7
Views
3,464
hi everybody! I only know how to convert Binary to BCD with some instruction with plc. EX: [ BCD K10 D0 ] convert 10 decimal to BCD in D0 registry...
Replies
5
Views
3,955
Hi folks, I'm trying to parse a binary string on a Red Lion DA30D using a Raw UDP/IP input port. I've done this before with ASCII strings so I do...
Replies
38
Views
978
Back
Top Bottom