微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 利用串口调试精灵或PC端的超级终端调试串口的程序

利用串口调试精灵或PC端的超级终端调试串口的程序

时间:09-28 来源:互联网 点击:

;利用串口调试精灵或PC端的超级终端,波特率设为9600,数据位8位,
;停止位1位,无校验位.
;首选从PC机向串串口发送一个字符如2,单片机收到后返发收到这个数如2-PIC16给电脑.
;注意实验板的设定:S4,S5,S1要全部到OFF,S13第6,7脚一定要ON.
;烧写时注意振荡方式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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top