There's some silly mistakes in there, the most obvious one being,
If PIE1.TMR2IE And PIR1.TMR2IF Then 'Is it a CCP1 interrupt
Which should be,
If PIE1.CCP1IE And PIR1.CCP1IF Then 'Is it a CCP1 interrupt
There's also zeroing timer 1 isn't a 16 bit write.
I've made some changes to fix these things and removed the UART code,
Code:
'18F4431 32MHz XTL REMOTE_SLAVE 164 3 020223 1600
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz XTL x4 =32mHz
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20
Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
TRISA = %11000000 '7=OSC, 6=OSC,
TRISB = %00000000
TRISC = %11110000 '6=1-slave4431_cs, 2=74HC164 CLK, 0=74HC164 DATA
TRISD = %00000000 '6=led, 7=led, 5=sync
TRISE = %00000000
Dim wordtemp As Word
Dim ms As Long
Dim cnt As Byte
Dim servocount As Byte
Dim i As Byte
Dim servoPos(9) As Word 'Byte 'integer 'BYTE is an INTEGER?
Enable High 'This is set for SERVOS
Enable Low 'This is set for GPS later
main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
OSCCON = %01110000 '& h70
'setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS
T2CON = %01001110 'pre=16 post=10
PR2 = 49 'This is timer 2 period register. I.E. reset after 50 clocks (0 to 49 = 50 counts)
PIE1.TMR2IE = 1 'timer 2 interrupts enable
T1CON = 0 'timer 1 stopped
For i = 0 To 8
servoPos(i) = i * 1000 + 8000 '1ms(8000) to 1.875(7/8ths - 15000)ms in 1/8th mS steps
Next i
INTCON.PEIE = 1
INTCON.GIE = 1
While 1 'loop forever because everything is done on interrupts
'adjust servo positions here
Wend
On High Interrupt
Save System
Break '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If PIE1.TMR2IE And PIR1.TMR2IF Then 'Is it a timer 2 interrupt
ms = ms + 1 'Yes, so increment ms variable
cnt = cnt + 1 'If cnt >= 20 Then 'start every 20mS
If cnt >= 20 Then 'start every 20mS
T1CON = 0 'stop timer 1
TMR1L = 0 'zero timer 1
TMR1H = 0 'zero timer 1
cnt = 0 'Reset count
CCP1CON = %00001000 ' & h8 'CCP1 pin low and high on match - will be first pulse
CCPR1L = 0x13 '& hd 'Start pulse in 0.25mS (2000 clock cycles)?
CCPR2H = 0x07 '& h7
PIE1.CCP1IE = 1 'enable CCP1 interrupts
PIR1.CCP1IF = 0 'ensure interrupt flag is clear
servocount = 0 'reset servoCount
LATC.0 = 1 'connected to data in of shift register will clock in a high when CCP1 goes high
T1CON = 1 'start timer 1
Endif
PIR1.TMR2IF = 0 '0 = no TMR2 To PR2 match occurred
Endif
If PIE1.CCP1IE And PIR1.CCP1IF Then 'Is it a CCP1 interrupt
LATC.0 = 0 'Yes, so clear the data in pin as the high has already been clocked in
If servocount = 9 Then 'have we done all servos?
PIE1.CCP1IE = 0 'yes so no more CCP1 interrupts
Endif
If CCP1CON = 0x08 Then '& h8 Then 'have we started the 4000 cycle pulse
CCP1CON = 0x09 '& h9 'yes so end the pulse after 0.5mS
wordtemp = CCPR1H * 256 + CCPR1L
wordtemp = wordtemp + 4000
CCPR1L = wordtemp And 255
CCPR1H = wordtemp / 256
Else
CCP1CON = 0x08 '& h8 'No so output the timed gap
wordtemp = CCPR1H * 256 + CCPR1L
wordtemp = wordtemp - 4000 + servoPos(servocount)
CCPR1L = wordtemp And 255
CCPR1H = wordtemp / 256
servocount = servocount + 1
Endif
PIR1.CCP1IF = 0
Endif
Resume
I've also removed the two lines that write to CCPR1 as this is not a 16 bit write. Nothing should ever write to CCPR1, don't know why they bothered to convert the Pic file and change a word variable into a byte - stupid.
Mike.