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:
HBDelay nop HBDelay1 nop HBDelay2 goto $ + 1 HBDelay4 nop HBDelay5 nop nop movlw d'13' movwf BitWait BW decfsz BitWait,f goto BW nop return+
file: /Techref/microchip/12C672-rs232-tn.htm, 3KB, , updated: 2019/6/25 08:49, local time: 2024/12/21 22:06,
owner: kosme_lustosa-gmail-,
3.149.254.35: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? <A HREF="http://sxlist.com/techref/microchip/12C672-rs232-tn.htm"> PIC Specific RS232 routine</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.