# Thread: 7-Seg display not counting

1. ## 7-Seg display not counting

Hi All,

I have a 3 digit 7-seg LED display and this works fine, but it's only display the ones...

I'm missing the tens and hundreds.

If I make W1 = 123, then it's show 123 on the display!

Thanks,

W1 = 0

Loop_1:

W1 = W1 + 1

for I = 1 to 50
gosub Display
pause 1
Next I
I = 0

goto Loop_1

' Sub to send the binary number (0-999) in W1 to 7-seg

display:

B0 = W1 / 100 ' Find number of hundreds
W1 = W1 // 100 ' Remove hundreds from W1

Gosub bin2seg ' Convert number to segments

poke PortC, B0 ' Send segments to LED
high PortA.2
Pause 5 ' Leave it on 5 ms
low PortA.2 ' Turn off to prevent ghosting

B0 = W1 / 10 ' Find number of tens
W1 = W1 // 10 ' Remove tens from W1

Gosub bin2seg ' Convert number to segments

Poke PortC, B0 ' Send segments to LED
high PortA.1
Pause 5 ' Leave it on 5 ms
low PortA.1 ' Turn off to prevent ghosting

B0 = W1 ' Get number of ones

Gosub bin2seg ' Convert number to segments

Poke PortC, B0 ' Send segments to LED
High PortA.0
Pause 5 ' Leave it on 5 ms
Low PortA.0 ' Turn off to prevent ghosting

Return ' Go back to caller

bin2seg:

' Convert binary number in B0 (0 t/m 9) to segments for LED
Lookup B0,[\$3F,\$6,\$5B,\$4F,\$66,\$6D,\$7D,\$7,\$7F,\$6F],B0

Return

END

2. ## Re: 7-Seg display not counting

Don't keep modifing W1. Only use W1 as an entry value. Do something similar to:

D1 = W1
B0 = D1 / 100 ' Find number of hundreds
D1 = D1 // 100 ' Remove hundreds from W1

Gosub bin2seg ' Convert number to segments

poke PortC, B0 ' Send segments to LED
high PortA.2
Pause 5 ' Leave it on 5 ms
low PortA.2 ' Turn off to prevent ghosting

B0 = D1 / 10 ' Find number of tens
D1 = D1 // 10 ' Remove tens from W1

Gosub bin2seg ' Convert number to segments

Poke PortC, B0 ' Send segments to LED
high PortA.1
Pause 5 ' Leave it on 5 ms
low PortA.1 ' Turn off to prevent ghosting

B0 = D1 ' Get number of ones

3. ## Re: 7-Seg display not counting

Hi Dave,

Many thanks for your advice, this solve the problem and I can display now a value of 0 to 999.

The next step is to receive this value (0-999) serial of an other PIC in the UART, Some like this:

W1 VAR WORD

If RCIF = 1 then

HSERIN [W1]
Gosub display
else
Gosub display

ENDIF

The sender (PIC16F883) send like this:

W1 VAR WORD

SEROUT PortA.7,T2400, [W1] ' True2400,N,8,1

This works very well, but the max on the Display is always 255 (8-bit)

It seems I'm missing the other half of the sending WORD...

Regards,
Gerben

4. ## Re: 7-Seg display not counting

I'have found this, W1 must be send as High.Byte and Low.Byte.

Thanks

5. ## Re: 7-Seg display not counting

I'm glad you got it going....

6. ## Re: 7-Seg display not counting

The communications works very well now.

The LED display received of the master (PIC) the CountDown value (0-999) in the UART, and show this on the three 7-Seg LED.

My next step is, to convert this Value (seconds) into Minutes and Seconds on the 7-Seg LEDs.

Sample: The Received Value 180 seconds must be show as "3.00" then 179 = "2.59" 178 = "2.58" and so down...

I found samples for a 7-Seg clock, but this works some different, some help is great!

Thanks a lott

7. ## Re: 7-Seg display not counting

I would do it something like this:

minutes = received data / 60
seconds = received data // 60

8. ## Re: 7-Seg display not counting

Maybe something like this:

Code:
```minutes=time_in_seconds/60
seconds=time_in_seconds//60```
Ioannis

9. ## Re: 7-Seg display not counting

Dave beat me while I was into something...

Ioannis

10. ## Re: 7-Seg display not counting

Convert the (0-999) seconds to minutes and seconds works well, but I didn't find a way to get this in the software incl shifting of the DP point.

