Searching \ for 'Serial comunication using PIC16X84' 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/microchip/ios.htm?key=serial
Search entire site for: 'Serial comunication using PIC16X84'.

Truncated match.
PICList Thread
'Serial comunication using PIC16X84'
1999\09\14@173359 by YeYo Man

flavicon
face
I need to stablish a connection beetwen a PIC16X84 and the PC trought
the serial port. I would appreciate very much if someone already has a
WORKING routine for this purpose, I need to send and receive bytes. And
using the max232 would be great.

Thanks in advanced.

1999\09\14@214137 by Myke Predko

flavicon
face
Hiya,

You might want to take a look at the macros that I developed and wrote about
at:

http://www.rentron.com/Myke7.htm

I have published a couple of macros that provide bit-banging NRZ serial for
the PICMicro that should fit the software bill for you.

myke
----- Original Message -----
From: YeYo Man <spam_OUTyeyomanTakeThisOuTspamTELELINE.ES>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Tuesday, September 14, 1999 6:27 PM
Subject: Serial comunication using PIC16X84


> I need to stablish a connection beetwen a PIC16X84 and the PC trought
> the serial port. I would appreciate very much if someone already has a
> WORKING routine for this purpose, I need to send and receive bytes. And
> using the max232 would be great.
>
> Thanks in advanced.
>

1999\09\15@125036 by Jose Souto

flavicon
face
This code may be compiled to 16F84 changing the 12c508.h file
Sorry for the tabs, cut&paste missed it.

BR's
J Souto

/*--------------------------------------------------------------------------+
| Asynchronous Serial communication routines for 12c508                    |
| Author: Jose Luiz Pinto Souto                                            |
| soutospamKILLspamcryogen.com                                                        |
| 9600 BPS, 1 start bit, 8 data bits, 1 stop bit                           |
|             |
| Compiled with CC5xFree from http://www.bknd.com        |
+--------------------------------------------------------------------------*/

/*
** 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;   // start bit
       for (idx=10; idx; idx--) { // 3us
           _TxOUT = Carry;  // 4us
           Delay_uSeg(28);  // 91us (28*3+7)
           Carry  = 1;   // 1us
           txBuf  = rr(txBuf);  // 1us
           nop();   // 1us
       }    // 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;    // 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);   // 1/2 bit delay (14*3+7)
if (RxD_pin)
           continue;   // false start bit detection

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

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

       Delay_uSeg(30);   // 1 bit delay
       nop();    // timming adjustment
Carry = RxD_pin;  // stop bit read
       return;    // 100 us availiable
   }
}

/*--------------------------------------------------------------------------*/
void main( void)
/*--------------------------------------------------------------------------*/
{
   OSCCAL    = W;   // Oscilator Calibration Value
   GPIO      = 0b00011000;
   TRIS      = 0b00001000;
   OPTION    = 0b10000000;  // 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;
   }
}

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