.: EMICROS :.  Embedded Micro Software
Home CAN232 CANUSB I2C232 I2CUSB CanWiser Learn C
Add your text here
Contact

Email : info@emicros.com

Ordering Information

.: Ordering using our PayPal powered shopping cart (PayPal account not required).

CAN232 : $79
CANUSB : $89
I2C232 : $79

I2CUSB : $89

Click here to View Cart and check out.

 

 

 

 
The serial channel needs to be configured before it can be used. The function SetupCommPort() shown here sets the port pins, the baud rate register, the transmit control register, and then the receive control register.

Ther serial port uses RC7 to receive and RC6 to transmit. The data direction for these pins must be set as input for RC7/RX (TRISHC7=1;) and output for RC6/TX (TRISC6=0;).

The Baud Rate Register is set to a value passed to the function. This value is a constant defined in the serial.h file and can be set to 9600, 19200, 57600, or 115200 baud.

The Transmit Status and Control Register configures the transmitter and the only bit that is set is the TXEN bit to enable the transmitter.

In the Receive Status and Control Register (RCSTA) the receiver is enabled (CREN=1) and also the Serial Port Enable Bit is set to enable both the transmitter and receiver.

 

/* ---------------------------------------------
// function: SetupCommPort( unsigned char baud )
// description: This function configures the 
//   serial channel.
// The baud rate setting is passed to it
// and the values defined in the serial.h file.
// -------------------------------------------*/
void SetupCommPort( unsigned char baud )
{
   TRISC7 = 1; /* Set the RX pin as output */
   TRISC6 = 0; /* Set the TX pin as input */
  /* ---------------------------------------
  // Set the baud rate register with the
  // value passed to it.
  // -------------------------------------*/
  SPBRG = baud;

  /* --------------------------------------
  // Set Transmit Status & Control Reg
  // Bit 7 CSRC = 0 Don't care for async mode
  // Bit 6 TX9 = 0 Select 8 bit trans mode
  // Bit 5 TXEN = 1 Enable transmitter
  // Bit 4 SYNC = 0 Asynchronous mode
  // Bit 3 unused=0 unused bit
  // Bit 2 BRGH = 0 Select low speed mode
  // Bit 1 TRMT = 0 Trans Stat bit (read only)
  // Bit 0 TX9D = 0 9th bit if TX9=1 (not used)
  // ----------------------------------------*/
  TXSTA = 0b00100000;

  /* -----------------------------------------
  // Set the Receive Status & Control Reg
  // Bit 7 SPEN = 1 Serial Port Enable Bit
  // Bit 6 RX9 = 0 Select 8 bit receive mode
  // Bit 5 SREN = 0 Single Rec Mode (not used)
  // Bit 4 CREN = 1 Cont Rec Enabled
  // Bit 3 ADDEN= 0 Disable Address Detection
  // Bit 2 FERR = 0 Framing Error (read only)
  // Bit 1 OERR = 0 Overrun Error (read only)
  // Bit 0 RX9D = 0 9th bit if RX9=1 (not used)
  //------------------------------------------*/
  RCSTA = 0b10010000;
}

 
 
Copyright 2010 Embedded Micro Software. All rights reserved