I have been trying to get interupts to work for a few days now. I kind of understand them but seem to have a sticking point somewhere. Maybe the "OPTION" register. Not sure. Been all over the net reading. This seems to be quite common. Anyway can someone help. I have been using PB PRO for a while but not for bidirectional RS-232.

I am simply trying to engage 6 relays based on commands. Then while not doing that continuosly send data back down to a PC. When serial command arrives, act on it. Below is my code.

Thanks. Scott.C.

'************************************************* ***************
'* Name : Antenna_ROTOR.BAS *
'* Date : 5/23/2011 *
'* Version : 1.0 *
'* Notes : PIC 16F873A *
'* : *
'************************************************* ***************
'* Notes : Pin Outs are as follows
'* ******
'* MCLR ******1 28*****
'* Position Sense ******2 27*****
'* ******3 26***** CTS (FUTURE)
'* ******4 25***** RTS (FUTURE)
'* ******5 24***** ANT 4
'* ******6 23***** ANT 3
'* ******7 22***** ANT 2
'* GND ******8 21***** ANT 1
'* CLK ******9 20***** +5VDC
'* *****10 19***** GND
'* *****11 18***** RS-232 RX
'* *****12 17***** RS-232 TX
'* *****13 16***** C-CW RELAY
'* *****14 15***** CW RELAY
'* ******
'* Notes : Interface between Alliance HD-73 rotor and PC Serial Port
'* : 2400 8, N, 1
'* : Provides constant rotor position, status feedback
'* : Responds to serial commands to move rotor CW or CCW via 2 relays
'*
'************************************************* ************************

DEFINE OSC 4 ' 4 MHz clock
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 20 ' Set sampling time in uS

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

TRISA = %000001 ' Set PORTA
TRISB = %01100000 ' Set PORTB
TRISC = %10000000 ' Set PORTC
INTCON = %10010000
PIE1 = %00100000
'**************** DEFINE VARIABLES ***************************************

relay VAR BYTE 'relay number storage variable
stat VAR BYTE 'relay status ON/OFF variable
POTADC VAR WORD 'ADC Result
RXBYTE var byte

'**************** PORT B Setup *******************************************

ANT4 VAR PORTB.3 'ANT4 Relay
ANT3 VAR PORTB.2 'ANT3 Relay
ANT2 VAR PORTB.1 'ANT2 Relay
ANT1 VAR PORTB.0 'ANT1 Relay

'**************** PORT C Setup *******************************************

CCW VAR PORTC.5 'CCW Relay
CW VAR PORTC.4 'CW Relay

'****************** PORT SETUP *******************************************

CW=0 ' CW Relay Off
CCW=0 ' CCw Relay Off
ANT1=0
ANT2=0
ANT3=0
ANT4=0
ADCON0=0 ' Set up ADCON1

'***************** Main Program ******************************************
on interrupt goto RECEIVE

LOOP:

TRANSMIT:
ADCIN 0, POTADC 'convert ADC value to a byte value:
HSEROUT [DEC POTADC,32] 'TX DATA on PORTC.6
PAUSE 50

GOTO loop

DISABLE
RECEIVE:
IF (RCSTA.2=1) THEN
HSERIN [RXBYTE]
else
HSERIN 500,TRANSMIT,[WAIT(254),relay,stat] 'serial data in on Portc.7
endif

IF relay = 1 THEN outr1 ' if relay#1 then goto relay#1 routine
IF relay = 2 THEN outr2 ' if relay#2 then goto relay#2 routine
IF relay = 3 THEN outr3 ' if relay#3 then goto relay#3 routine
IF relay = 4 THEN outr4 ' if relay#4 then goto relay#4 routine
IF relay = 5 THEN outr5 ' if relay#5 then goto relay#5 routine
IF relay = 6 THEN outr6 ' if relay#6 then goto relay#6 routine

RESUME
ENABLE

'***************** DRIVE RELAYS ******************************************
outr1:
IF stat = 1 THEN high1
LOW CW: GOTO LOOP
high1:
HIGH CW: GOTO loop ' Turn on CW Relay

outr2:
IF stat = 1 THEN high2
LOW CCW: GOTO loop
high2:
HIGH CCW: GOTO loop ' Turn on CCW Relay

outr3:
IF stat = 1 THEN
HIGH ANT1: LOW ANT2: LOW ANT3: LOW ANT4
GOTO loop ' Turn On Relay for Antenna 1
endif

outr4:
IF stat = 1 THEN
HIGH ANT2: LOW ANT1: LOW ANT3: LOW ANT4
GOTO loop ' Turn On Relay for Antenna 2
endif

outr5:
IF stat = 1 THEN
HIGH ANT3: LOW ANT1: LOW ANT2: LOW ANT4
GOTO loop ' Turn On Relay for Antenna 3
endif

outr6:
IF stat = 1 THEN
HIGH ANT4: LOW ANT1: LOW ANT2: LOW ANT3
GOTO loop ' Turn On Relay for Antenna 4
endif

END