📄 uart.asm
字号:
SUBTITLE "Software uart subroutines"
#define TX_ GPIO,2
;************************************************************************************************************
; SEND BYTE BY UART
;************************************************************************************************
;Name: pic10_uart
;Function: Send a byte by uart
;Input: W
;Output: No
;Comments:
;************************************************************************************************************
pic10_uart
MOVWF TX_buffer ; Load the sent byte in a data register
CALL start_bit ; Generate START bit
CALL send_byte ; Send byte
CALL stop_bit ; Generate STOP bit
RETLW 0
;----------------------------------------------------------------------------------------------
stop_bit
BCF TX_ ; Clear TX_ line
MOVLW BAUDRATE ;|
MOVWF counterL ;|
DECFSZ counterL,f ; > Define a single bit duration
GOTO $-1 ;|
NOP ;|
RETLW 0
;----------------------------------------------------------------------------------------------
start_bit
BSF TX_ ; Set TX_ line
MOVLW BAUDRATE ;|
MOVWF counterL ;|
DECFSZ counterL,f ; > Define a single bit duration
GOTO $-1 ;|
NOP ;|
RETLW 0
;----------------------------------------------------------------------------------------------
send_byte
MOVLW D'8' ; 8 -> W
MOVWF Bit_counter ; W -> Bit_counter
send_next_bit
RRF TX_buffer,F ; Shift TX_buffer to right
BTFSS STATUS,C ; Check STATUS<C>
GOTO send_1 ; If C=1 send 1 by the uart
GOTO send_0 ; Else send 0 by the uart
send_1
BSF TX_ ; Set TX_ line
MOVLW BAUDRATE ;|
MOVWF counterL ;|
DECFSZ counterL,f ; > Define a single bit duration
GOTO $-1 ;|
NOP ;|
GOTO end_send_byte
send_0
BCF TX_ ; Clear TX_ line
MOVLW BAUDRATE ;|
MOVWF counterL ;|
DECFSZ counterL,f ; > Define a single bit duration
GOTO $-1 ;|
NOP ;|
end_send_byte
DECFSZ Bit_counter,F ; All bits are sent?
GOTO send_next_bit ; No,send next bit
RETLW 0
;----------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -