please dont rip this site
with a 4Mhz Xtal, and the code that I use, I can
get 9600 baud Tx or Rx not both, because I'm not using interrupts to keep
the routine as simple as possible, you can include it almost in any program
with minor modifications, I know that here in the list are better ones but
this one is very simple :-).

Serial TX routine:
; *************************************************
; **               transmit routine              **
; **   W must have the data to be transmitted    **
; *************************************************
; Note: _tx is the bit used for transmit data, must be set as output.
;       baudrate is a constant see initialization.
;       you must declare as registers the follow: txreg, delay & count
;
send	mov	txreg, W
	clrb	_tx	;send start bit
	mov	W, #baudrate
	mov	delay, W
	mov	W, #9
	mov	count, W
txbaudwait	decsz	delay
	jmp	txbaudwait
	mov	W, #baudrate
	mov	delay, W
	decsz	count
	jmp	sendnextbit
	mov	W, #9
	mov	count, W
	setb	_tx	;send stop bit
	retw	#0
sendnextbit	rr	txreg
	sb	C	;check next bit to tx
	jmp	setlo
	setb	_tx	;send a high bit
	jmp	txbaudwait
setlo	clrb	_tx	;send a low bit
	jmp	txbaudwait
; end
; *********************************************
; **              Serial RX routine          **
; ** before	call	this one
; *********************************************
; same as below but _rx must be declared as pin, and configured as input.
; also declare rcreg as register
; count must have the value 9 before call this routine (needed only the
; first time you call it).
;
receive	snb	_rx
	jmp	$-1
	mov	W, #baudrate
	mov	delay, W
rxbaudwait	decsz	delay
	jmp	$-1
	mov	W, #baudrate
	mov	delay, W
	decsz	count
	jmp	recvnextbit
	mov	W, #9
	mov	count, W
	retw	#0
recvnextbit	clrb	C
	snb	_rx
	setb	C
	rr	rcreg
	jmp	rxbaudwait
;

Remember that when you call receive routine, it will keep looping until a
low state (start bit) can be detected, then it will get the 8 bits and
exit routine, if you are planning to receive many bytes, you must call this
one again, as much as characters to receive you are especting.

with some programming you can modify that to do other jobs in the mean time,
but keep in mind the timming factor, at 4Mhz and high baud rates it's very
critical!.

there is no parity check, only 8N1 format.

At the start of the program you must declare the follow:

;
; definitions...
;
count	equ	$10
delay	equ	$11
txreg	equ	$12
rcreg	equ	$13
;
clockrate	equ	2000000	;Xtal value (2Mhz in this case)
fclk	equ	clockrate/4
baudrate	equ	((fclk/2400)/3-2)	;2400 is the baud rate
;
;

for 4mhz clockrate must be .4000000, etc.
but remember that not all combinations work, you must done this calculation
by hand to make shure that the baudrate value will not be more than FF or
it won't work, in this case the value is : 2e6/4= 5e5/2400 = 208/3 = 69-2
=67.44\  , the value for the baudrate constant will be 67, remember
that if the decimal component is more that .5 you must round up the number
to avoid errors, also, the smaller value for baudrate, the higher posibility
of reception error, so if the number is bigger, will work better.

I hope that it can be useful for you, anyway if doesn't work write me and
i will try to help you...

see you.

   Leandro J. Laporta (LU2AOQ)     mail: lu2aoq@yahoo.com
 wrk: Arg. Assoc. for Space Tech.   ham: TCP/IP high speed group HSG

Code:


file: /Techref/scenix/lib/io/osi2/serial/rs232at9600on16F84noint_sx.htm, 7KB, , updated: 2005/7/15 15:08, local time: 2024/3/28 03:04,
TOP NEW HELP FIND: 
18.232.188.122: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://www.piclist.com/techref/scenix/lib/io/osi2/serial/rs232at9600on16F84noint_sx.htm"> scenix lib io osi2 serial rs232at9600on16F84noint_sx</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?

  PICList 2024 contributors:
o List host: MIT, Site host massmind.org, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
 

Welcome to www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .