serialcom.h

Serial port funtions to allow non-blocking read and write (hardware UART). Useful for debugging without changing all the timing, and for general use of serial port. (by Jonathan Bisson).



/********************************************************************
    Filename:   serialCom.h
    Created:    Sunday, October 05, 2003
    Author(s):  Jonathan Bisson
    History:
    
    Purpose:    Serial port funtions to allow non-blocking read and write (hardware UART).
                Useful for debugging without changing all the timing, and
                for general use of serial port.  Functions uses circulars buffers
                with size define by RX_BUFFER_SIZE and TX_BUFFER_SIZE.
                
                The baud rate is define by BAUD.
                
                serialInit() must be call before activate interruption
                interruptRx() and interruptTx() must be call in the interrupt() function

    Copyrights(c) 2003
*********************************************************************/
#ifndef _SERIALCOM_H_
#define _SERIALCOM_H_


#include <system.h>

//Define the size of the buffers
#define RX_BUFFER_SIZE 8
#define TX_BUFFER_SIZE 8

//Define the baud rate

//#define BAUD 129   //9600bps@20MHz (error = 0,16%)
//#define BAUD 64    //19200bps@20MHz (error = 0,16%)
#define BAUD 31    //38400bps@20MHz (error = 1,7%)
//#define BAUD 21    //57600bps@20MHz (error = 1,36%)

//#define BAUD 0x19   //9600bps@4MHz (error = 0,16%)
//#define BAUD 0x0c   //19200bps@4MHz (error = 0,16%)
//#define BAUD 0x05   //38400bps@4MHz (error = 8,5%)
//#define BAUD 0x03   //57600bps@4MHz (error = 8,5%)

//Variables uses by serialCom function
char rxBuffer[RX_BUFFER_SIZE];
char rxByteCount;
char rxIn;
char rxOut;

char txBuffer[TX_BUFFER_SIZE];
char txByteCount;
char txIn;
char txOut;

//Functions
void serialInit();

void interruptRx();
void interruptTx();

char getRxByteCount();
char getChar();

char getTxByteCount();
void putChar(char character);
void sendString(const char * string);
void sendHex(char number);

#endif



http://www.sourceboost.com/home.html

Copyright © 2002-2006 SourceBoost Technologies