PDA

View Full Version : 7-segment display blinking problem?



serdar_ozcan
- 13th March 2006, 15:24
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

Melanie
- 13th March 2006, 15:32
Best option would be to use Hardware PWM and HPWM command.

mister_e
- 14th March 2006, 03:13
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.

serdar_ozcan
- 14th March 2006, 11:58
Melanie,
How? Please help me. I use 16f877 and how must I use hpwm command in my code?

Melanie
- 14th March 2006, 12:23
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.

serdar_ozcan
- 14th March 2006, 14:43
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.