"); //-->
例子8-2代码从略
例子8-3代码
#include<p16f877.inc> cblock 0X20 txBuff :8 txPtr txCount rxBuff :8 putPtr getPtr endc w_temp equ 0x40 status_temp equ 0x41 pch_temp equ 0x42 fsr_temp equ 0x43 org 0x000 goto main org 0x004 movwf w_temp movf STATUS,W CLRF STATUS MOVWF status_temp movf PCLATH,W MOVWF pch_temp movf FSR,W MOVWF fsr_temp ;clrf PCLATH ChkRxInt banksel PIR1 BTFSS PIR1,RCIF GOTO ChkTxInt _RdRxFIFO btfsc RCSTA,FERR GOTO _FERR_pro movlw rxBuff movwf FSR MOVF putPtr,w addwf FSR,f movf RCREG,W MOVWF INDF INCF putPtr,f MOVLW .7 ANDWF putPtr,f btfsc PIR1,RCIF GOTO _RdRxFIFO BTFSS RCSTA,OERR GOTO EndOfInt _OERR_pro bcf RCSTA,CREN BSF RCSTA,CREN GOTO EndOfInt _FERR_pro MOVF RCREG,W GOTO EndOfInt ChkTxInt banksel PIE1 BTFSS PIE1,TXIE GOTO EndOfInt bcf STATUS,RP0 BTFSS PIR1,TXIF GOTO EndOfInt movlw txBuff movwf FSR MOVF txPtr,w addwf FSR,f movf INDF,W MOVWF TXREG INCF txPtr,f decfsz txCount,f goto EndOfInt bsf STATUS,RP0 BCF PIE1,TXIE BCF STATUS,RP0 GOTO EndOfInt EndOfInt clrf STATUS MOVF fsr_temp,w movwf FSR MOVF pch_temp,w movwf PCLATH MOVF status_temp,w movwf STATUS SWAPF w_temp,f SWAPF w_temp,w RETFIE org 0x200 main banksel TXSTA MOVLW B'00100100' MOVWF TXSTA MOVLW .25 MOVWF SPBRG CLRF PIE1 BSF PIE1,RCIE CLRF STATUS CLRF txCount clrf getPtr clrf putPtr movlw b'10010000' movwf RCSTA CLRF INTCON BSF INTCON,PEIE BSF INTCON,GIE Loop call Check_Data goto Loop Check_Data clrf STATUS MOVF txCount,w skpz return movf getPtr,w xorwf putPtr,w skpnz return movlw rxBuff movwf FSR MOVF getPtr,w addwf FSR,F INCF getPtr,F MOVLW .7 ADDWF getPtr,f movf INDF,w movwf txBuff+0 movlw ' ' movwf txBuff+1 movlw '1' movwf txBuff+2 movlw '2' movwf txBuff+3 movlw '3' movwf txBuff+4 movlw '4' movwf txBuff+5 movlw 0x0d movwf txBuff+6 movlw 0x0a movwf txBuff+7 movlw .8 movwf txCount clrf txPtr bsf STATUS,RP0 BSF PIE1,TXIE BCF STATUS,RP0 RETURN END
效果图
从图中可以看出,第二个单片机有时候回送的是0x55,有时候则不是。不知何故。
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。