[SOLVED] Serial Communication Problem in Atmega32

Status
Not open for further replies.

Briez

Member level 5
Joined
Nov 30, 2012
Messages
83
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Visit site
Activity points
1,835
I Want to communicate PC with atmega32 so i wrote a c code for it and made hardware for it, But communication doesn't work...........

Someone Please help me to sort out this Problem,

I am Providing My Circuit and C code..........

Code:
#define F_CPU	8000000UL
#include<avr/io.h>
#include<util/delay.h>
#include"LCD.h"

#define BAUD 9600
#define MYUBRR (((F_CPU / (BAUD* 16UL))) - 1)

void uart_init();
void transmit( unsigned char data );
unsigned int usart_getch();

	uint8_t mybyte;
	unsigned char count=0;
int main(void)

{

	DDRB|=0xFF;
	DDRA|=0xF0;

	lcd_init();	
	uart_init();

while(1)
	{
		mybyte=usart_getch();	// get data from serial port
		lcd_cmd(0xC0);			
		lcd_data1(mybyte);		// write data to LCD
		transmit(mybyte);		// send data back to the PC (HyperTerminal)
	}
return 0;
}
void uart_init()
{
/* Set baud rate */
UBRRH = (uint8_t)(MYUBRR>>8);
UBRRL = (uint8_t)MYUBRR;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
}

void transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) );
/* Put data into buffer, sends the data */
UDR = data;
}

 
unsigned int usart_getch()
{
	while ((UCSRA & (1 << RXC)) == 0);
				// Do nothing until data have been received and is ready to be read from UDR
	return(UDR); // return the byte
}

 

Thank you a lot for Reply
But,
My Dear Friend,
I can understand your kind reply but i want to make serial communication without use of Interrupt, the code given above by me was taken from expert website but i am facing problem on that.........
Please give me solution without use of interrupt technique......

Please Reply me fast i want to implement it Urgently.......... Thanks....
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…