📄 sercom.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; SERCOM.ASM Version 1.0 10-9-05 MPB
;...............................................................
;
; Test RS232 communications using the
; USART Asynchronous Transmit and Receive
;
; The Proteus Virtual Terminal allows ASCII characters
; to be displayed, and generated from the computer keys.
; The program outputs a fixed message to the display
; from a table, and then displays numbers input from the
; terminal on a BCD 7-segment LED display.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PROCESSOR 16F877 ; define MPU
__CONFIG 0x3731 ; XT clock (4MHz)
; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE "P16F877A.INC" ; Standard register labels
Point EQU 020
Inchar EQU 021
; Initialise ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORG 0 ; Place machine code
NOP ; Required for ICD mode
BANKSEL TRISD ; Select bank 1
CLRF TRISD ; Display outputs
BCF TXSTA,TX9 ; Select 8-bit transmission
BCF TXSTA,TXEN ; Disable transmission initially
BCF TXSTA,SYNC ; Asynchronous mode
BSF TXSTA,BRGH ; High baud rate
MOVLW D'25' ; Baud rate counter value ..
MOVWF SPBRG ; .. for 9600 baud, 4MHz clock
BSF TXSTA,TXEN ; Enable transmission
BANKSEL RCSTA ; Select bank 0
BSF RCSTA,SPEN ; Enable serial port
; MAIN LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CALL write ; Display message on terminal
readin CALL read ; Get number input from terminal
GOTO readin ; Keep reading until reset
; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Write message to terminal......................................
write CLRF Point ; Table pointer = 0
next MOVF Point,W ; Load table pointer
CALL mestab ; Get character
CALL sencom ; Output to terminal
INCF Point ; Point to next
MOVLW D'14' ; Number of characters + 1
SUBWF Point,W ; Check pointer
BTFSS STATUS,Z ; Last character done?
GOTO next ; No - next
RETURN ; All done
; Read input numbers from terminal...............................
read BSF RCSTA,CREN ; Enable reception
waitin BTFSS PIR1,RCIF ; Character received?
GOTO waitin ; no - wait
MOVF RCREG,W ; get input character
MOVWF Inchar ; store input character
MOVLW 030 ; ASCII number offset
SUBWF Inchar,W ; Calculate number
MOVWF PORTD ; display it
RETURN ; done
; Transmit a character ..........................................
sencom MOVWF TXREG ; load transmit register
waitot BTFSS PIR1,TXIF ; sent?
GOTO waitot ; no
RETURN ; yes
; Table of message characters....................................
mestab ADDWF PCL ; Modify program counter
RETLW 'E' ; Point = 0
RETLW 'N' ; Point = 1
RETLW 'T' ; Point = 2
RETLW 'E' ; Point = 3
RETLW 'R' ; Point = 4
RETLW ' ' ; Point = 5
RETLW 'N' ; Point = 6
RETLW 'U' ; Point = 7
RETLW 'M'; ; Point = 8
RETLW 'B' ; Point = 9
RETLW 'E' ; Point = 10
RETLW 'R' ; Point = 11
RETLW ':' ; Point = 12
RETLW ' ' ; Point = 13
END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -