just connect rx of one uC to tx of another and vice versa. But if one uC should act as a master program then it will be easy. If you are searching for serial port interface, you can use this code
/*----------------------------------------------------------------
-----------------MAIN FUNCTION------------------------------------
-----------------------------------------------------------------*/
void main()
{
unsigned char a;
//lcd initializationsa
Init_Ports();
InitUART( 25 ); /* Set the baudrate to 2400 bps using a 1MHz crystal */
for(;
/* Forever */
{
TransmitByte(0x99); /* Echo the received character */
Receive_PORT=ReceiveByte();
}
}
/*----------------------------------------------------------------
------------FUNCTIONS TO Initialize UART--------------------------
-----------------------------------------------------------------*/
void InitUART( unsigned char baudrate )
{
UBRRL = baudrate; /* Set the baud rate */
UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and transmitter */
}
/*----------------------------------------------------------------
------------FUNCTIONS TO READ UART-------------------------------
-----------------------------------------------------------------*/
unsigned char ReceiveByte( void )
{
while ( !(UCSRA & (_BV(RXC))) ); /* Wait for incomming data */
return UDR;/* Return the data */
}
/*----------------------------------------------------------------
------------FUNCTIONS TO WRITE UART-------------------------------
-----------------------------------------------------------------*/
void TransmitByte( unsigned char data )
{
while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
}
void Init_Ports(void)
{
Receive_DDR=0xFF; //setting that port for output
Receive_PORT=0XFF; //setting all bits high for starting
}
For testing uart of uC you can use this link.
http://avrmicrocontroller.googlepages.com/TestingUARTofAVRmicrocontroller.html
See fuse bits to see which frequency you are running microcontroller
Bibin John
www.bibinjohn.tk