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

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