serial port
//Program to get a serial data from RS232 (using HyperTerminal)..
// and sending it back to the RS232 (to HyperTerminal).
#include<avr/io.h>
#include<avr/interrupt.h>
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
void usart_init();
// --------------------------------------------
int main()
{
usart_init(); // initialization of USART
sei(); // Enable global interrupt
for (;;) // infinite loop
{
// Do Nothing
}
}
void usart_init()
{
UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); // Turn on the transmission reception ..
// circuitry and receiver interrupt
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..
// into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}
ISR (USART_RXC_vect)
{
unsigned char value;
value = UDR; // Fetch the received byte value into the variable "value"
UDR = value; //Put the value to UDR
}