Hi ,
I met problem.
I send 0x0F for 200 times first, Then send core data.
But in RX XBEE, I didn’t receive 200 0x0F. Sometime 0F is received , sometimes it is not 0F but E8. Sometime the total number is 90, sometime it is around 140.
Who can help me?
What’s the probable reason? In Xbee?
Maybe 200 bytes is overflow in XBEE DI BUFFER?
PIC CODE
list p=16F877 ; list directive to define processor
#include <p16f877.inc> ; processor specific variable definitions
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC
; & _WRT_OFF & _LVP_OFF & _CPD_OFF
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
ByteCounter EQU 0x7C ;address used for byte counter
ByteCounter1 EQU 0x60
#define CTS PORTC,5 ;C5 is connected to XBEE CTS
;**********************************************************************
ORG 0x000 ; processor reset vector
goto Main ; go to beginning of program
;**********************************************************************
; isr code can go here or be located as a call subroutine elsewhere
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
Main:
banksel TRISC
bcf TRISC,6 ;c6=0 as output
; UART module setup
banksel SPBRG ;115.2k as 0x0A=8.7US
movlw 0x15 ; rs232 baud as 57.6k as 0x15
movwf SPBRG ; Enable SPBRG register Baud Rate
banksel TXSTA ; Select memory bank for TXSTA SFR
bcf TXSTA,TX9 ; 6----8-bit transmission
bsf TXSTA,TXEN ; 5----Enable Transmission/set
bcf TXSTA,SYNC ; 4----Asynchronous mode
bsf TXSTA,BRGH ; 2----High Baud Rate
banksel RCSTA
bcf RCSTA,RX9 ; 6
bsf RCSTA,SPEN ; 7--cause TXIF=1--cause TRMT=1--yes.2cond time
bsf RCSTA,CREN ; 4
;******************Delay for 10ms******************************
;****************send a 0x0F as start flag repeatly************
Sendrepeat:
MOVLW 0x0F
MOVWF 0x61 ;
MOVLW 0xC8 ;C8=200. 1000 is not allowed in PIC.
MOVWF ByteCounter1 ;maximum is FF in 8 bits.
loop0:
MOVF 0x61,0
CALL SerialTX0
DECFSZ ByteCounter1,1
GOTO loop0
GOTO Record ;?????
SerialTX0:
BANKSEL PORTC
BTFSC PORTC,5 ;CTS=PORTC,5, TEST C5, CTS
GOTO SerialTX0
BANKSEL TXSTA
BTFSS TXSTA,TRMT ;TXSTA,1 =default value is 1.
GOTO SerialTX0 ; make sure data transmission is sucessful ?
BANKSEL PIR1
BTFSS PIR1,TXIF
GOTO SerialTX0
MOVWF TXREG
CALL Reset0
return
Reset0:
BANKSEL RCSTA
BSF RCSTA,SPEN ; enable receive from TXREG to TSR.
return
;*****************save data into PIC memory************************
Record:
MOVLW 0x0A ; substitute your code to load W here
MOVWF 0x50 ;
MOVLW 0x0B
MOVWF 0x51 ;
MOVLW 0x0C
MOVWF 0x52 ;
MOVLW 0x0D
MOVWF 0x53 ;
MOVLW 0x0E
MOVWF 0x54 ;
MOVLW 0x0F
MOVWF 0x55 ;
;****************send real data out of PIC**********************
Send:
MOVLW 0x06
MOVWF ByteCounter ;ByteCounter=d10
MOVLW 0x50
MOVWF FSR
Loop:
MOVF INDF,0 ; substitute your code to load W here
CALL SerialTX
INCF FSR,1
DECFSZ ByteCounter,1
GOTO Loop
CALL DelayBig ;
GOTO Record
SerialTX:
BANKSEL PORTC
BTFSC PORTC,5 ;CTS=PORTC,5, TEST C5, CTS
GOTO SerialTX
BANKSEL TXSTA
BTFSS TXSTA,TRMT ;TXSTA,1 =default value is 1.
GOTO SerialTX ; make sure data transmission is sucessful ?
BANKSEL PIR1
BTFSS PIR1,TXIF ;PIR1,4
goto SerialTX
movwf TXREG ;cause TRMT=0, FULL. causing 2nd data is not given to TXREG.
CALL Reseting
return
DelayBig:
BANKSEL RCSTA ;05,A5=400u;
MOVLW 0x05
MOVWF 0x20 ;46,F5=10ms.FF,FF=40ms,88,FF=20ms
LOOP2: ;;03,C5=O DELAY;
MOVLW 0xA5 ;08,F5=1ms;88,44=5ms
MOVWF 0x21 ;04,95=290us;05,95=390u;05,D5=600u;05,A5=400u;
LOOP1:
DECFSZ 0x21,1
GOTO LOOP1
DECFSZ 0x20,1
GOTO LOOP2
BANKSEL RCSTA
BSF RCSTA,SPEN ; enable receive from TXREG to TSR.
return
Reseting:
BANKSEL RCSTA
BSF RCSTA,SPEN ; enable receive from TXREG to TSR.
return
END
;*********************transmit data finish******************************