Code:
INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
#CONFIG
__config _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#ENDCONFIG
DEFINE OSC 20
ANSELA = 0 'DISABLE ANALOG
TRISA.1 = 1 'RX PIN AS INPUT
ADCON1 = 7
TXSTA.4 = 0 'SYNC BIT OFF
RCSTA.7 = 1 'SPEN BIT ON
RCSTA.4 = 1 'CREN BIT ON
PIE1.5 = 1 'RCIE BIT ON
INTCON.6 = 1 'PEIE BIT ON
INTCON.7 = 1 'GIE BIT ON
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _doEncoder, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT_INT
avg var word
UP var PORTC.0
TRISC.0 = 0
UP = 0
DOWN var PORTC.1
TRISC.1 = 0
DOWN = 0
WEST var PORTC.2
TRISC.2 = 0
WEST = 0
EAST var PORTC.7
TRISC.7 = 0
EAST = 0
RX var PORTC.5
TRISB.6 = 1
TX var PORTC.4
TRISB.5 = 0
azLIMIT var PORTC.6
TRISC.6 = 1
LED var PORTB.7
TRISB.7 = 0
LED = 1
newpos var word
oldpos var word
distance var word
Eencoder0Pos var word
Aencoder0Pos var word
Enewposition var word
Eoldposition var word
elHOMEpos var word
elSTOWpos var word
Anewposition var word
Aoldposition var word
azPOS var word
azSTOWpos var word
azHOMEpos var word
cereal var word
apple var word
apple = 0
stowed var word
stowed = 0
wsave var byte $70 SYSTEM
wsave1 var byte $A0 SYSTEM
wsave2 VAR BYTE $120 SYSTEM
wsave3 VAR BYTE $1A0 SYSTEM
HEL var byte
HAZ var byte
b0 var byte
i var byte
el_UP var byte
el_UP = 0
el_DN var byte
el_DN = 0
az_EAST var byte
az_EAST = 0
az_WEST var byte
az_WEST = 0
goto MainMenu
disable
doEncoder:
if el_UP = 1 then Eencoder0Pos = Eencoder0Pos + 1
iF el_DN = 1 THEN Eencoder0Pos = Eencoder0Pos - 1
IF az_WEST = 1 THEN Aencoder0Pos = Aencoder0Pos + 1
IF az_EAST = 1 THEN Aencoder0Pos = Aencoder0Pos - 1
@ INT_RETURN
allSTOP:
GOSUB POS
WEST = 0
EAST = 0
UP = 0
DOWN = 0
el_UP = 0
el_DN = 0
az_EAST = 0
az_WEST = 0
pause 2000
return
CLR:
For i = 0 to 30
hserout [10]
next i
return
TEST1:
Eencoder0Pos = 0
avg = 0
testloop:
gosub POS
el_UP = 1
UP = 1
for i = 1 to 30
pause 250
oldpos = newpos
newpos = Eencoder0POS
if oldpos > newpos then distance = oldpos - newpos
if newpos > oldpos then distance = newpos - oldpos
avg = avg + distance
hserout ["Distance Travelled: ", #distance, 13, 10]
next i
gosub allSTOP
avg = avg/30
pause 1500
hserout ["Test Complete. 1/4 Second Average was: ", #avg, 13, 10]
pause 5000
goto MainMenu
Startup:
pause 2000
gosub CLR
hserout ["Running Startup Procedures!", 13, 10]
hserout ["PLEASE WAIT....", 13, 10]
pause 3000
Eencoder0Pos = 0
hserout [10, 10, "Eencoder0Pos Before is: ", #Eencoder0Pos, 13, 10]
pause 2000
Eoldposition = Eencoder0Pos
DOWN = 1
el_DN = 1
pause 1000
gosub allSTOP
hserout [10, "Eencoder0Pos After is: ", #Eencoder0Pos, 13, 10]
pause 2000
Enewposition = Eencoder0Pos
hserout [10, "Eoldposition is: ", #Eoldposition, 13, 10]
hserout [10, "Enewposition is: ", #Enewposition, 13, 10]
pause 2000
IF Eoldposition = Enewposition THEN
stowed = 1
apple = 1
pause 5000
gosub CLR
hserout ["Startup Sequence Good!", 13, 10]
hserout ["Continuing to Main Menu...", 13, 10]
pause 3500
goto MainMenu
ENDIF
IF Enewposition <> Eoldposition THEN
stowed = 0
apple = 0
UP = 1
el_UP = 1
pause 1000
gosub allSTOP
gosub CLR
hserout ["Startup Error!", 13, 10]
hserout ["Dish will need homing before move will be allowed!", 13, 10]
hserout ["Continuing to Main Menu...", 13, 10]
pause 5000
goto Mainmenu
ENDIF
MainMenu:
gosub CLR
hserout ["******** MAIN MENU ********", 13, 10, 10]
hserout [" 1. Start Homing Sequence", 13, 10]
hserout [" 2. Manual JOG Mode", 13, 10]
hserout [" 3. Auto-Acquire Satellite", 13, 10]
hserout [" 4. Stow Dish for Travel", 13, 10, 10]
hserout ["Enter Your Selection:"]
hserin [b0]
If b0 = "1" then goto HomeDish
If b0 = "2" then goto JogMenu
If b0 = "3" then goto TEST1
If b0 = "4" then goto Startup
goto MainMenu
HomeDish:
gosub CLR
hserout ["******** HOME DISH ********", 13, 10, 10]
hserout [" 1. Start Homing Sequence", 13, 10, 10]
hserout [" 2 Abort Homing", 13, 10, 10]
hserout ["Enter Your Selection:"]
hserin [b0]
if b0 = "2" then goto MainMenu
homeloop:
IF b0 = "1" THEN
gosub HomeEL
'gosub HomeAZ
HAZ = 1
IF (HEL = 1) AND (HAZ = 1) THEN
gosub clr
hserout ["HOME PROCESS WAS SUCCESSFUL!", 13, 10]
goto MainMenu
ENDIF
IF (HEL = 0) OR (HAZ = 0 ) THEN
gosub clr
hserout ["DIS HOME PROCESS CAN SUCK MY DICK!", 13, 10]
goto MainMenu
ENDIF
ENDIF
pause(200)
goto homeloop
goto HomeDish
HomeAZ:
gosub clr
hserout ["HOMING AZIMUTH - PLEASE WAIT..", 13, 10]
PAUSE(500)
Aencoder0Pos = 0
oldpos = 0
WEST = 1
az_WEST = 1
PAUSE(250)
IF Aencoder0Pos = 0 THEN
gosub allSTOP
EAST = 1
az_EAST = 1
PAUSE(250)
gosub allSTOP
PAUSE(500)
Aencoder0Pos = 0
WEST = 1
az_WEST = 1
PAUSE(500)
IF Aencoder0Pos = 0 THEN goto moveerror
ENDIF
pause 1000
loop4:
pause 250
oldpos = newpos
newpos = Aencoder0POS
if oldpos > newpos then distance = oldpos - newpos
if newpos > oldpos then distance = newpos - oldpos
if distance < 100 then
gosub allSTOP
Aencoder0Pos = 65000
hserout ["HOMING AZIMUTH WAS SUCCESSFUL!", 13, 10]
HAZ = 1
endif
goto loop4
az_EAST = 1
EAST = 1
loop8:
pause 100
if Aencoder0Pos > 0 then goto loop8
return
HomeEL:
gosub clr
hserout ["HOMING ELEVATION - PLEASE WAIT..", 13, 10]
PAUSE(500)
Eencoder0Pos = 0
el_UP = 1
UP = 1
PAUSE(250)
IF Eencoder0Pos = 0 THEN
gosub allSTOP
DOWN = 1
el_DN = 1
PAUSE(250)
gosub allSTOP
PAUSE(500)
Eencoder0Pos = 0
UP = 1
el_UP = 1
PAUSE(500)
IF Eencoder0Pos = 0 THEN goto moveerror
ENDIF
pause 1000
oldpos = Eencoder0Pos
loop3:
pause 250
newpos = Eencoder0POS
hserout ["oldpos = ", #oldpos, 13, 10]
hserout ["newpos = ", #newpos, 13, 10]
if oldpos > newpos then distance = oldpos - newpos
if newpos > oldpos then distance = newpos - oldpos
if oldpos = newpos then distance = 0
hserout ["distance = ", #distance, 13, 10]
oldpos = newpos
if distance < 1 then
gosub allSTOP
Eencoder0Pos = 3000
HAZ = 1
hserout ["HOMING ELEVATION WAS SUCCESSFUL!", 13, 10]
goto safe_el
endif
goto loop3
safe_el:
el_DN = 1
DOWN = 1
loop9:
pause 100
gosub pos
if Eencoder0Pos > 1500 then goto loop9
return
JogMenu:
gosub CLR
pause 250
hserout ["***** JOG MENU *****", 13, 10, 10]
hserout ["U - UP", 13, 10]
hserout ["D - DOWN", 13, 10]
hserout ["E - EAST", 13, 10]
hserout ["W - WEST", 13, 10]
hserout ["S - ALL STOP", 13, 10]
hSEROUT ["X - MAIN MENU", 13, 10, 10]
hserin [b0]
if b0 = "U" Then
gosub allSTOP
HIGH UP
el_UP = 1
endif
if b0 = "D" then
gosub allSTOP
HIGH DOWN
el_DN = 1
endif
if b0 = "E" then
gosub allSTOP
high EAST
az_EAST = 1
endif
if b0 = "W" then
gosub allSTOP
HIGH WEST
az_WEST = 1
endif
if b0 = "S" then gosub allSTOP
if b0 = "X" then
gosub allSTOP
goto MainMenu
endif
goto JOGMenu
ACQUIRE:
goto MainMenu
STOW:
goto MainMenu
abort:
gosub allSTOP
gosub clr
hserout ["USER STOP! -- MOVE ABORTED!", 13, 10]
PAUSE(5000)
goto MainMenu
moveerror:
gosub allSTOP
gosub clr
hserout ["SYSTEM ERROR! -- MOVE ABORTED!", 13, 10]
PAUSE(5000)
goto MainMenu
POS:
pause 100
hserout [" EL -- ", #Eencoder0Pos, " AZ -- ", #Aencoder0Pos, 13, 10]
return
Bookmarks