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: 2008/1/29 09:46, local time: 2008/11/21 13:02,
owner: kosme_lustosa-gmail-,
38.103.63.59:LOG IN
|
| ©2008 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! <A HREF="http://piclist.org/techref/microchip/12C672-rs232-tn.htm"> PIC Specific RS232 routine</A> |
| Did you find what you needed? |
|
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
|
.