shashankshanky
Newbie level 3
hi all,
i want to receive the data from the hyperterminal and set PORT A high. however no data was transferred. i also tried receiving the data from the micro-controller. Even this was not working.
Later, i tried to simulate the same using the protheus designing software. still no response. tired of these, i tried simulating the sample code available in the data sheet. i even set the required bits to zero for asynchronous operation. all my efforts are wasted. i dont know where i am going wrong. please help me solve my problem .
c code:
#include<avr/io.h>
#define FOSC 1843200// Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
void USART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (0<<URSEL)|(0<<USBS)|(3<<UCSZ0);
}
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
int main( void )
{
DDRA=0B11111111;
int i;
unsigned char recdata';
USART_Init ( MYUBRR );
for(i=0;i<10;i++)
{
recdata=USART_Receive();
PORTA=0B11111111;
}
}
i tried everything. only problem i get is during the data (transmission or receiving). neither data is being received nor transmitted .I tried simulating everything in proteus designing software. still no solution. please help me
i want to receive the data from the hyperterminal and set PORT A high. however no data was transferred. i also tried receiving the data from the micro-controller. Even this was not working.
Later, i tried to simulate the same using the protheus designing software. still no response. tired of these, i tried simulating the sample code available in the data sheet. i even set the required bits to zero for asynchronous operation. all my efforts are wasted. i dont know where i am going wrong. please help me solve my problem .
c code:
#include<avr/io.h>
#define FOSC 1843200// Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
void USART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (0<<URSEL)|(0<<USBS)|(3<<UCSZ0);
}
unsigned char USART_Receive( void )
{
/* Wait for data to be received */
while ( !(UCSRA & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR;
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
int main( void )
{
DDRA=0B11111111;
int i;
unsigned char recdata';
USART_Init ( MYUBRR );
for(i=0;i<10;i++)
{
recdata=USART_Receive();
PORTA=0B11111111;
}
}
i tried everything. only problem i get is during the data (transmission or receiving). neither data is being received nor transmitted .I tried simulating everything in proteus designing software. still no solution. please help me