On Sun, 7 Dec 1997 15:08:58 +0100 Kees van Bruggen writes: >Can anyone help me to find some serial C-language routines for the = >16C84. >I am using the MPLAB-C compiler. I am interested in the SEND/RECEIVE = >routines and the routines for setting the baudrate. The 16C84 doesn't have any dedicated hardware for serial sending and receiving. This means that software must be used. The best approach to software serial sending and receiving depends a lot on the application. C compilers may include library routines to send and/or receive, which may or may not be suitable for the application. The general methods for software async serial include: * Dedicated foreground routines. This is the simplest to code, but has several limitations. Usually it can't send and receive at the same time. While sending or receiving, the PIC can't do anything else (unless carefully integrate with the send/receive routine). The sending and receiving routines can't be interrupted, as this would throw off the timing. * Timer interrupt at a multiple of the baud rate. This is very flexible. The ISR operates as a "state machine", sending and/or receiving as required. But the PIC may not have enough time at high baud rates. Also the main program is interrupted constantly, so it doesn't exceute at a constant rate. But, once the timer ISR is in place, it can also operate counters or flags to precisely pace the main program. The "paced main program" method, where either counted instructions or polling the timer are used to call the serial state machine routine is comparable to the timer interrupt method. This is primarily of use on the 12-bit PICs which don't have interrupts. * Hardware interrupt from serial input. This is mainly a receiving scheme. The serial input is connected to the INT or TMR0IN pin so the start bit interrupts the PIC. It then uses software timing (similar to first method above) or a timer interrupt (similar to second method) to receive the data bits. The advantage here is that the PIC runs uninterrupted at full speed while no data is being received. The disadvantage is that the ISR takes a whole character time (if software timed), or disrupts the timer register (if hardware timed).