Please help me with displaying BCD 7 segment

Thread Starter

lordnaikon

Joined Jan 9, 2010
10
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.
 

JDT

Joined Feb 12, 2009
657
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.
 

Thread Starter

lordnaikon

Joined Jan 9, 2010
10
Hi JDT.
can u give me the link?
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.
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.
 

SgtWookie

Joined Jul 17, 2007
22,210
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.

Rich (BB code):
         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
 

Thread Starter

lordnaikon

Joined Jan 9, 2010
10
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.
 

SgtWookie

Joined Jul 17, 2007
22,210
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?
 

Thread Starter

lordnaikon

Joined Jan 9, 2010
10
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.
 

JDT

Joined Feb 12, 2009
657
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!
 

eblc1388

Joined Nov 28, 2008
1,542
im still stuck with binary to bcd conversion. can someone help me with this problem?
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
 

BillB3857

Joined Feb 28, 2009
2,533
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?
 

Thread Starter

lordnaikon

Joined Jan 9, 2010
10
What exactly is your problem? :confused:
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.

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?
hi billb. that what i mean to do in assembly language. but how i want to do? pls help.
 

eblc1388

Joined Nov 28, 2008
1,542
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.
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.
 
Top