利用串口調(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.
;燒寫(xiě)時(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
;-------------------
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
ANDWF GETPTR,F
MOVF INDF,W
MOVWF TXBUFF+0
MOVLW 'P'
MOVWF TXBUFF+1
MOVLW 'I'
MOVWF TXBUFF+2
MOVLW 'C'
MOVWF TXBUFF+3
MOVLW 'A'
MOVWF TXBUFF+4
MOVLW 'V'
MOVWF TXBUFF+5
MOVLW 'R'
MOVWF TXBUFF+6
MOVLW 0X0D
MOVWF TXBUFF+7
MOVLW 0X0A
MOVWF TXBUFF+8
MOVLW .9
MOVWF TXCOUNT
CLRF TXPTR
BSF STATUS,RP0
BSF PIE1,TXIE
BCF STATUS,RP0
RETURN
;---------------------
END