; 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
;
DelayY
decfsz Count,f
goto R_next
bsf STATUS,C
retlw 0x01
;
;
;*****************************************************************
; Function Name: putcUART *
; Return Value: none *
上一页 [1] [2] [3] [4] [5] 下一页
本文关键字:暂无联系方式PIC单片机,单片机-工控设备 - PIC单片机