I have a system that uses a control protocol of 8 bytes where it has a start byte which is always $A0 and an End byte which is always $AF. The bytes in between are for control and the 8th one is the checksum (I am not worried about that.
I got my USART recieving the data fine byte by byte but cannot but them in separate variables in correct order or in an array with 8 values.
I wrote this code but it just stays dead.
I need the interrupts as the program has to use the bytes to control a camera after it receives the packet and maybe another may come to cancel the previous.
My Code:
'************************************************* *******
'* PELCO PROTOCOL RECEIVER TO RECEIVE 8 BYTES WHEN INTERRUPTED *
'* PACKETS ALAYS START WITH BYTE1 = $A0 AND BYTE7 = $AF *
'************************************************* ********
@ device hs_OSC, wdt_on, pwrt_on, protect_off
define osc 20
Include "modedefs.bas"
RCSTA = %10010000 'Enable the Usart receive function
SPBRG = 64 'Set to 4800 bps
INTCON = %11000000 'Enable Global & Periferal Interrups
PIE1.5=1 'enable receive interrupt flag
trisc.6=0
TRISC.7=1 'usart input pin
TRISA.0=0
test var porta.0 'Output pin to PC to test values received
counter var word 'Used in the keep-busy loop
BAUD CON 16390
PELCO VAR BYTE[8] 'Packet of data received from the input
BYTECOUNT VAR BYTE 'Counter to put each byte in it's correct position
BYTECOUNT=0
PELCO=0
'---------------------------------jump over your interrupt routines
goto main
'-----------------------------------------------------------------
on interrupt goto myroutine
'******************* interrupt routine *********************
disable
myroutine:
if PIR1.5=1 then
PELCO[BYTECOUNT]=RCREG
IF RCREG=$AF THEN
GOSUB SENDATA
PIR1.5=0
ELSE
BYTECOUNT=BYTECOUNT+1
GOTO MYROUTINE
ENDIF
ENDIF
resume
enable
'************************************************* **
main:
'****************** Loop to keep the PIC busy *************
if counter=5000 THEN 'just to keep the pic busy to make sure the
toggle portd.0 'Toggle LED connected to this pin.
counter=0 ' interrupts are working.
else
counter=counter+1
endif
goto main
end
'********** Send data to PC to check if correct ********
SENDATA:
serout2 test,BAUD,[HEX PELCO[0],HEX PELCO[1],HEX PELCO[2],HEX PELCO[3],HEX PELCO[4],HEX PELCO[5],10,13]
RETURN
'***********************************************
Bookmarks