- This topic has 3 replies, 2 voices, and was last updated 11 years, 3 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
|
Microcontroller › AVR › looping problem in ATmega16
when i use bello progrm usart_getch function repeats only 3 times. why?
#define F_CPU 16000000 // set CPU freq.
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE F_CPU/16/USART_BAUDRATE-1
#define PUMP_CONTROL PORTC
#include<avr/io.h>
#include<util/delay.h>
#include<string.h>
void USART_Init();
void usart_putch(unsigned char send);
unsigned int usart_getch();
int main(void)
{
unsigned int c=5;
USART_Init();
while(c)
{
usart_putch(usart_getch());
c–;
}
}
void USART_Init()
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>;
UBRRL=BAUD_PRESCALE;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = 0x86; // Set frame format: 8data, 1stop bit, no parity
}
void usart_putch(unsigned char send)
{
unsigned char ucsrc;
while ( !( UCSRA & (1<<UDRE)))
;
UDR = send; // Send the byte
}
unsigned int usart_getch() //FUNCTION TO RECIVE A CHARATER.
{
while ( !(UCSRA & (1<<RXC)) );
return UDR; // return the byte
}
insted of while loop i used for, do-while also….
Hi Shashank,
For all microcontroller codes there should be an infinite loop at the end of the main function like the following
int main(void)
{
unsigned int c=5;
USART_Init();
while(c)
{
usart_putch(usart_getch());
c–;
}
while (1)
{
;
}
}
Which all keys in the keyboard are you pressing to send data to the microcontroller? If you press keys like ENTER key, they will send two characters at a time and hence you will feel that you missed one loop.
I am using cutecom for hyperterminal and to send data i press enter key.
other than enter key which key i can use to send data to mcu?
Hi,
Normally in cutecom you don’t have to press the ENTER key to send data. As soon as you press any key that data will be send to through the serial port. Check your cutecome settings.
Or you can try with some other software.
Another solution is that in your code try to compensate for the two extra characters due to ENTER key