OK! I have gotten most of what I needed to work, I think.... I am having a few snags though really close to the end. This is a self acquire satellite dish. (I still need to write the code for aiming, but that's just a "where am i, count and move"... should be easy enough) I finally have the homing sequence down. I went down a rabbit hole not realizing where the azimuth limit switch was. Once I found it, it shortened my process immensely. However, now that I'm trying to test the new homing code and write the stow code, I am having a couple issues.

1. My external interrupt is not interrupting. This goes to the encoders on the dish and is receiving 5v+ pulses when the dish moves in any direction. I am verifying this with a scope. But PIC doesn't recognize and gives me Move Error. (Which it should cuz I want it to stop if it can't see where it's going)

2. My serial connection is losing characters. Every line is missing random characters. I would say 5% - 15% lost on average.

3. They way I have it set up now is to wait on the serin command for an input. I am using a terminal at the moment, but I am going to have a handheld device with 4 buttons and a LCD, as well as the ability to connect with it from a smartphone app. The handheld will have it's own MC, but since i want to have different style user implements, all the 'intelligent stuff' has to be done on this one on the unit itself. My question is, can anyone help me figure out a decent way to implement these different interfaces simultaneously? I was kicking around an idea of using an interrupt for serial and have all commands live at the same time since I easily have 72 single char I can send without complicating it further. But if I do it that way, I'll have to code in so many safeties so users dont do stuff in the wrong order..... ya I'm kinda stumped. lol

4. I only started working with MC's about two months ago, so I was also wondering if anything jumps out at anyone about something I could do more easily, or make this more reliable.

'************************************************* ***************
'* Name : Galaxy Main
'* Author : John Moore
'* Notice : Copyright (c) 2010
'* : All Rights Reserved
'* Date : May 4, 2014
'* Version : 1.2
'* Notes :
'* :
'************************************************* ***************


INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_TICKS.bas"
include "modedefs.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


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
INT_Handler INT_INT, _doEncoder, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM


@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
@ INT_ENABLE INT_INT


GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer


ADCON1 = 7
INTCON = %11111000
UP var PORTC.0
TRISC.0 = 0
low up
DOWN var PORTC.1
TRISC.1 = 0
low down
WEST var PORTC.2
TRISC.2 = 0
low west
EAST var PORTC.7
TRISC.7 = 0
low east
RX var PORTB.6
TRISB.6 = 1
TX var PORTB.5
TRISB.5 = 0
azLIMIT var PORTC.6
TRISC.6 = 1




newtime var word
oldtime var word
Sencoder0Pos var word
Eencoder0Pos var word
Aencoder0Pos var word
Enewposition var word
Eoldposition var word
Enewvel var word
Eoldvel var word
elPOS var word
elHOMEpos var word
elSTOWpos var word
Anewposition var word
Aoldposition var word
Anewvel var word
Aoldvel var word
azPOS var word
azSTOWpos var word
azHOMEpos var word
cereal var word
bugprint var word
apple var word
apple = 0
stowed var word
stowed = 0
slow var word
wsave var byte $70 SYSTEM
wsave1 var byte $A0 SYSTEM
wsave2 VAR BYTE $120 SYSTEM
wsave3 VAR BYTE $1A0 SYSTEM
velocity var word[10]
vnt var word
cnt var byte
HEL var byte
HAZ var byte
b0 var byte
i var byte


goto MainMenu


Disable
doEncoder:
IF up = 1 THEN Eencoder0Pos = Eencoder0Pos + 1
IF down = 1 THEN Eencoder0Pos = Eencoder0Pos - 1
IF west = 1 THEN Aencoder0Pos = Aencoder0Pos + 1
IF east = 1 THEN Aencoder0Pos = Aencoder0Pos - 1
@ INT_RETURN


CLR:
For i = 0 to 30
serout TX, 2, [10]
next i
return


Startup:
pause 5000
'gosub CLR
serout tx, 2, ["Running Startup Procedures!", 13, 10]
serout tx, 2, ["PLEASE WAIT....", 13, 10]
pause 250
Eencoder0Pos = 15491
serout TX, 2, ["Eencoder0Pos Before is: ", #Eencoder0Pos, 13, 10]
Eoldposition = Eencoder0Pos
high down
pause 1000
gosub allSTOP
serout TX, 2, ["Eencoder0Pos After is: ", #Eencoder0Pos, 13, 10]
Enewposition = Eencoder0Pos
serout TX, 2, ["Eoldposition is: ", #Eoldposition, 13, 10]
serout TX, 2, ["Enewposition is: ", #Enewposition, 13, 10]
IF Eoldposition = Enewposition THEN
stowed = 1
apple = 1
'gosub CLR
serout TX, 2, ["Startup Sequence Good!", 13, 10]
serout TX, 2, ["Continuing to Main Menu...", 13, 10]
goto MainMenu
ENDIF
IF Enewposition < Eoldposition THEN
stowed = 0
apple = 0
high up
pause 1000
gosub allSTOP
gosub CLR
pause 100
serout TX, T9600, ["Startup Error!", 13, 10]
pause 100
serout TX, T9600, ["Dish will need homing before move will be allowed!", 13, 10]
pause 100
serout TX, T9600, ["Continuing to Main Menu...", 13, 10]
pause 5000
goto Mainmenu
ENDIF


MainMenu:
gosub CLR
pause 200
serout TX, T9600, ["******** MAIN MENU ********", 13, 10, 10]
pause 200
serout TX, T9600, [" 1. Start Homing Sequence", 13, 10]
pause 200
serout TX, T9600, [" 2. Manual JOG Mode", 13, 10]
pause 200
serout TX, T9600, [" 3. Auto-Acquire Satellite", 13, 10]
pause 200
serout TX, T9600, [" 4. Stow Dish for Travel", 13, 10, 10]
pause 200
serout TX, T9600, ["Enter Your Selection:"]
pause 500
Serin RX, T9600, b0
If b0 = "1" then goto HomeDish
If b0 = "2" then goto JogMenu
If b0 = "3" then goto ACQUIRE
If b0 = "4" then goto Startup
goto MainMenu


HomeDish:
gosub CLR
serout TX, T9600, ["******** HOME DISH ********", 13, 10, 10]
serout TX, T9600, [" 1. Start Homing Sequence", 13, 10, 10]
serout TX, T9600, [" 2 Abort Homing", 13, 10, 10]
serout TX, T9600, ["Enter Your Selection:"]
Serin RX, T9600, 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
serout TX, T9600, ["HOME PROCESS WAS SUCCESSFUL!", 13, 10]
goto MainMenu
ENDIF
IF (HEL = 0) OR (HAZ = 0 ) THEN
gosub clr
serout TX, T9600, ["DIS HOME PROCESS CAN SUCK MY DICK!", 13, 10]
goto MainMenu
ENDIF
ENDIF
pause(200)
goto homeloop
goto HomeDish


HomeAZ:
gosub clr
serout TX, T9600, ["HOMING AZIMUTH - PLEASE WAIT..", 13, 10]
PAUSE(500)
Aencoder0Pos = 0
HIGH WEST
PAUSE(250)
IF Aencoder0Pos = 0 THEN
gosub allSTOP
high EAST
PAUSE(250)
gosub allSTOP
PAUSE(500)
Aencoder0Pos = 0
high WEST
PAUSE(500)
IF Aencoder0Pos = 0 THEN goto moveerror
ENDIF


loop4:
if azLIMIT = 0 then
loop5:
pause 100
if azLIMIT = 0 then goto loop5
if azLIMIT = 1 then
gosub allSTOP
Aencoder0Pos = 0
high EAST
pause 3000
gosub allSTOP
HAZ = 1
return
endif
endif
if azLIMIT = 1 then
low WEST
high EAST
loop6
pause 100
if azLIMIT = 1 then goto loop6
if azLIMIT = 0 then
pause 3000
low EAST
high WEST
goto loop4
endif
endif



HomeEL:
gosub clr
serout TX, T9600, ["HOMING ELEVATION - PLEASE WAIT..", 13, 10]
PAUSE(500)
Eencoder0Pos = 0
HIGH up
PAUSE(250)
IF Eencoder0Pos = 0 THEN
gosub allSTOP
high down
PAUSE(250)
gosub allSTOP
PAUSE(500)
Eencoder0Pos = 0
high up
PAUSE(500)
IF Eencoder0Pos = 0 THEN goto moveerror
ENDIF
loop3:
pause 250
Eoldposition = Enewposition
Enewposition = Eencoder0Pos
IF Enewposition > Eoldposition THEN goto loop3
if Eoldposition = Enewposition then
gosub allSTOP
elPOS = 0
Eencoder0Pos = 3665
pause(500)
high down
pause(5000)
GOSUB allSTOP
gosub clr
serout TX, T9600, ["HOMING ELEVATION WAS SUCCESSFUL!", 13, 10]
HEL = 1
return
ENDIF
goto loop3


JogMenu:
gosub CLR
high TX
serout TX, T9600, ["***** JOG MENU *****", 13, 10, 10]
serout TX, T9600, ["U - UP", 13, 10]
serout TX, T9600, ["D - DOWN", 13, 10]
serout TX, T9600, ["E - EAST", 13, 10]
serout TX, T9600, ["W - WEST", 13, 10]
serout TX, T9600, ["S - ALL STOP", 13, 10]
SEROUT TX, T9600, ["X - MAIN MENU", 13, 10, 10]
serin RX, T9600, b0
if b0 = "U" Then
gosub allSTOP
high up
endif
if b0 = "D" then
gosub allSTOP
high down
endif
if b0 = "E" then
gosub allSTOP
high east
endif
if b0 = "W" then
gosub allSTOP
high west
endif
if b0 = "S" then gosub allSTOP
if b0 = "X" then goto MainMenu
goto JOGMenu


ACQUIRE:
GOSUB CLR
SEROUT TX, T9600, [" AUTO-ACQUIRE ", 13, 10]
SEROUT TX, T9600, ["NOT YET ASSHOLE!", 13, 10]
goto MainMenu


STOW:
GOSUB CLR
SEROUT TX, T9600, [" AUTO-STOW DISH", 13, 10]
SEROUT TX, T9600, ["NOT YET ASSHOLE!", 13, 10]
goto MainMenu


allSTOP:
low up
low down
low east
low west
return


abort:
gosub allSTOP
gosub clr
serout TX, T9600, ["USER STOP! -- MOVE ABORTED!", 13, 10]
PAUSE(5000)
goto MainMenu


moveerror:
gosub allSTOP
gosub clr
serout TX, T9600, ["SYSTEM ERROR! -- MOVE ABORTED!", 13, 10]
PAUSE(5000)
goto MainMenu


POS:
pause 100
serout TX, 0, ["EL -- ", #Eencoder0Pos, " ", "AZ -- ", #Aencoder0Pos, 13, 10]
PAUSE 100
return