Symbol mskTmrAndSer = %10100000
Symbol flgTmrAndSer = %10100000
Symbol False = 0
Symbol True = 1
Symbol tmrIntOn1stTick = 65535 'Interrupt to be caused by roll over on first major tick
Symbol tmr50mS_8 = 63974 'SetTimer value for 50mS second ticks @8MHz
Symbol tmr50mS_16 = 62411 'SetTimer value for 50mS second ticks @16MHz
Symbol tmr50mS_32 = 59286 'SetTimer value for 50mS second ticks @32MHz
'
'TaskID Values
Symbol tsk1_CL = 1
Symbol tsk1_ETP1 = 2
Symbol tsk1_TT1 = 3
Symbol tsk1_SF1 = 4
Symbol tsk1_DR1 = 5
Symbol tsk1_DR2 = 6
Symbol tsk1_DR3 = 7
Symbol tsk1_SF2 = 8
Symbol tsk1_ETP2 = 9
Symbol tsk1_TT_Graph = 10
Symbol tsk1_ETP3 = 11
Symbol tsk1_TTV2 = 12
Symbol tsk1_ETP4 = 13
Symbol tsk1_TTV3 = 14
Symbol tsk1_RPNXYC = 15
'
'Symbol tsk2_??? = 20
'
'Variables
Symbol tTaskTimerOn = bit0
Symbol tDoTask = bit1
Symbol bTaskID = b4
Symbol bSerialRec = b5 'Received serial byte/character
'
'ScratchPad
Symbol sSerInBuffStart = 0
Symbol mskSerInRange = %00111111 'Bytes 0-63 in Scratchpad
'
'Compilation Directives
#PICAXE 28X2
#No_Data
#No_Table
'
'Executable Code: Initialisation
SetFreq m8
'
'Initialise serial link for
hSerSetup B9600_8, %00001 '9600 baud @ 32MHz, Background, no invertion
' %abcde where, for X2 chips:
' Bit e (bit 0): Foregrd/Backgrd mode e=0 foreground; e=1*background
' Bit d (bit 1): Transmit mode - d=0*No invert; d=1 Invert transmit polarity
' Bit c (bit 2): Receive mode - c=0*No invert; c=1 Invert receive polarity
' Bit b (bit 3): disable hserout b=0 enable; b=1 disable
' Bit a (bit 4): disable hserin a=0 enable; a=1 disable
'
Ptr = sSerInBuffStart 'Ptr is used for reading received background serial data
hSerPtr = sSerInBuffStart 'hSerPtr is updated by the background serial firmware
'
'Start the background timer (runs continuously)
Timer = tmrIntOn1stTick
SetTimer tmr50mS_8 'Expires after 50mS at 8 MHz
Flags = 0 'Reset serial reception flag
SetIntFlags Or flgTmrAndSer, mskTmrAndSer 'Set timer 0 or hSerial to interrupt
bTaskID = 0 'Initialise for seqence previously in Interrupt routine
tTaskTimerOn = False
Do
If tTaskTimerOn = True Then
Select Case bTaskID
Case tsk1_CL
hSerOut 0, ("CL")
tDoTask = False
Case tsk1_ETP1
hSerOut 0, ("ETP", 25, 200)
tDoTask = False
Case tsk1_TT1
hSerOut 0, ("TT", "Menu", 0)
tDoTask = False
Case tsk1_SF1
hSerOut 0, ("SF", 51)
tDoTask = False
Case tsk1_DR1
hSerOut 0, ("DR", 10, 2, 90, 40)
tDoTask = False
Case tsk1_DR2
hSerOut 0, ("DR", 120, 2, 200, 40)
tDoTask = False
Case tsk1_DR3
hSerOut 0, ("DR", 230, 2, 255, 55, 40)
tDoTask = False
Case tsk1_SF2
hSerOut 0, ("SF", 18)
tDoTask = False
Case tsk1_ETP2
hSerOut 0, ("ETP", 25, 30)
tDoTask = False
Case tsk1_TT_Graph
hSerOut 0, ("TT", "Graph", 0)
tDoTask = False
Case tsk1_ETP3
hSerOut 0, ("ETP", 135, 30)
tDoTask = False
Case tsk1_TTV2
hSerOut 0, ("TT", "Vak 2", 0)
tDoTask = False
Case tsk1_ETP4
hSerOut 0, ("ETP", 245, 30)
tDoTask = False
Case tsk1_TTV3
hSerOut 0, ("TT", "Vak 3", 0)
tDoTask = False
Case tsk1_RPNXYC 'Last action for Task sequence 1 "tsk1_???"
hSerOut 0, ("RPNXYC")
tDoTask = False
tTaskTimerOn = False 'Disable task stepping in the interrupt routine
End Select
End If
If pinc.0 = 1 then
tTaskTimerOn = True
EndIf
If Ptr <> hSerPtr Then
' bSerialRec = @PtrInc And mskSerInRange 'Fetch character/byte from Scratchpad -Edited-
bSerialRec = @PtrInc 'Fetch character/byte from Scratchpad -Edited-
Ptr = Ptr And mskSerInRange 'Manage the Scratchpad pointer -Edited-
SerTxd (bSerialRec) 'Send it to the PE terminal
EndIf
Loop
'
'
' ************************************************************
' Interrupt handler
' ************************************************************
'
Interrupt:If hSerInFlag = True then 'Restrict pointer to 0-63 (Must appear
hSerInPtr = hSerInPtr And mskSerInRange ' first in the interrupt routine)
hSerInFlag = False
EndIf
If TOFlag = True then 'All timer ticks
TOFlag = False 'Reset (clear) the flag first
If tTaskTimerOn = True Then
Inc bTaskID
tDoTask = True
EndIf
Timer = tmrIntOn1stTick 'Then reset the timer
EndIf 'Timer has ticked
SetIntFlags Or flgTmrAndSer, mskTmrAndSer 'Set timer 0 or hSerial to interrupt
Return
' ************************************************************