|
RCDATA EQU 30H
RCFLAG EQU 31H
RCOneSIGN EQU 0
RCWrong EQU 5
#INCLUDE <P16877.INC>
org 0
nop
goto start
org 4
intentr
goto intsever
;____________________________
org 9
start
clrf RCFLAG
clrf RCDATA
InitUart
bsf STATUS,RP0
bcf RCFLAG,RCOneSIGN
movlw b'10111111' ;TX=output
movwf TRISC
movlw b'10100110'
movwf TXSTA
movlw 19h
movwf SPBRG ;9600,high speed mode
bsf STATUS,RP0
movlw b'00100000'
movwf PIE1
movlw b'11000000'
movwf INTCON
bcf STATUS,RP0
movlw b'10010000'
movwf RCSTA
main
btfsc RCFLAG,RCOneSIGN
goto TXLoop
;btfss RCFLAG,RCWrong
goto main
TXLoop
bcf STATUS,RP0
movf RCDATA,w
movwf TXREG
bsf STATUS,RP0
btfss TXSTA,TRMT
goto $-2
bcf STATUS,RP0
bcf RCFLAG,RCOneSIGN
goto main
;*****************************
intsever
movf STATUS,w
btfsc STATUS,RP0
bcf STATUS,RP0
movwf RCFLAG
btfsc RCSTA,OERR
goto RCerror
movf RCREG,w
movwf RCDATA
bsf RCFLAG,RCOneSIGN
retfie
RCerror
bcf STATUS,RP0
bcf RCSTA,CREN
movf RCREG,w
movf RCREG,w
movlw b'10010000'
movwf RCSTA
btfsc RCFLAG,RCWrong
bsf STATUS,RP0
clrf RCFLAG
retfie
;----------------
end
注意,这个程序是先收再发的,如果接收不到数据那么发送也就不启动。 |
|