Please help me with displaying BCD 7 segment

Discussion in 'The Projects Forum' started by lordnaikon, Jan 9, 2010.

  1. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    Hi to all.
    Im new to this forum and new to electronic. I need some guidance. Currently im doing a project for my final year. My project have two infrared sensor which i put at entrance and exit. I mean like visitor counter. I use atmel 8052 microcontroller (AT89S52) and i program it in assembly. I program port 2 as sensor input,port 1 is output and port 3 as counter which give 8 bit binary code from P3.0 to P3.7. Im stuck with the counter part only. The others all ok. I want to display from 00 to 99. So,the 8 bit binary will display until 99. I already done with two common anode 7 segment display and two SN74LS47N ic which is BCD to 7 segment decoder. The display will display from 0 to F. In BCD,it just display 0 to 9 right? how do i skip from A to F? I mean,i just want to display 0 to 9 only. I also try using common cathode 7 segment with 74HC4511.The ic is the same with 74LS47. The result is the same. But when the counter reach 10 to 15. It will give blank display for A,B,C,D,E,F and come back to 0. so it will count until 15 too. Suppose after 9 it will display 0 and another one 7 segment will display 1. it will display 10 by using two 7 segment and it will count until 99. Can anyone please help me.. how do i skip A(1010),B (1011),C (1100),D (1101),E (1110), F (1111) and just displaying 0 to 9. Another things is do i need binary to BCD converter ic for displaying 00 to 99? Sorry for my bad english.
     
  2. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    If you want to use two BCD to 7-segment decoder IC's then instead of outputting 8-bit binary on your port you need to output two 4-bit BCD digits.

    P3.0 to P3.3 - Units BCD
    P3.4 to P3.7 - Tens BCD

    This conversion is done in software in your Atmel micro-controller.

    There are many on-line examples showing how to do this.

    If you have two 8-bit ports available you could do the BCD to 7-segment conversion in the micro-controller (using a look-up table) and drive the displays directly.
     
  3. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    Hi JDT.
    can u give me the link?
    you mean i have to use 2 port of my microcontroller right?
    im new with this. This is my assembly code. im using microvision from Keil.

    ORG 0000H
    MOV P0,#0H
    MOV P1,#0H
    MOV P2,#0H
    MOV R3,#0H

    MAIN: JB P1.0, INCRES
    JB P1.1, DECRES
    SJMP MAIN

    INCRES: INC R3
    MOV P2,R3
    ACALL DELAY
    SJMP MAIN


    DECRES: DEC R3
    MOV P2,R3
    ACALL DELAY
    SJMP MAIN


    DELAY: MOV R0,#20
    LOOP3: MOV R1,#255
    LOOP2: MOV R2,#255
    LOOP1: DJNZ R2,LOOP1
    DJNZ R1,LOOP2
    DJNZ R0,LOOP3

    RET

    END

    this program is the part of counter. im stuck with the counter. if i get the solution then i will add to the original program.

    im using two sensor. sensor 1 for entrance and sensor 2 for exit. when P1.0 get high. it will count up and when P1.1 get high. it will count up. so how do i do? please help me. im new with programming 8052.
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I've taken the liberty to reformat your source code.
    Please use the CODE blocks to preserve your original formatting. You can find the # icon on the Advanced screen (use the Go Advanced button) that will insert these blocks for you.

    Code ( (Unknown Language)):
    1.          ORG 0000H
    2.          MOV P0,#0H
    3.          MOV P1,#0H
    4.          MOV P2,#0H
    5.          MOV R3,#0H
    6.  
    7. MAIN:    
    8.          JB P1.0, INCRES
    9.          JB P1.1, DECRES
    10.          SJMP MAIN
    11.  
    12. INCRES:
    13.          INC R3
    14.          MOV P2,R3
    15.          ACALL  DELAY        
    16.          SJMP MAIN
    17.          
    18. DECRES:
    19.          DEC R3
    20.          MOV P2,R3
    21.          ACALL  DELAY    
    22.          SJMP MAIN
    23.  
    24. DELAY:  
    25.          MOV    R0,#20
    26. LOOP3:  
    27.          MOV    R1,#255
    28. LOOP2:  
    29.          MOV    R2,#255
    30. LOOP1:  
    31.          DJNZ   R2,LOOP1
    32.          DJNZ   R1,LOOP2
    33.          DJNZ   R0,LOOP3
    34.          RET    
    35.          END
    36.  
     
  5. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    hi sgtwookie.

    Sorry for that.I will not do that again. hmm. could u kindly help me with this 7 segment?
     
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  7. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    how do i do that? im new with programming 8052. currently i write program using assembly. i dont know how to write in c. pls help me.
     
  8. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    The basic technique is covered in the web page that I posted a link to.

    It's shifts, and adds.

    You DO know how to perform shifts, and adds, right?
     
  9. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    Yes mr SgtWookie. sorry for late reply. I don't know how to perform add and shift. actually,im not very sure. To convert binary to BCD,first we must MUL (multiply) the BCD by 2 right? if it more then 9 we have to ADD 6 by it. To perform shift, we using rotate left (RL) right? that mean we have to give number to perform this method. So the counter only display the result on 7 segment. im i right? How to do that? i don't know.
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  11. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    thank you mr SgtWookie. i'll try my best. later if i got problem i will ask.
     
  12. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    I can't give you any Atmel code (don't use it). But I have done this many times in a PIC. A flowchart would go something like this:-

    Initialise a register to zero.
    (this will store the BCD tens digit)
    Copy your 8-bit binary number to another register
    (this will ultimately contain the BCD units value)

    Setup a loop
    If your binary number is greater than 9
    Subtract 10 from your binary number.
    Increment the BCD tens digit
    Do it again
    Else
    End the loop
    (The remainder is the BCD units value)

    Now, for each BCD digit,
    Look-up the 7-segment data,
    Put on the port.

    Don't know how to do look-up in an Atmel. There is another All About Circuits Forum where you will be able to find help on this.
    Ask in there!
     
  13. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    ok. thnks JDT. i'll try to do. if i fail to do. i'll post and ask for help in AAC forum.
     
  14. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    im still stuck with binary to bcd conversion. can someone help me with this problem?
     
  15. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    What exactly is your problem? :confused:

    1. don't understand how the flowchart works
    2. unable to convert flowchart into assembly code for 8051 codes
    3. no time to do the programming
     
  16. BillB3857

    Senior Member

    Feb 28, 2009
    2,400
    348
    Believe me when I say I don't do any uP programming, but it seems as though trying to convert from Hex to Dec is the long way around. Wouldn't it be more simple to reset the unit position to zero on the 10th count and supply a carry to the Tens position? Likewise, on a down count, when the Units count reaches zero, on the next down count, decrement the tens position by one and set the units to 9?
     
  17. lordnaikon

    Thread Starter New Member

    Jan 9, 2010
    10
    0
    hi eblc1388. sry for late reply. firstly my problem is how do i get bcd count 00 to 99 to 7 segment. from my uC i get 8 bit binary. tht equivalent to 2 digit bcd. but, it display A to F too. i want after 9 goes to 0 back skip A to F. so how do i do in assembly. i program it using keil uvision. u see my program above that sgtWookie post and reformat above. can u help me? after the count R3 count to 0000 1001(nine),i want i goes to 0001 0000(10). not 0000 1010. and the 4 bit at digit 1 will count until 0 to nine. when it reach nine i will give 0010 0000(20). it will repeat until 99 decimal.

    hi billb. that what i mean to do in assembly language. but how i want to do? pls help.
     
  18. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    What you want to do is to convert a binary value (between 00-99 decimal) into two BCD digits. If you place these two digits into one byte, then you have a packed BCD value, like you wanted in the first place.

    Say for example your binary value "B" is 34 = 0x22 (00100010) and you want 0x34 (0011-0100) as the output.

    First clear a variable "K" to zero. Then keep on subtracting 10 from the binary value "B", increment "K" each times you subtract 10, loops until you have borrow. Now you have done the "-10 operation" four times, or once too many. Add 10 back to the previous result. Masked off higher nybble(bit4 to 7) to get the unit value, which will be 4. This is the bit0~3 of your final result.

    Reduce the value of "K" by one to get 3, now this is your TEN-digit value. Swap it to bits 4 to 7 and add the result of the above. You have 0x34 as your result.
     
Loading...