Decoding variable into 4 digits of BCD, are there simple ways to this?


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Decoding variable into 4 digits of BCD, are there simple ways to this?

    Hello. I have giant 7 segment 4 digit display, which is driven by 4 CD4543BE (Inputs tied together, latches driven separately).

    Say I connected it to MCU, with 1 digit display I can do something like this

    Code:
    IF A=1 THEN HIGH PINA: LOW PINB: LOW PINC: LOW PIND
    IF A=2 THEN HIGH PINB: LOW PINA: LOW PINC: LOW PIND
    And so on. There will be 10 lines of code in case of 1 digit display. But with 2-3-4 digits same approach will generate a huge code. One way I see is to use DIG statement and loop it 4 times to get all digits decoded. Maybe there are other, more elegant ways to do this?

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    It all depends on how the hardware is configured. Is the design optimized for minimal code? With out a schematic it's hard to say...
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Well, there is no hardware yet I plan to use PIC16F887. The modules itself have A-B-C-D inputs of CD4543BE connected in paralel, and latch pins are also available on connector.

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    If you mean hooking up A to PORTC.0, B to PORTC.1, C to PORTC.2 and D to PORTC.3, to be able to directly address them, then yes, I can do that.

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Schematic...... Not some wild a** guess... Definitive schematic Please...
    Dave Purola,
    N8NTA
    EN82fn

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Schematic of what?

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Here is simple counter code I've made. It just counts from 0 to 99. But it is far from perfection.

    Code:
    marcato:
    tato=0
    FOR KAKO=0 TO 99
    XAXO=KAKO DIG 0
    high latch 'enable write ones
    low latch2 'disable write tens
    gosub decoder 'display ones
    if xaxo=0 and kako dig 1<>0 then 'if count is above 10
    low latch 'disable ones
    high latch2 'enable tens
    'tato=tato+1
    xaxo=kako dig 1
    gosub decoder
    xaxo=0
    endif
    
    if xaxo=0 and kako dig 1=0 then     'reset leading 0
    low latch
    high latch2
    xaxo=0
    gosub decoder
    endif
    
    PAUSE 300
    NEXT 
    goto marcato
    END
    
    decoder:
    IF XAXO=0 THEN GOSUB ZERO 
    IF XAXO=1 THEN GOSUB ONE
    IF XAXO=2 THEN GOSUB TWO
    IF XAXO=3 THEN GOSUB THREE
    IF XAXO=4 THEN GOSUB FOUR
    IF XAXO=5 THEN GOSUB FIVE
    IF XAXO=6 THEN GOSUB SIX
    IF XAXO=7 THEN GOSUB SEVEN
    IF XAXO=8 THEN GOSUB EIGHT
    IF XAXO=9 THEN GOSUB NINE
    return
    
    ZERO:
    LOW A: LOW B: LOW C: LOW D
    RETURN
    ONE:
    HIGH A: LOW B: LOW C: LOW D
    RETURN
    TWO:
    LOW A: HIGH B: LOW C: LOW D
    RETURN
    THREE:
    HIGH A: HIGH B: LOW C: LOW D
    RETURN
    FOUR:
    HIGH C: LOW A: LOW B: LOW D
    RETURN
    FIVE:
    HIGH C: HIGH A: LOW B: LOW D
    RETURN
    SIX:
    HIGH C: HIGH B: LOW A: LOW D
    RETURN
    SEVEN:
    HIGH A: HIGH B: HIGH C: LOW D
    RETURN
    EIGHT:
    HIGH D: LOW A: LOW B: LOW C
    RETURN
    NINE:
    HIGH D: HIGH A: LOW B: LOW C
    RETURN

  8. #8
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Choose a port (A,B, or C). Connect the low 4 pins of the port to carry the number you want to display and connect those to the data pins of the CD4543BE. Then connect the 4 pins of the high byte to the latches. to write "2" to the first digit, send "12" to the port. to write 9 to the second digit send "29" to the port. Write 6 to the 3rd port with "46" and so on.

  9. #9
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Excellent, thank you! will give it a try

    So as I understand, this should display "2" in 1st digit from left?

    PORTC=%10000010

    or

    PORTC=52

    ?

  10. #10
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    The binary code you displayed is correct, however that is 82, not 52,
    52 would put "2" on the 4th digit AND the first digit as well. (the numbers are hex, by the way - not decimal)
    Last edited by Charlie; - 7th March 2020 at 12:52.

  11. #11
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    Yes I see, is there a number to directly use decimal variable, or I need to convert it to hex?

    And by the way, since I will have 16 total of such modules, to save number of MCU pins used, I come up with idea of using CD4514BE - 4 to 16 decoder, this should allow me to by using only 5 pins from MCU, drive up to 16 modules.
    Name:  latcher2.JPG
Views: 873
Size:  55.1 KB
    Last edited by CuriousOne; - 8th March 2020 at 05:19.

  12. #12
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Decoding variable into 4 digits of BCD, are there simple ways to this?

    from 0-9 hex and decimal are exactly the same so no "conversion" is required. The high nibble is really decoding the device since you need a pin for each device so you want binary 0001, 0010, 0100, 1000. This is hex 1,2,4,8. It is simplest to treat the byte as 2 nibbles, the low one with the number to display, the other with the address.

Similar Threads

  1. Best way or ways?
    By Ramius in forum General
    Replies: 9
    Last Post: - 1st August 2013, 03:01
  2. Ways to make code easily reviewable and extendable
    By Ted's in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 23rd August 2008, 01:10
  3. Array to simple Variable converting
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2006, 17:44
  4. Showing numbers in diffrent ways?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th July 2005, 16:57
  5. PIC problem, ways to do reset
    By lab310 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th May 2005, 15:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts