Searching \ for 'Async Serial' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/serials.htm?key=serial
Search entire site for: 'Async Serial'.

Truncated match.
PICList Thread
'Async Serial'
1999\10\05@222253 by Azrael

picon face
   I am currently working on a project that would greatly benefit from
Asyncronus Serial transfers to another PIC chip.  I have looked for examples
and/or source examples but have come up with only concepts.  Anyone written
or seen code for this for a 16C5XX series chip?  And being a poor college
student has me pretty much writing this alone.  Thanks for any help or
information you can offer.

-Stu

1999\10\06@064330 by Jose Souto

flavicon
face
part 0 13921 bytes
x-html> Azrael wrote:
    I am currently working on a project that would greatly benefit from
Asyncronus Serial transfers to another PIC chip.  I have looked for examples
and/or source examples but have come up with only concepts.  Anyone written
or seen code for this for a 16C5XX series chip?  And being a poor college
student has me pretty much writing this alone.  Thanks for any help or
information you can offer.

-Stu


/*------------------------------------------------------------------- -------+
 | Asynchronous Serial communication routines for 12c508   ;             & nbsp;    |
 | Author: Jose Luiz Pinto Souto       ;             & nbsp;            &nb sp;           |
 | souto@cryogen.com         ;             & nbsp;            &nb sp;              ;        |
 | 9600 BPS, 1 start bit, 8 data bits, 1 stop bit                 &n bsp;          |
 |            ;             & nbsp;            &nb sp;              ;             & nbsp;         |
 | Compiled with CC5xFree from www.bknd.com                  &n bsp;            &nbs p;  |
 +----------------------------------------------------------------- ---------*/

/*
** 4 MHz Internal Oscillator
*/

#include <12c508.h>

char rxBuf;

#pragma bit RxD_pin @ GP3
#pragma bit _TxOUT  @ GP2
 

/*
;----------------------------------------------------------------------- -----*
; GPIO.0 : output - unused
; GPIO.1 : output - unused
; GPIO.2 : output - TxD pin
; GPIO.3 : input  - RxD pin     (obs.)
; GPIO.4 : output - unused
; GPIO.5 : output - unused
;----------------------------------------------------------------------- -----*
  obs.: requires external pull-up or internal week pull-up enabled
*/
 

/*----------------------------------------------------------------------- ---*/
void Delay_uSeg (char timeout)
/*---------------------------------------------------------------------- ----*/
{
    // delay = 3*timeout + 7uS (including call and return)

    while (1) {
        timeout--;
        if (timeout==0) {
            nop();
            nop();
            return;
        }
    }
}

/*----------------------------------------------------------------------- ---*/
void TxSerial (char txBuf)
/*---------------------------------------------------------------------- ----*/

/*
 ;----------------------------------------------------------------- ----------*
 ; Transmit 1 start bit Lo, 8 data bits and 1 stop bit Hi at 9600 bps
 ; No Parity
 ; Byte time = 1.040 mS
 ; Bit  time = 104 uS (0.16% erro w/4.00 Mhz Internal RC)
 ; Input : W = byte to be transmitted
 ; Output: byte transmitted by serial pin
 ;----------------------------------------------------------------- ----------*
*/

{
    char idx;

    while (1) {
        Carry = 0;   & nbsp;            &nb sp;     // start bit
        for (idx=10; idx; idx--) {      // 3us
            _TxOUT = Carry;            ;  // 4us
            Delay_uSeg(28);            ;  // 91us (28*3+7)
            Carry  = 1;          &nbs p;      // 1us
            txBuf  = rr(txBuf);         // 1us
            nop();            &n bsp;         // 1us
        }    &nbs p;                           // 3us
        return;
    }
}

/*----------------------------------------------------------------------- ---*/
void RxSerial (void)
/*---------------------------------------------------------------------- ----*/

/*
 ;----------------------------------------------------------------- ----------*
 ; Receives 1 start bit Lo, 8 data bits and 1 stop bit Hi at 9600 bps
 ; No Parity
 ; Byte time = 1.040 mS
 ; Bit  time = 104 uS (0.16% erro w/4.00 Mhz Internal RC)
 ;
 ; False start bit check
 ;
 ; Start bit hunting timeout = 4*1.283ms
 ;
 ; Input  : none
 ; Output : Carry = 1 => success
 ;          rxBuf = input byte
 ;          Carry = 0 => error (timeout or stop bit=0)
 ;----------------------------------------------------------------- ----------*
*/

{
    char idx;

    rxBuf = 4;       &n bsp;            &nbs p;     // 5.135 ms timeout
    idx   = 0;

    while (1) {
        while (RxD_pin) {                // input "high"
            if ((-- idx)==0) {
                 if ((-- rxBuf)==0) {
                     Carry = 0;
                     return;
                 }
            }
        }

        Delay_uSeg(14);  &nb sp;              ; // 1/2 bit delay (14*3+7)
        if (RxD_pin)
            continue;             ;       // false start bit detection

        rxBuf = 0x80;    ;             & nbsp;  // 8 bits counter and reception buffer
        nop();
        nop();     ;             & nbsp;        // timming adjustment

        do {
            Delay_uSeg(30);            ;  // (30*3+7)us
            Carry = RxD_pin;          &nbs p; // bit read
            rxBuf = rr(rxBuf);          // store and count
        } while (Carry==0);< /tt>

        Delay_uSeg(30);  &nb sp;              ; // 1 bit delay
        nop();     ;             & nbsp;        // timming adjustment
        Carry = RxD_pin;  & nbsp;             // stop bit read
        return;   &nbs p;                      // 100 us availiable
    }
}

/*----------------------------------------------------------------------- ---*/
void main( void)
/*---------------------------------------------------------------------- ----*/
{
    OSCCAL    = W;                  &n bsp;    // Oscilator Calibration Value
    GPIO      = 0b00011000;
    TRIS      = 0b00001000;
    OPTION    = 0b10000000;  &nb sp;          // intenal pull-up enabled

    // Serial routines usage example

    char a;

    a = 0xAA;

    TxSerial(a);
    TxSerial(0x55);

    do {
        RxSerial();
    } while (Carry==0);
    a = rxBuf;

    RxSerial();
    if (Carry==1) {
        a = rxBuf;
    }
}
 
 

1999\10\06@075653 by Myke Predko

flavicon
face
Hey Stu,

Check out the Macros I wrote for Articles on:

http://www.rentron.com

The macros are designed to be placed in code very simply.

myke
{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...