Darrel's interrupts in a 7 segment display
I have a design with a 3 digit 7 segment multiplexed display that showed a certain value. The circuit and the code worked fine while the display was about the only thing the PIC had to do.
Now, I tried to use Darrel's "DT_INTS-14.bas" as I need a few other things done in the code as well.
The chip is a 16F887.
My observations; the display flickers a lot; changing the prescaler to 1:1 is still bad, but better than other settings. Pre-loading TMR1 with any value seems to have no effect.
What am I doing wrong?
ANSEL = 0
ANSELH = 0
CM1CON0.7 = 0
CM2CON0.7 = 0
TRISA = 0
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
N VAR BYTE
SEGDEF VAR BYTE
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _DISP, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = $1
; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
Main:
'********************
TMR1H = %11111111
TMR1L = %11110111
'********************
toggle stat_LED
pause 500
GOTO Main
'---[TMR1 - interrupt handler]--------------------------------------------------
DISP: N = 1
GOSUB BIN2SEG
PORTC = SEGDEF
PORTE = 6
PAUSE 3
N = 2
GOSUB BIN2SEG
PORTC = SEGDEF
PORTE = 5
PAUSE 3
N = 3
GOSUB BIN2SEG
PORTC = SEGDEF
PORTE = 3
PAUSE 3
@ INT_RETURN
BIN2SEG:LookUp n,[132,175,193,137,170,152,144,143,128,136,210,251],SEGDEF
Return
Worked! now, another (sub)problem
Wow, worked the first time, Darrel.
Now, if I want to bit bang (I've already commited the hardware UART to something else) a couple of parameter values over the serial port, where in the code you've shown would the line go?
I've been struggling with this, with no success; or is this normal when one is using TMR0?
Regards,
Anand
Re: Darrel's interrupts in a 7 segment display
Hi all,
I'm having trouble understanding something in this example code. Maybe someone can explain.
Code:
Main:
FOR Value = 0 TO 999
GOSUB SetDisp
PAUSE 500
NEXT Value
GOTO Main
'---[Set 7-seg patterns to WORD value]--------------------------------------
SetDisp:
FOR Idx = 2 to 0 STEP -1
Temp = Value DIG Idx
LookUp Temp,[132,175,193,137,170,152,144,143,128,136,210,251],Temp
SEGDEF(Idx) = Temp
NEXT Idx
RETURN
The biggest question is why is there 12 data points in the table? I am assuming that the actual numbers are because of the wiring of the digits with this specific LED as I can not figure out a segment pattern. After that, I fall down on why 12 instead of 8 unless it involves positioning the decimal point somehow. I wonder, if with the original wiring, this would be clearer to me. I would think that you would line up the segments in order with the port pins in order.
Thanks
Mark
Re: Darrel's interrupts in a 7 segment display
Another observation that this is a specific solution to the OP's issue is that can't be just cut-n-pasted without thinking it through:
Code:
PORTE = %111 ; turn off all digits to prevent ghosting
PORTC = SEGDEF(digitloop) ; put segment pattern to pin
PORTE = ~(DCD digitloop) ; turn on the digit
my application is common cathode and it uses a ULN2803 as a driver for the cathodes of the digits. If I hadn't looked at it and tried to understand it, I could have easily have turned on ALL BUT ONE of the displays instead of ONE AT A TIME. Mine is also, 8 digits, so it matters a bit more for the PIC pin. Not a complaint in any way, more of a way to close the loop for anyone looking at it later. BTW: very slick way to step through the digits. Learned something new today.
Mark
1 Attachment(s)
Re: Darrel's interrupts in a 7 segment display
Quote:
Originally Posted by
boroko
Hi all,
I'm having trouble understanding something in this example code. Maybe someone can explain.
Code:
Main:
FOR Value = 0 TO 999
GOSUB SetDisp
PAUSE 500
NEXT Value
GOTO Main
'---[Set 7-seg patterns to WORD value]--------------------------------------
SetDisp:
FOR Idx = 2 to 0 STEP -1
Temp = Value DIG Idx
LookUp Temp,[132,175,193,137,170,152,144,143,128,136,210,251],Temp
SEGDEF(Idx) = Temp
NEXT Idx
RETURN
The biggest question is why is there 12 data points in the table? I am assuming that the actual numbers are because of the wiring of the digits with this specific LED as I can not figure out a segment pattern. After that, I fall down on why 12 instead of 8 unless it involves positioning the decimal point somehow. I wonder, if with the original wiring, this would be clearer to me. I would think that you would line up the segments in order with the port pins in order.
Thanks
Mark
As I can not resist a challenge even if it is only an academic exercise to me.
------- GFEDCBA
0 132 10000100
1 175 10101111
2 193 11000001
3 137 10001001
4 170 10101010
5 152 10011000
6 144 10010000
7 143 10001111
8 128 10000000
9 136 10001000
F 210 11010010
- 251 11111011
Looking at the bit pattern for :-
0 the active segments are 0 and inactive 1 in a 0 the central cross bar is inactive therefore this is C
6 the only inactive segment is top right therefore this is E
5 the inactive segments are top right and bottom left so bottom left is D
9 confirms bottom left is D
3 top left and bottom left inactive so top left is A
2 top left and bottom right inactive so bottom right is G
7 top left centre bottom left and bottom inactive so bottom is B
which leaves F is the top segment giving this pattern
-F-
A E
-C-
D G
-B-
251 is the centre bar obviously used for - (minus)
210 converting the bit pattern gives F
Having decoded this pattern it makes no sense to me as the normal segment pattern is
Attachment 7412
Leaving the question why connect a 7 segment display in this no standard way?
Re: Darrel's interrupts in a 7 segment display
Well Actually Steve, The display's may have been wired that way in the schematic originally. Makes no difference. As far as the table is concerned, to generate all 16 hexidecimal characters the table would be 16 entries wide. in the past I have generated tables with all 16 entries as well as lower case "c,n o r". Thats 20. Ther is no standard way if you get my drift. It's completely up to the circuit designer.
1 Attachment(s)
Re: Darrel's interrupts in a 7 segment display
Quote:
Originally Posted by
Dave
Well Actually Steve, The display's may have been wired that way in the schematic originally. Makes no difference. As far as the table is concerned, to generate all 16 hexidecimal characters the table would be 16 entries wide. in the past I have generated tables with all 16 entries as well as lower case "c,n o r". Thats 20. Ther is no standard way if you get my drift. It's completely up to the circuit designer.
In my post I decoded the lookup table to work out the display pattern and the wiring. I intuitively did not like the resultant pattern and wondered why choose that pattern. Internet searches revealed a commonly followed trend of port.0-port.7 connected to a-g respectively.
From Wikipedia
Quote:
Attachment 7413
LED-based 7-segment display which cycles through the common glyphs of the ten decimal numerals and the six hexadecimal "letter digits" (A–F)
Hexadecimal digits can be displayed on seven-segment displays. A combination of uppercase and lowercase letters is used for A–F;[6] this is done to obtain a unique, unambiguous shape for each hexadecimal digit (otherwise, a capital D would look identical to an 0 and a capital B would look identical to an 8). Also the digit 6 must be displayed with the top bar lit to avoid ambiguity with the letter b.
Which implies that there are two ways to wire up a seven segment display one for g-a encoding and one for a-g encoding. But as you say no one has to follow these commonly used encodings, which do dictate the circuit to be used.
The inclusion of "-" and "F" in the encoding makes me think that the original code was probably for displaying temperatures. Also the codes are eight digits which includes the DP reinforcing the idea of a temperature display. I wonder if the original project was wired in the same way, that is assuming this is recycled code.
Can anyone see any advantage in this scheme?
-F-
A E
-C-
D G
-B-
I can not and surely the wiring will be like spaghetti.
Re: Darrel's interrupts in a 7 segment display
most obvious reason would be to make the easiest possible (construction wise ) homebrew pcb layout . ie reduce the need for a ds board or even just minimise via's
Re: Darrel's interrupts in a 7 segment display
Quote:
Originally Posted by
richard
most obvious reason would be to make the easiest possible (construction wise ) homebrew pcb layout . ie reduce the need for a ds board or even just minimise via's
Yes it just has me wondering as I can not see any obvious benefit. As I will never use these I am going to stop worrying about it.
Re: Darrel's interrupts in a 7 segment display
intriguing discussion, but you're right... a rabbit trail. Mine works, I'm moving on.
Mark