电子产业
数字化服务平台

扫码下载
手机洽洽

  • 微信小程序

    让找料更便捷

  • 扫码下载手机洽洽

    随时找料

    即刻洽谈

    点击下载PC版
  • 华强电子网公众号

    电子元器件

    采购信息平台

  • 华强电子网移动端

    生意随身带

    随时随地找货

  • 华强商城公众号

    一站式电子元器件

    采购平台

  • 芯八哥公众号

    半导体行业观察第一站

16C5X模拟串口(2)

来源:-- 作者:-- 浏览:271

标签:

摘要: if BAUDRATE == 9600BAUD_1 equ .173 ; 3+3X = CLKOUT/Baud (9600 baud, 10MHz) BAUD_4 equ .216 ; 3+3X = 1.25*CLKOUT/BaudBAUD_X equ .170 ; 11+3X = CLKOUT/BaudBAUD_Y equ .171 ; 9 +3X = CLKOUT/Bau

if BAUDRATE == 9600
BAUD_1 equ .173 ; 3+3X = CLKOUT/Baud (9600 baud, 10MHz)

 

BAUD_4 equ .216 ; 3+3X = 1.25*CLKOUT/Baud
BAUD_X equ .170 ; 11+3X = CLKOUT/Baud
BAUD_Y equ .171 ; 9 +3X = CLKOUT/Baud
endif
if BAUDRATE == 4800
error "Baudrate and cLOCk speed incompatable"
endif
if BAUDRATE == 2400
error "Baudrate and clock speed incompatable"
endif
if BAUDRATE == 1200
error "Baudrate and clock speed incompatable"
endif
endif

; GenerIC delay loop
Delay macro
local loop
movwf DlyCnt
loop
decfsz DlyCnt,f
goto loop
endm

; Specific delay loops... loads counter value then generic delay loop
Delay1 macro ; 3+3X = CLKOUT/Baud
movlw BAUD_1
Delay
endm

Delay4 macro ; 3+3X = 1.25*CLKOUT/Baud
movlw BAUD_4
Delay
endm

DelayX macro ; 11+3X = CLKOUT/Baud
movlw BAUD_X
Delay
endm

DelayY macro ; 9 +3X = CLKOUT/Baud
movlw BAUD_Y
Delay
endm
;
;************************ Data RAM Assignments **********************
;
udata
RcvReg res 1 ; Data received
XmtReg res 1
global RcvReg
global XmtReg
global OpenUART
global putcUART
global getcUART

udata_ovr
Count res 1 ; Counter for #of Bits Transmitted
DlyCnt res 1
;
CODE
;
;*****************************************************************
; Function Name: OpenUART *
; Return Value: none *
; Parameters: None (parameters set at assembly time) *
; RAM Usage: 0 bytes *
; ROM Usage: 4 words *
; Description: Sets the TRIS register for the UARTPORT *
; such that the RX_PIN is an input, the *
; TX_PIN is an output, and the rest of the *
; bits are as specified by TRISMASK. Also *
; sets the TX_PIN high (idle condition). *
;*****************************************************************
OpenUART
bsf UARTPORT,TXPIN ; Start it off high
movlw portmask
tris UARTPORT ; Set PWM pin for output
retlw 0

;
;*****************************************************************
; Function Name: getcUART *
; Return Value: returns a status in the carry bit (STATUS.C) *
; if a character was recieved, carry =1. *
; if no character recieved, carry = 0 *
; received character returned in RcvReg *
; Parameters: None (parameters set at assembly time) *
; RAM Usage: 0 *
; ROM Usage: depends *
; Description: looks for a start bit on the RX_PIN. If *
; none, it clears the carry bit and returns. *
; if there is a carry bit, it reads in the *
; rest of the byte, saves it in RcvReg, *
; and sets the carry bit. *
;*****************************************************************
getcUART
clrf RcvReg ; Clear RcvReg
bcf STATUS,C ; Clear the carry bit (assume nothing rx'd)
btfsc UARTPORT,RXPIN ; check for a Start Bit

retlw 0 ; no char received.. return null.
Delay4 ; delay for 1

IF Nbit
movlw 8 ; 8 Data bits
ELSE
movlw 7 ; 7 data bits
ENDIF
;
movwf Count
R_next bcf STATUS,C
IF MODE
rrf RcvReg,f ; to set if MSB first or LSB first
ELSE
rlf RcvReg,f
ENDIF
btfsc UARTPORT, RXPIN
;
IF MODE
IF Nbit
bsf RcvReg,MSB ; Conditional Assembly
ELSE
bsf RcvReg,MSB-1
ENDIF
ELSE
bsf RcvReg,LSB
ENDIF

型号 厂商 价格
EPCOS 爱普科斯 /
STM32F103RCT6 ST ¥461.23
STM32F103C8T6 ST ¥84
STM32F103VET6 ST ¥426.57
STM32F103RET6 ST ¥780.82
STM8S003F3P6 ST ¥10.62
STM32F103VCT6 ST ¥275.84
STM32F103CBT6 ST ¥130.66
STM32F030C8T6 ST ¥18.11
N76E003AT20 NUVOTON ¥9.67