please dont rip this site

PIC Specific RS232 routine

by Tony Nixon

These simple serial routines may help.19200 baud Fosc = 4MHz Receive can be polled or interrupt driven.

;
; ----------------
; TRANSMIT ROUTINE
; ----------------
;
TxRoutine       movwf TxSend            ; temp store data to be sent
        bcf PORT,TX             ; do start bit
        call HBDelay5
        call HBDelay2
;
        movlw 8h                        ; 8 data bits to send
        movwf BCount
;
TxLoop  rrf TxSend
        btfsc STATUS,C
        goto TxHiBit
;
        nop
        bcf PORT,TX
        goto DoneBit
;
TxHiBit bsf PORT,TX
        goto $ + 1
;
DoneBit call HBDelay5           ; wait 1 bit length
        call HBDelay5
        decfsz BCount
        goto TxLoop
;
        call DoRet
        nop
        bsf PORT,TX             ; stop bit
        call HBDelay1
        call HBDelay
DoRet   return

;
;
; ---------------
; RECEIVE ROUTINE
; ---------------
;
RxRoutine       bcf flag1,data
        btfsc PORT,RX           ; wait for start bit
        return
;
        call HBDelay2           ; wait 1/2 bit length - 2 cycles
        movlw 9h
        movwf BCount
;
RxLoop  btfsc PORT,RX           ; start bit is lost during routine
        goto RxHiBit
;
        bcf STATUS,C            ; receive start bit and 8 data bits
        goto RxLoBit
;
RxHiBit bsf STATUS,C
        nop
RxLoBit rrf RxHold
        call HBDelay4           ; wait 1/2 bit length - 4 cycles
        call HBDelay5           ; wait 1/2 bit length - 5 cycles
        decfsz BCount
        goto RxLoop
;
        movf RxHold,W
        bsf flag1,data
        return                  ; data returned in W Reg
;
; --------------
; HALF BIT DELAY
; --------------
;
HBDelay nop
HBDelay1        nop
HBDelay2        goto $ + 1
HBDelay4        nop
HBDelay5        movlw 0x05
        movwf BitWait
BW      decfsz BitWait
        goto BW
        nop
        return

Questions:

Comments:


file: /Techref/microchip/12C672-rs232-tn.htm, 3KB, , updated: 2019/6/25 08:49, local time: 2024/11/25 17:30, owner: kosme_lustosa-gmail-,
TOP NEW HELP FIND: 
3.147.65.47:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/Techref/microchip/12C672-rs232-tn.htm"> PIC Specific RS232 routine</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .