Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help with displaying BCD 7 segment

Status
Not open for further replies.

lordnaikon

New Member
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.
 
You need to convert your 8bit count value into BCD. This will give you 2 numbers each having a range of 0-9.

For the tens digit, divide the count by 10. For the units digit, get the remainder when you divide the count by ten.

i.e.
tens = count / 10
units = count mod 10

You then shift the tens value 4 bits to the left, bitwise OR it with the units value, and assign its value to the output port.
 
hi dougy
u mean i have to give DIV instruction to get the remainder value? how do we do that?
This is my assembly program for counter

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

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

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

DECRES: DEC R3
MOV P3,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 i do separately. because i have problem with the counter. After i got the solution then i will add to the original program. pls help me. im new with this 8052. so the problem is my program right?
 
Last edited:
You have a counter register, R3, that will count up or down. You don't have anything to stop it going over 99 or below 0. I don't know if that is important or not.

You could change it to two counters, one for units, one for 10s. When the units counter gets to 0x0A, clear it and increment the 10s counter. When the unit counter gets to 0x0F, set it to 0x09 and decrement the 10s counter.

Now your two counters are counting in BCD.

You could also add a limit at 99 and prevent down counting at 00 if you want.
 
Yes, you can use the div instruction. The following is from the KEIL site
The DIV instuction divides the unsigned 8-bit integer in the accumulator by the unsigned 8-bit integer in register B. After the division, the quotient is stored in the accumulator and the remainder is stored in the B register. The carry and OV flags are cleared.

I don't program in this language, but I'm guessing you could do something like:
mov B 10
mov A count
div AB
swap A
orl A B

now the BCD is in A
 
hi diver300.
You have a counter register, R3, that will count up or down. You don't have anything to stop it going over 99 or below 0. I don't know if that is important or not.

im using two infrared sensor. sensor 1 for entrance and sensor2 for exit. When people come in,it will count up. if P2.0 high,it will count up and if P2.1 high. it will count down.

You could change it to two counters, one for units, one for 10s. When the units counter gets to 0x0A, clear it and increment the 10s counter. When the unit counter gets to 0x0F, set it to 0x09 and decrement the 10s counter.

im not very clear with this. you mean when the counter get 0x0A (A), clear it and set to 0x09 (9)?
 
You could change it to two counters, one for units, one for 10s. When the units counter gets to 0x0A, clear it and increment the 10s counter. When the unit counter gets to 0xFF, set it to 0x09 and decrement the 10s counter.

im not very clear with this. you mean when the counter get 0x0A (A), clear it and set to 0x09 (9)?

What I mean is that to get the counter to count up to 9 and down to 0, you have to do something when the counter goes above 9 or below 0.

When the counter gets to 0x0A (one above 9), then you need to clear it to 0 and increment the counter that represents the 10s.

When the counter counts down below 0, it will get to 0xFF. Then you need to set it to 9, and decrement the counter that represents the 10s.
 
Status
Not open for further replies.

Latest threads

Back
Top