7-segment display blinking problem?


Closed Thread
Results 1 to 6 of 6
  1. #1
    serdar_ozcan's Avatar
    serdar_ozcan Guest

    Question 7-segment display blinking problem?

    Hi,
    I want to display a values on 3 x 7-Segment display entering by up and down buttons. I have three buttons. Up value, down value and calibration buttons. But, at the same time, I want to send analog voltage value (depend of 7-segment display value) from portA.0. But, the value on the 7-segment display is blinking. Because when I show the display, I send also pwm command. I don't want my display is blinking..Can I correct this program ?

    DEFINE OSC 20
    Segments Var PORTB
    Digits Var PORTC
    inc var PORTE.0 ' increment button
    decr var PORTE.1 'decrement button
    set var PORTE.2 'calibration button
    i Var Byte
    j var byte
    n Var Byte
    Value Var Word
    s var byte
    t var byte
    r var byte
    c1 var word
    s0 var word
    delay var word
    dummy var word
    dummy1 var word
    dummy2 var word
    dummy3 var word
    art var byte
    azt var byte
    kon var byte
    ADCON1 = %00000010 ' Set PortA to analog.PortE to digital.
    TRISA = %00000000 ' Set PortA to output.
    TRISB = $80 ' Set segment pins to output
    TRISC = 0
    TRISD = %11111111
    TRISE = %11111111 ' PortE input.
    s = 0
    t = 0
    r = 0
    kon = 2
    mainloop:
    read 2,Value.byte0
    read 3,Value.byte1
    read 6,S0.Byte0
    read 7,s0.byte1
    if kon = 2 then gosub serdar
    kon = 0
    if inc = 1 then
    s = s + 1
    if s <= 10 then s0 = s0 + 1
    if s > 10 then s0 = s0 + 10
    if s > 230 then s = 230
    if s0 >= Value then s0 = Value
    gosub serdar
    endif
    if inc = 0 then s = 0
    if decr = 1 then
    t = t + 1
    if t <= 10 then s0 = s0 - 1
    if t > 10 then s0 = s0 - 10
    if t > 230 then t = 230
    if s0 <= 0 then s0 = 0
    gosub serdar
    endif
    if decr = 0 then t = 0
    if set = 1 then
    for j = 0 to 5
    n = 10
    i = 2
    gosub display1
    pause 1
    n = 11
    i = 1
    gosub display1
    pause 1
    n = 12
    i = 0
    gosub display1
    pause 1
    next j
    goto calib
    endif
    ser:
    PWM PORTA.0,c1,100 'send voltage depends of calibration
    gosub display
    goto mainloop
    ' Subroutine to send the number (0 - 99) in Value to LEDs
    display:
    For i = 0 To 2 ' Loop through 3 digits
    n = s0 Dig i ' Get digit to display
    GoSub display1 ' Display the digit
    Pause 1 ' Leave it on 1 millisecond
    Next i ' Do next digit
    return
    ' i = digit number
    ' n = number to display
    display1:
    Digits = $ff ' All digits off to prevent ghosting
    ' Convert binary number in n to segments for LED
    Lookup n, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18, $46, $08, $47], Segments
    ' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
    Digits = ~Dcd i
    if i = 2 then gec
    pause 20
    gec:
    Return
    serdar:
    dummy1 = s0
    dummy2 = 255
    dummy3 = Value
    dummy = dummy1 * dummy2
    c1 = div32 dummy3
    gosub display
    write 6,s0.byte0
    write 7,s0.byte1
    RETURN
    calib:
    if (set = 1) and (inc = 1) then
    art = art + 1
    if art <= 10 then Value = Value + 1
    if art > 10 then Value = Value + 10
    if art > 230 then art = 230
    if Value >= 999 then Value = 999
    endif
    if (set = 1) and (decr = 1) then
    azt = azt + 1
    if azt <= 10 then Value = Value - 1
    if azt > 10 then Value = Value - 10
    if azt > 230 then azt = 230
    IF Value <= 0 then Value = 0
    endif
    kon = kon + 1
    if kon > 2 then kon = 2
    s0 = Value
    gosub display
    write 2,Value.byte0
    write 3,Value.byte1
    if (inc = 0) or (decr = 0) then
    art = 0
    azt = 0
    endif
    if set = 0 then
    art = 0
    azt = 0
    goto mainloop
    endif
    goto calib
    END

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Best option would be to use Hardware PWM and HPWM command.

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


    Did you find this post helpful? Yes | No

    Default

    OR if you have extra i/o (let's say 8), you can even built a cheap D/A converter with resistors and an op-amp.
    Steve

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

  4. #4
    serdar_ozcan's Avatar
    serdar_ozcan Guest


    Did you find this post helpful? Yes | No

    Question How?

    Melanie,
    How? Please help me. I use 16f877 and how must I use hpwm command in my code?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I assume you have a proper copy of PBP and with it came a manual? Look up the HPWM command. It comes complete with examples in the manual. Your PIC16F877 has TWO PWM channels (look at the Datasheet), HPWM will be able to activate either one or both. Once you invoke HPWM, it keeps running in background regardless what else is happening until you change or stop it. This allows you to take new ADC reading and refresh your LED Displays without the PWM interfering.

  6. #6
    serdar_ozcan's Avatar
    serdar_ozcan Guest


    Did you find this post helpful? Yes | No

    Question how?

    Yes, of course I have a proper copy of PBP. But, when I changed "PWM portC.2,255,100" line to "HPWM 1,255,10000", I see 3,0V. on the PortC.2 instead of 5,0V. And still I can't understand. ( crystal 20MHz.) I tried on Proteus 6.7...

    Best Regard.

Similar Threads

  1. 7 Segment Displays and MAX7219
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st October 2010, 18:30
  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. Weird compile issue 7 segment LED display
    By George in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st June 2006, 02:12
  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