利用串口調(diào)試精靈或PC端的超級(jí)終端調(diào)試串口的程序
;利用串口調(diào)試精靈或PC端的超級(jí)終端,波特率設(shè)為9600,數(shù)據(jù)位8位,
;停止位1位,無(wú)校驗(yàn)位.
;首選從PC機(jī)向串串口發(fā)送一個(gè)字符如2,單片機(jī)收到后返發(fā)收到這個(gè)數(shù)如2-PIC16給電腦.
;注意實(shí)驗(yàn)板的設(shè)定:S4,S5,S1要全部到OFF,S13第6,7腳一定要ON.
;燒寫時(shí)注意振蕩方式XT,WDT要禁止.
LIST P=16F877
INCLUDE P16F877.INC
;***********************************
__CONFIG _DEBUG_OFF_CP_ALL_WRT_HALF_CPD_ON_LVP_OFF_BODEN_OFF_PWRTE_ON_WDT_OFF_HS_OSC;
;************************
CBLOCK 0x20
TXBUFF :9
TXPTR
TXCOUNT
RXBUFF :9
PUTPTR
GETPTR
STATUS_TEMP
FSR_TEMP
ENDC
W_TEMP EQU 7FH
;-------------------------
ORG 0X000
GOTO MAIN
;-------------------------
ORG 0X004
GOTO INT
ORG 0X008
INT
MOVWF W_TEMP
SWAPF STATUS,W
CLRF STATUS
MOVWF STATUS_TEMP
MOVFW FSR
MOVWF FSR_TEMP
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
BSF STATUS,RP0
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
ENDOFINT
CLRF STATUS
MOVFW FSR_TEMP
MOVWF FSR
SWAPF STATUS_TEMP,W
MOVWF STATUS
SWAPF W_TEMP,F
SWAPF W_TEMP,W
RETFIE
;-------------------
評(píng)論