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 movwf txreg bcf _tx ;send start bit movlw baudrate movwf delay movlw .9 movwf count txbaudwait decfsz delay goto txbaudwait movlw baudrate movwf delay decfsz count goto sendnextbit movlw .9 movwf count bsf _tx ;send stop bit retlw 0 sendnextbit rrf txreg btfss _c ;check next bit to tx goto setlo bsf _tx ;send a high bit goto txbaudwait setlo bcf _tx ;send a low bit goto txbaudwait ; end ; ********************************************* ; ** Serial RX routine ** ; ** before call this one, delay = baudrate ** ; ********************************************* ; 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 btfsc _rx goto $-1 movlw baudrate movwf delay rxbaudwait decfsz delay goto $-1 movlw baudrate movwf delay decfsz count goto recvnextbit movlw .9 movwf count retlw 0 recvnextbit bcf _c btfsc _rx bsf _c rrf rcreg goto 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 0x10 delay equ 0x11 txreg equ 0x12 rcreg equ 0x13 ; 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
file: /Techref/scenix/lib/io/osi2/serial/rs232at9600on16F84noint.htm, 4KB, , updated: 2000/5/3 12:17, local time: 2024/8/14 17:30,
18.191.1.73: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://piclist.com/techref/scenix/lib/io/osi2/serial/rs232at9600on16F84noint.htm"> scenix lib io osi2 serial rs232at9600on16F84noint</A> |
Did you find what you needed? |
![]() 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 piclist.com! |
.