Can we have the code please
Hi,
It is very unlikely that DT's int handler mess with your CCP2CON register. Do you have a LCD / Serial / Debug out then try dumping the CCP2COn values periodically to know whats going on.
A look at the code may be helpful. I have 18F4520 ready with me and would like to duplicate the problem for my own interest.
Temp variables exceeding T7
Hi Darrel, sorry my english.
I need help for this message:
Message[301] c:\..........asm 3074:MESSAGE:(Temp variables exceeding T7)
Tks.
DT_INTS breaks pulsein/count PBP routines?
Is this true? I can believe it to be. If so, is there any way I can replace this functionality using the interrupt driven counters or something? A hardware counter is not an option unfortunately, as the board is already in units in the field.
The reason I need to add interrupts is because I need to add background hardware UART character reception using UART2 because the program spends too much time doing other things in the foreground to service the port soon enough.
Is there a list of what PBP functions are affected by DT_INTS? If so where can I find it?
Does anyone have examples of interrupt driven serial IO using DT_INTS? How about pulse counting routines?
Thanks,
Mike
7 seg display with rs232 data input
I was testing with darrel Taylor Instant interrups. The colaboration is fantastic. Great.
I mount four 7 seg, 4 inches each, with common anode, and the 16f877A. The input for data is the serial input, across portc.7. I probe fist without darrel tool, using on interrupts and I see that the serial input line stop de scan for the 7 segs, because the multiplexing loss the times in this waiting for the data. Each display is activate with portd.4 to portd.7
The circuit work fine, so, the program need tuning up.
When I used the Darrel tool, the time for the 7 segs scan don't change with the data wait in the serian in line, including this part in the main loop. The scan for the multiplexing is in instant interrup routine. My dude, in this case, is with time multiplexing scan. I not Know what is the lines for the scan, and in this moment, i only see the scan very slow.
I need help for to put the timer a time for correct and fast scan.
Thanks.
Luis Elizarraraz
Slow scan for 7 seg multiplexing
Thanks for answer me Darrel.
The code for my application is the follow:
'-------------------------------------------------------------------------------------
'
'Start
INCLUDE "MODEDEFS.BAS"
define loader_used 1
DEFINE OSC 20 ' Define crystal as 4Mhz
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
' ** Declare the Variables **
LEDS Var Byte ' The amount of LEDs in the display
O_C Var Byte ' Used by the interrupt for time sharing
Counter Var byte ' General purpose counter
Del Var Word ' General purpose delay loop variable
del1 var word
D_Number Var word ' The number to display on the LEDS
DP Var Byte ' Position of the decimal point
Disp_Patt Var Byte ' Pattern to output to PortC
Num Var Byte[4] ' Array to hold each digits value
Digit1 var Portd.4 ' 1ro
Digit0 Var Portd.5 ' 2do
Digit3 Var Portd.6 ' 3ro
Digit2 Var Portd.7 ' 4to
' ** THE MAIN PROGRAM STARTS HERE **
trisd=%00001111 'portd.4 a portd.7 like output
TrisB=0 ' Make PortB and PortC outputs
PortC=0:PortB=0 ' Clear PortB and PortC
O_C=0 ' Clear the time share variable
TRISB=0
x var byte
y var byte
duty var byte
canal var byte
d var word
v1 VAR word
V2 VAR word
ciclo var word
indi var bit
conta var byte
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _Multi, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON=$01 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
d=0
ciclo=0
indi=0
high portd.7
high portd.6
high portd.5
high portd.4
Main:
serout2 portc.6,84,[13,"C>"]
serin2 portc.7,84,3000,main,[dec4 D_Number]
serout2 portc.6,84,["L"]
Gosub Display ' Display the value
goto main
Display:
For LEDS=3 to 0 step -1 ' Loop for 4 digits (0-65535) ' Disable the interrupt while we calculate
Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit
If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
If D_Number<1000 and LEDS=3 then Num[LEDS]=10 ' Zero Suppression for the Third digit ' Re-enable the interrupt
Next
return
' INTERRUPT HANDLER
' Multiplexes the 3-digits
'
Disable ' Disable all interupts during the interrupt handler
Multi:
'sigue: ' 0 1 2 3 4 5 6 7 8 9 A B C E F G H I J L N 0 U b c d e f g h i n p q s o u
lookup Num[O_C],[63,6,91,79,102,109,125,39,127,111,119,127,57,121,1 13,125,118,6,30,56,55,63,62,124,88,94,123,113,111, 116,4,84,115,103,109,92,28],Disp_Patt
' Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt ' Decode the segments for the LED
' Process the first display (farthest right)
If O_C=0 then ' If it is our turn then
Digit3=1 ' Turn OFF the 3er LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=1 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit0=0 ' Turn ON the first LED
Endif
' Process the second display
If O_C=1 then ' If it is our turn then
Digit0=1 ' Turn OFF the first LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=2 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit1=0 ' Turn ON the second LED
Endif
' Process the third display
If O_C=2 then ' If it is our turn then
Digit1=1 ' Turn OFF the second LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=3 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit2=0 ' Turn ON the third LED
Endif
' Process the 4th display
If O_C=3 then ' If it is our turn then
Digit2=1 ' Turn OFF the second LED
PortB=Disp_Patt ' Place the digit pattern on portC
If DP=4 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
Digit3=0 ' Turn ON the third LED
Endif
O_C=O_C+1 ' Increment the time share counter
If O_C>=4 then O_C=0 ' If it reaches 3 or over then clear it
@ INT_RETURN ' Allow more interrupts
what's the way for more speed?
Darrel, thanks. before your instant interrups tools never I was experimenting interrupts.
I have clear idea the hserin/hserout sustitution, but I ignored what's the procedure (concretly) for incress the speed.
I havew the display working now, but I need to find de solution for the slow scan.
The question is How incress the speed with the preescaler 1:1 now?
what's the value for load?
Thanks and regards
Luis Elizarraraz
Display four 7 sgments with rs232 input
Darrel:
Thanks for the solution!
For finish this project, I'm going to show the final version for the code.
Recapitulation:
Hardware:
Four 7 segments modules conected to the portb, like driver using uln2803.
Each module is conected to the anode with 2 transistors: bc337 directed to portd (portd.4 to portd.7 for each module) and from the bc337 colector to the irf640 gate.
For the communication, max232 connected to the pc (data inputs) and the ttl side, to the portc.6 and portc.7 (tx and rx).
I send to the pc the characters "C>" like invitation for to introduce the data.
The data follow the format: "CXXXX" where XXXX is any number from 0000 to 9999.
When the circuit receive the data in the correct format, this send to the pc the character "L" (Listen).
The problems with the slow scan was solutioned with the Darrel Taylor instant interrups tools. I finded relative easy the first project using interrups..!Thanks and more thanks Darrel ¡
Finally, the code:
'-----------------------------------program picbasic pro /Darrel support-------------------
'
INCLUDE "MODEDEFS.BAS"
define loader_used 1
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 9600
'DEFINE HSER_SPBRG 25
DEFINE Freq 400
DEFINE Prescaler 1
Timer1 VAR WORD EXT
TmrLoad CON EXT
@Timer1 = TMR1L
@TmrLoad = 65536 - (OSC*1000000/4/Prescaler/Freq)
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
' ** Declare the Variables **
LEDS Var Byte ' The amount of LEDs in the display
O_C Var Byte ' Used by the interrupt for time sharing
Counter Var byte ' General purpose counter
Del Var Word ' General purpose delay loop variable
del1 var word
D_Number Var word ' The number to display on the LEDS
DP Var Byte ' Position of the decimal point
Disp_Patt Var Byte ' Pattern to output to PortC
Num Var Byte[4] ' Array to hold each digits value
TRISD=%00001111 'portd.4 a portd.7 como salidas
TrisB=0 ' Make PortB and PortC outputs
PortC=0:PortB=0 ' Clear PortB and PortC
O_C=0 ' Clear the time share variable
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _Multi, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON=$01 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
PORTD=%11110000
Main:
hserout [13,"C>"]
hserin [dec4 D_Number]
SIGUE:
hserout ["L"]
Gosub Display ' Display the value
goto main
Display:
For LEDS=3 to 0 step -1 ' Loop for 4 digits (0-65535) ' Disable the interrupt while we calculate
Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit
If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
If D_Number<1000 and LEDS=3 then Num[LEDS]=10 ' Zero Suppression for the Third digit ' Re-enable the interrupt
Next
return
' INTERRUPT HANDLER
' Multiplexes the 4-digits
'
Multi:
T1CON.0 = 0
Timer1 = Timer1 + TmrLoad
T1CON.0 = 1
'sigue: ' 0 1 2 3 4 5 6 7 8 9 A B C E F G H I J L N 0 U b c d e f g h i n p q s o u Z
lookup Num[O_C],[63,6,91,79,102,109,125,39,127,111,119,127,57,121,1 13,125,118,6,30,56,55,63,62,124,88,94,123,113,111, 116,4,84,115,103,109,92,28,255],Disp_Patt
' Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt ' Decode the segments for the LED
' Process the first display (farthest right)
If O_C=0 then portd=%11011111
If O_C=1 then portd=%11101111
If O_C=2 then portd=%01111111
If O_C=3 then portd=%10111111
PortB=Disp_Patt ' Place the digit pattern on portC
O_C=O_C+1 ' Increment the time share counter
If O_C>=4 then O_C=0 ' If it reaches 3 or over then clear it
@ INT_RETURN ' Allow more interrupts
'-----------------------end --------------------------------------------------------
The display is working very good.
Regards.