-
adding with 7 segments
Hi guys,
i'm experimenting with some 7 segment displays and my 16F84A.
I can get fixed values to work ( like portb=$40 and b5=5 and lookup the value )
But when i try to increment b5 and output the result i get strange readings...
What is wrong ?
Must i do this in a different way ?
Here's the code:
'7 segment display test
'device 16F84
'7 seg portb
'1 button porta.0
'1 button porta.1
init:
'a var portb.0
'b var portb.1
'c var portb.2
'd var portb.3
'e var portb.4
'f var portb.5
'g var portb.6
'dp var portb.7
b5 var word
DEFINE OSC 4
input porta
TRISB = $80
portb=$40
pause 1500
start:
b5=5
loop:
if porta.1 =1 then
b5=b5+1
Lookup b5, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], b5
portb=$ff
portb=b5
pause 300
endif
if porta.0 =1 then
b5=b5-1
Lookup b5, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], B5
portb=$ff
portb=b5
pause 300
endif
if (porta.0=0) and (porta.1=0) then
Lookup b5, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], B5
portb=$ff
portb=b5
pause 300
endif
goto loop
Thanks
-
i think i got it:
had to change
Lookup b5, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], B5
to
Lookup b5, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], B1
.
-
I got things to work with one 7segment display.
I tryed to follow the article here with 2 7segments:
http://www.melabs.com/resources/articles/ledart.htm
but i cant get it to work...
Had to do some minor changes as some original lines were giving me errors...
something is missing here
here's the code:
B1 var word
W1 var word
B0 var word
B3 var word
TRISB = $80
loop: For B1 = 0 To 99 ' Count from 0 to 99
B0 = B1 ' Pass the count to the conversion subroutine
gosub display4
Pause 1000 ' Display it for 1 second
Next B1 ' Do next
Goto loop ' Do it forever
' Convert binary number in B0 to segments for LED
bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18],B3
Return
display4:
B0 = W1 / 10 ' Find number of tens
W1 = W1 // 10 ' Remove tens from W1
Gosub bin2seg ' Convert number to segments
Poke PortB, B3 ' Send segments to LED
Poke PortA, $1D ' Turn on second digit
Pause 1 ' Leave it on 1 ms
Poke PortA, $1F ' Turn off digit to prevent ghosting
B0 = W1 ' Get number of ones
Gosub bin2seg ' Convert number to segments
Poke PortB, B3 ' Send segments to LED
Poke PortA, $1E ' Turn on first digit
Pause 1 ' Leave it on 1 ms
Poke PortA, $1F ' Turn off digit to prevent ghosting
Return
-
have a look at this one
http://melabs.com/resources/samples/pbp/7segment.pbp
and change Display sub.
For i = 0 To 3 ' Loop through 4 digits
to
For i = 0 To 1 ' Loop through 2 digits
If you're using PBP, this will work, if you're using PBC... :eek: it might cause some headaches :(
-
Thanks it works now ;)
one note:
i have slowed down the count by adding a pause 500...
mainloop:
For Value = 0 To 99
GoSub display ' Display the value
pause 500 'slow count
Next Value
However i notice that one digit ( number ones ) stays most of the time off while the second digit ( number tens ) stays most of the time on.
I've tryed to change the pause 1 to pause 50 but not better result.
display:
For i = 0 To 1 ' Loop through 2 digits
n = Value Dig i ' Get digit to display
GoSub display1 ' Display the digit
Pause 1 ' Leave it on 1 millisecond
Next i ' Do next digit
Return
Is there a way to level this ?
Thanks