用PIC16C63A作單片機(jī)串行通信,將BUFFER1和BUFFER2中的數(shù)據(jù)通過串口發(fā)送出去,我寫了下面的程序,不知對不對,謝謝!
;******************************************* ;MCU-PIC16C63A,WDT=ON,HS,16MHZ ;本例將寄存器BUFFER1和BUFFER2中的數(shù)據(jù)串口發(fā)送出去,沒有中斷調(diào)用,單片機(jī)選用PIC16C63A ;******************************************* LIST P=PIC16C63A INCLUDE "P16C63A.INC" ORG 0000H GOTO MAIN BUFFER1 EQU 20H BUFFER2 EQU 21H
MAIN MOVLW 0X55 MOVWF BUFFER1 MOVLW 0X56 MOVWF BUFFER2 ;發(fā)送過程 BSF STATUS,RP0 MOVLW 25H MOVWF SPBRG;設(shè)定波特率9600 CLRF TXSTA;SYNC=0-異步方式,沒有第9位,BRGH=0低速 BCF STATUS,RP0 MOVLW B'10010000' MOVWF RCSTA;SPEN=1,串口使能 BSF TXSTA,TXEN;允許發(fā)送
MOVF BUFFER1,W;發(fā)送第一個寄存器數(shù)據(jù) MOVWF TXREG again BTFSS TXSTA,TRMT;判斷TSR為空則間斷 GOTO again MOVF BUFFER2,W;發(fā)送第二個寄存器數(shù)據(jù) MOVWF TXREG again2 BTFSS TXSTA,TRMT;判斷TSR為空則間斷 GOTO again2 NOP END
※ PIC單片機(jī) www.pic16.com
發(fā)信人:martin 發(fā)表時間:2001-11-02 13:12:06
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' ; 十進(jìn)制的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' |
|
|