- This topic has 0 replies, 1 voice, and was last updated 10 years ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
|
Microcontroller › AVR › please help me to find error in this code
its not showing anything on hyperterminal
#include <avr/io.h>
#include <avr/delay.h>
#define F_CPU 12000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();
unsigned char value;
int main(void)
{
usart_init(); // initialization of USART
value=usart_getch(); // get data from serial port
usart_putch(value); // send data back to the PC (HyperTerminal)
return 0;
}
void usart_init()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
// Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (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 >> ; // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}
void usart_putch(unsigned char send)
{
while (!(UCSRA & (1 << UDRE))); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte
return 0;
}
unsigned int usart_getch()
{
while (!(UCSRA & (1 << RXC)));
// Do nothing until data have been received and is ready to be read from UDR
return(UDR); // return the byte
}