My complete code is here. Sadly I have now deleted the troublesome line and replaced it with two lines. I am using PBP 2.50 and PM
Code:
'-------------------------------------
' PBP BCM CODE 22/10/09 V.04 8mhz
'-------------------------------------
@ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
@ DEVICE PIC16F88,PROTECT_OFF
@ DEVICE PIC16F88,WDT_OFF
@ DEVICE PIC16F88,PWRT_ON
@ DEVICE PIC16F88,MCLR_ON
@ DEVICE PIC16F88,BOD_OFF
@ DEVICE PIC16F88,LVP_OFF
@ DEVICE PIC16F88,CPD_OFF
@ DEVICE PIC16F88,DEBUG_OFF
@ DEVICE PIC16F88,CCPMX_OFF
DEFINE OSC 8 'Set oscilator speed to 8mHz
OSCCON=%01111000 '8 Mhz
'DEFINE OSC 4 'Set oscilator speed to 4mHz
'OSCCON =%01100000 '4 Mhz
DEFINE HSER_BAUD 9600 'Set Baud rate to 9600bps
DEFINE HSER_BITS 9 'Set to 9 bit mode
DEFINE HSER_EVEN 1 'Set Even Parity
DEFINE HSER_CLROERR 1 'Clear overflow error automatically
ANSEL = 0 'ALL DIGITAL
CMCON = 7 'COMPARATORS OFF
INTCON = 0 'Disable interrupts
TRISB = %00000100 'SET PORTB RB2(RX) as input, others to OUTPUT
TRISA = %11111111 'SET PORTA AS INPUTS
'Variables
BCMDATA VAR BYTE[12] 'Define BCMAADATA as a byte array (12 Bytes)
Count1 VAR BYTE 'Define Count1 as a byte variable (Used in For/Next Loops)
CheckSum VAR BYTE 'Define CheckSum as a byte variable
Commloop: 'Start of Communications Loop
HSERIN [WAIT ($87)] 'Wait for Packet start Byte $87
HSERIN [STR BCMDATA\11] 'Receive 11 bytes into array BCMDATA
'Gosub CalcSum 'Gosub CalcSum to Calculate Checksum
Hserout [$87] 'Transmit Packet start Byte $87
HSEROUT [str BCMDATA\11] 'Transmit 11 bytes from array BCMDATA
HSERIN [WAIT ($AA)] 'Wait for Packet start Byte $AA
HSERIN [STR BCMDATA\11] 'Receive 11 bytes into array BCMDATA
'Gosub CalcSum 'Gosub CalcSum to Calculate Checksum
Hserout [$AA] 'Transmit Packet start Byte $AA
HSEROUT [str BCMDATA\11] 'Transmit 11 bytes from array BCMDATA
Pause 32 'Pause for 16ms
HSEROUT [$AA,$10,$00,$00,$00,$20,$40,$61,$10,$01,$00,$74] 'Transmit 12 bytes
pause 32 'Pause for 16ms
HSEROUT [$87,$40,$58,$15,$6E,$10,$01,$32,$2F,$2F,$04,$39] 'Transmit 12 bytes
pause 32 'Pause for 16ms
goto CommlooP 'Goto Loop
CalcSum: 'Calculate Packet CheckSum Routine
CheckSum = 0 'Clear CheckSum Variable
For Count1 = 0 to 10 'For Count1 = 0 to 10 (Start 11 byte loop)
CheckSum = CheckSum + BCMDATA[Count1] 'Add Bytes
Next Count1 'Repeat until 11 bytes added
CheckSum = NOT CheckSum 'Not CheckSum
CheckSum = CheckSum + 1 'Add 1 to CheckSum
BCMDATA[12] = CheckSum AND $7F 'AND result
Return 'Return
END
However i have just tried this.
Code:
HSERIN [WAIT($87), str BCMDATA\11] 'Receive 12 bytes into array DATAIN
And it compiles correctly, might have been me with a typo!!!!! Arrggh. I let you know. Thanks for the help so far. This program is just proof of concept at the moment I know the "gosub" is not called at the moment. I'm trying to get the hserin/out working first.
Anything with my configs or program that would stop a pickit2 icsp working I can't get that to work for love or money, but the chip works fine in a standalone programmer. I've checked the circuit and pickit2 voltages and it all looks fine. Just can't find device 99% of the time.
Bookmarks