PDA

View Full Version : Multiplexing 7-Segment



ross246
- 16th June 2011, 10:26
Hi guys,

I'm currently creating a project to learn with and it's all working except for one small thing. It uses 3 7-segment displays to basically create a counter that increases on an interrupt using a PIC16F685. I am using interrupt code from another forum post, could have been on here so I don't really understand it just yet. The rest of the code is my own as I have fiddled with multiplexing before. Here is the code I will post the problem after:



define OSC 4
'LEDTOP --> PORTC.0
'LEDTOPLEFT --> PORTC.1
'LEDTOPRIGHT --> PORTC.2
'LEDMIDDLE --> PORTC.3

'LEDBOTTOMRIGHT --> PORTC.4
'LEDBOTTOM --> PORTC.5
'LEDBOTTOMLEFT --> PORTC.6
'SEG1 --> PORTB.7
'SEG2 --> PORTB.5
'SEG3 --> PORTB.6
TRISA = %11111111
TRISB = %00000000
TRISC = %00000000
ADCON1=%00000111
ANSELH=0
ANSEL=0
CM1CON0=0
CM2CON0=0
num VAR WORD
var1 VAR WORD
var2 VAR WORD
var3 VAR WORD
num=0
DisArray var byte[10]
DisArray(0) = %01110111
DisArray(1) = %01000010
DisArray(2) = %01101101
DisArray(3) = %00111101
DisArray(4) = %00011110
DisArray(5) = %00111011
DisArray(6) = %01111010
DisArray(7) = %00010101
DisArray(8) = %01111111
DisArray(9) = %00111111
OPTION_REG = %00111000
INTCON.2 = 0
INTCON.5 = 1
TMR0 = $FF

On Interrupt Goto incNum

loop:
var1 = num DIG 2
var2 = num DIG 1
var3 = num DIG 0

GOSUB selseg1
PORTC = DisArray(var1)
pause 5
GOSUB selseg2
PORTC = DisArray(var2)
pause 5
GOSUB selseg3
PORTC = DisArray(var3)
pause 3
goto loop
disable
incNum:
If INTCON.2 = 1 then
num = num + 1
endif
TMR0 = $FF
INTCON.2 = 0
RETURN
ENABLE
Selseg1:
portb = %01111111
RETURN
Selseg2:
portb = %11011111
Return

Selseg3:
portb = %10111111
RETURN
End



It is creating a feint shadow of the 3rd segments number on the 1st segment. In other words if I make it display the number "123", it displays the number perfectly clear, but if you look closesly or in a dark room you can see the number "3" over the number "1".

I have tried fiddling with the delays but I can't get it right. Thanks :)

Ross Steytler

BobEdge
- 16th June 2011, 15:57
Hi,

I think you need to switch the port b off before going to set the segments, when you enable your port b the segments are briefly set to the previous number.

Regards
Bob...

ross246
- 16th June 2011, 17:01
By switching off you mean assigning it %00000000 or in my case %11111111 since it is a common cathode display?

I tried that out and still nothing, I also tried adding a small pause between selecting the other display and its still creating "shadows". Now that it is dark I see that it is doing it on all 3 segments. All "shadowing" the previous one.

Thanks for your reply

ardhuru
- 16th June 2011, 18:01
By switching off you mean assigning it %00000000 or in my case %11111111 since it is a common cathode display?



For common cathodes, wouldnt you need to assign 0's to the segments to blank them?

ross246
- 16th June 2011, 18:55
Common cathode is common negative or ground so by assigning it 0's your making it negative so switching it on

EDIT: assigning the cathode itself negative :) which is connected to portb, by assigning the segments (portc) 0's yea that would blank them.

Ah by clearing portc which is connected to the segments i have solved the problem :) thanks so much guys

BobEdge
- 16th June 2011, 22:31
Hi Ross,

Glad you got it to work. Now you can move on to not displaying any leading zero's.
Very nice code by the way, much more efficient than what I came up with a few years back.

Regards
Bob...