Any sample of a (countdown) LED timer ?

Main:

' ******************** Main Program ********************

IF RCIF = 1 THEN ' If RCIF = 1 there's new char in RCREG

hserin [WAIT("@"),W1.HIGHbYTE,W1.LOWBYTE] ' Get char from serial port(UART)

gosub Display
Else
gosub Display

endif

goto Main

' Sub to send the number (0-999) in W1 to 7-seg

display:

D1 = W1 ' Put W1 entry value in D1
B0 = D1 / 100 ' Find number of hundreds
D1 = D1 // 100 ' Remove hundreds from W1

Gosub bin2seg ' Convert number to segments

poke PortC,B0 ' Send segments to LED
high PortA.2
Pause 3 ' Leave it on 3 ms
low PortA.2 ' Turn off to prevent ghosting

B0 = D1 / 10 ' Find number of tens
D1 = D1 // 10 ' Remove tens from W1

Gosub bin2seg ' Convert number to segments

Poke PortC,B0 ' Send segments to LED
high PortA.1
Pause 3 ' Leave it on 3 ms
low PortA.1 ' Turn off to prevent ghosting

B0 = D1 ' Get number of ones

Gosub bin2seg ' Convert number to segments

Poke PortC,B0 ' Send segments to LED
High PortA.0
Pause 3 ' Leave it on 3 ms
Low PortA.0 ' Turn off to prevent ghosting

Return ' Go back to caller

bin2seg:

' Convert binary number in B0 (0 t/m 9) to segments for LED
Lookup B0,[\$3F,\$6,\$5B,\$4F,\$66,\$6D,\$7D,\$7,\$7F,\$6F],B0

Return

END

11. ## Re: 7-Seg display not counting

I would keep it simple.

Two digits for all. If values is <9 then add a leading 0 to keep it two digits.

So no moving dot point.

Ioannis

12. ## Re: 7-Seg display not counting

Ok Ioannis, I add no moving point.

Add the Line received data // 60 give the seconds, but now missing the Minutes.

Have I split the software for the minutes (W2) ?

This is what I have:

Main:

' ******************** Main Program ********************

IF RCIF = 1 THEN ' If RCIF = 1 there's new char in RCREG

hserin [WAIT("@"),W1.HIGHbYTE,W1.LOWBYTE] ' Get char from serial port(UART)

' *** Convert 0-999 to Minutes & Seconds ***

W2 = W1 / 60 ' Minutes = W1 / 60
W1 = W1 // 60 ' seconds = W1 // 60

gosub Display
Else
gosub Display

endif

goto Main

display:

D1 = W1 ' Put W1 entry value in D1
B0 = D1 / 100 ' Find number of hundreds
D1 = D1 // 100 ' Remove hundreds from W1

Gosub bin2seg ' Convert number to segments

poke PortC,B0 ' Send Minutes to LED
high PortA.2 ' This the Minutes LED !!!
Pause 3 ' Leave it on 3 ms
low PortA.2 ' Turn off to prevent ghosting

B0 = D1 / 10 ' Find number of tens
D1 = D1 // 10 ' Remove tens from W1

Gosub bin2seg ' Convert number to segments

Poke PortC,B0 ' Send segments to LED
high PortA.1
Pause 3 ' Leave it on 3 ms
low PortA.1 ' Turn off to prevent ghosting

B0 = D1 ' Get number of ones

Gosub bin2seg ' Convert number to segments

Poke PortC,B0 ' Send segments to LED
High PortA.0
Pause 3 ' Leave it on 3 ms
Low PortA.0 ' Turn off to prevent ghosting

Return ' Go back to caller

bin2seg:

' Convert binary number in B0 (0 t/m 9) to segments for LED
Lookup B0,[\$3F,\$6,\$5B,\$4F,\$66,\$6D,\$7D,\$7,\$7F,\$6F],B0

Return

13. ## Re: 7-Seg display not counting

I do not understand why you do calculate twice the minutes and seconds and then form the calculated values you do again

B0 = D1 / 10 ' Find number of tens
D1 = D1 // 10 ' Remove tens from W1

Ioannis

14. ## Re: 7-Seg display not counting

Oh yes, I see !

I was trying to get the minutes on the display. The seconds (0-59) works.

The display received seconds (0-999) and I will display this in Min:Sec on three digits.

180 = 3.00, 179 = 2.59, 178=2.58 etc
Last edited by Gevo; - 13th May 2019 at 14:03.

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