adding with 7 segments


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default 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

  2. #2


    Did you find this post helpful? Yes | No

    Default

    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

    .

  3. #3


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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... it might cause some headaches
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  2. LED Machine Tach For Tired Eyes
    By Archangel in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 27th January 2010, 14:55
  3. 7 segments clock
    By the_apprentice in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th April 2006, 18:45
  4. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25
  5. WRITE not working
    By servo260 in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 29th December 2004, 02:02

Members who have read this thread : 0

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts