Microchip Application Note AN555 gives the code and a detailed account of interfacing RS232 to a 16CXX chip using the RA4/T0CKI method suggested below; ie preload 0xFF to detect start, check in initial interrrupt that start was not noise, then reprogram the timer to interrupt at half or quarter bit times to decode the byte. Ron On Fri, 13 Mar 1998, Marco DI LEO wrote: > James & Ili wrote: > > > > Marco, > > Did you read the post by Danjel ? It looks like a simpler way to go. > > James > > It appear to be the same approach except for the start bit detection. > > The Danjel method detect the start bit "[using] a periodical interrupt > running at 2 or 3 times the baud rate" in witch you "samples the RX > line". > I just try to detect the start bit using an interrupt on the start bit > edge. > The rest of both methods is essentially the same. > > There are pros and cons in both approaches: > Danjel method pros: you can use any pin as RX line because you sample it > using a bit test instruction. cons: if there is no traffic on the line > you still have 3 int per bit time interrupting you main task. > My method pros: your main task is only interrupted when a transmission > occur. If transmission are rare you can save lot of compute power. cons: > you have to use specific pin for the RX line. On the 16C84 you can > choose between the RB0/INT and RA4/T0CK1. Use the latter setting the > counter to external clock, no prescaler and preload it to 0xFF. At the > the first edge the counter roll to 0x00 thus generating an int. The > RB0/INT method is easier but the RA4/T0CK1 saves you an interrupt source > because you only use the timer/counter for bit timing/start bit > detection, having the RB0/INT free for other purposes. > > The choice of the method used to detect the start bit depends completely > on your application and on the timing of your main task. > > Marco > > ---- > Marco DI LEO email: m.dileo@sistinf.it > Sistemi Informativi S.p.A. tel: +39 6 50292 300 > V. Elio Vittorini, 129 fax: +39 6 5015991 > I-00144 Roma > Italy > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ron Kreymborg Computer Systems Manager Monash University CRC for Southern Hemisphere Meteorology Wellington Road Clayton, VIC 3168 Phone : 061-3-9905-9671 Australia Fax : 061-3-9905-9689 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~