PIC16C63串口通信程序
list p=16c63 ; list directive to define processor
#include <p16c63.inc> ; processor specific variable definitions
__CONFIG _BODEN_OFF&_CP_OFF&_WRT_ENABLE_ON&_PWRTE_ON&_WDT_OFF&_XT_OSC&_DEBUG_OFF&_CPD_OFF&_LVP_OFF
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x20 ; variable used for context saving
status_temp EQU 0x21 ; variable used for context saving
Buffer1 EQU 0x22
Buffer2 EQU 0x23
;**********************************************************************
ORG 0x000 ; processor reset vector
nop
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
bcf STATUS,RP0 ; ensure file register bank set to 0
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
ORG 40H
main
banksel TRISC ; MPLAB提供的宏,BANK选择
MOVLW 0X80
MOVWF TRISC ; TX/RX口输入输出配置
banksel SPBRG
MOVLW D'25' ; 十进制的25
MOVWF SPBRG ; 9600 BPS/ 4MHZ
banksel TXSTA
CLRF TXSTA
BSF TXSTA,BRGH ; HIGH SPEED/ASYN/8BITS
BSF TXSTA,TXEN
banksel RCSTA
CLRF RCSTA
BSF RCSTA,SPEN ; SERIAL PORT ENABLE
BSF RCSTA,CREN ; CONTINUOUS RECEIVE ENABLE
; 8BITS/DISABLE ADDEN
banksel TXREG
movf Buffer1,W
movwf TXREG
call TXPOLL
movf Buffer2,W
movwf TXREG
call TXPOLL
goto $
;************************************************
;* RXPOLL - This function polls the USART *
;* receive interrupt flag and waits until a *
;* data byte is available in RCREG. *
;************************************************
RXPOLL
bcf STATUS,RP0
btfss PIR1,RCIF
goto RXPOLL
return
;************************************************
;* TXPOLL - This function polls the TRMT flag *
;* and waits until the USART has finished *
;* shifting the data byte out of the transmit *
;* shift register. *
;************************************************
TXPOLL
bsf STATUS,RP0
TLOOP
btfss TXSTA,TRMT
goto TLOOP
bcf STATUS,RP0
return
END ; directive 'end of program'
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。