Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F43K22 serial communication

Status
Not open for further replies.

binojkumar

Full Member level 3
Joined
Jul 19, 2004
Messages
151
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Location
Bangalore
Activity points
983
Hi friends im new in PIC18F43K22, I need a serial communication(transmision and reception in 9600 bd rate) Code in C for this controller..pls help me.

Thanks in advance
 

This is for PIC18F4550. Modify accordingly.

//#define USE_OR_MASKS
#include <P18f2550.h>
#include <usart.h>
//-------------------------------Configuration setting ----------------------------------------------

unsigned char Rxdata[25];
unsigned char Txdata[] = "MICROCHIP_USART";

// BAUD_RATE_GEN is calculated as = [Fosc / (64 * Desired Baudrate)] - 1
// It needs to be changed depending upon oscillator frequency.
// 8MHz / (64 * 2400) - 1 = 51 (approx.)
#define BAUD_RATE_GEN 51 // Fosc = 8MHz, Baud Rate = 2400 bps

void main(void)
{
//-------------------------configure USART ---------------------------------------------------------
// API configures USART for desired parameters:
// - TX/RX interrupts turned off
// - Asynchronous mode
// - 8 bits
// - Continuous Receive Enabled
// - Low speed baud rate generator mode (Fosc / 16)
OpenUSART(USART_TX_INT_OFF | USART_RX_INT_OFF | USART_ASYNCH_MODE | USART_EIGHT_BIT | USART_CONT_RX | USART_BRGH_LOW, BAUD_RATE_GEN);
//baudUSART(BAUD_8_BIT_RATE | BAUD_AUTO_OFF);


//------------USART Transmission ----------------------------------------------------------------
putsUSART((char *)Txdata); // transmit the string

//-----------USART Reception ---------------------------------------------------------------------
getsUSART((char *)Rxdata, 24); // receive data up to 24 bytes
Rxdata[24] = 0; // NULL terminate the string for putsUSART call.
putsUSART((char *)Rxdata); // echo back the data recieved back to host

CloseUSART();
while(1); // end of program
}
 

thank u, but which ide and compiler i should use to support this API functions?
 

MPLAB and mcc18 or C18 compiler :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top