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




Bookmarks