Continue to Site

# pic16f86 -want to make 2 digit BCD counter

Status
Not open for further replies.

#### exotic-13

##### Newbie
i wanna make a counter that goes from 00 to 59 using two bcd displayers , how can i do this and please i need some youtube channels that would help improve myself .
the program is the following :
Code:
void main () {
TRISB=0;
for(i=0;  i<=5;  i++);
{    for(j=0;  j<=9; j++);
{  PORTB=j; i<<4;
delay_ms(1000);
}
i=i++
}
}

Last edited by a moderator:

#### barry

It depends on your “BCD displayer”, whatever that is. What do you want us to tell you?

#### paulfjujo

i wanna make a counter that goes from 00 to 59 using two bcd displayers , how can i do this and please i need some youtube channels that would help improve myself .
the program is the following :
Code:
void main () {
TRISB=0;
for(i=0;  i<=5;  i++);
{    for(j=0;  j<=9; j++);
{  PORTB=j; i<<4;
delay_ms(1000);
}
i=i++
}
}

I can suppose, the 2 BCD displayers are connected on PORT B
MSB on B7..B4 (0 to 5 ) and LSB on B3 ..B0 (0 to 9)
don't increase "i" in the loop, it is allready done inside "for" instruction

Code:
void main ()
{
do
{
TRISB=0;
for(i=0;  i<5;  i++);
{
for(j=0;  j<9; j++);
{
PORTB=( i<<4 )  |  j ;      // combine the two  i=MSB and  j=LSB
delay_ms(1000);
}
}
while(1);
}

#### Aussie Susan

Also the "i<<4;" doesn't do much other than waste a few cycles.
Susan

#### paulfjujo

Also the "i<<4;" doesn't do much other than waste a few cycles.
Susan
could you explain why ?

if BCD MSB is on PORT B7..B4 and BCD LSB on PORTB B3..B0
i represent the tens and j the units

As an aside this can be done as a HW only solution in case you ever
need it (1 chip, in this case 3 digits, 7 segment output data) -

This was an done on a ARM core part that has fabric inside to create other
digital HW functions, verilog was used for actual synthesis inside part.

The BCD to 7 seg was done via a simple LUT, as you can see on
above chip internal schematic.

Regards, Dana.

#### Aussie Susan

could you explain why ?
I was referring to the OP's post. I must admit that had not seen your code which, of course, uses this construct properly.
Apologies for the confusion.
Susan

Status
Not open for further replies.