Microcontroller › AVR › I have ATMEGA 16 i want to serial communication to pc terminal.
- This topic has 4 replies, 3 voices, and was last updated 12 years ago by
Pulkit Prajapati.
Viewing 5 posts - 1 through 5 (of 5 total)
-
AuthorPosts
-
February 25, 2013 at 4:19 am #2136
Pulkit Prajapati
ParticipantI have ATMEGA 16 i want to serial communication to pc terminal.I got garbage value at any baudrate.and in simulation nothing display in virtual terminal….
following is my code
#define BAUD_PRESCALE 79#include<avr/io.h>#include<util/delay.h>void usart_init();void usart_putch(unsigned char send);int main(){ unsigned char send;_delay_ms(50); // delay of 50 mili secondsusart_init(); // initialization of USARTwhile(1){send =8;usart_putch(send); // send data back to the PC (HyperTerminal)}return 0;}void usart_init(){UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitryUCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizesUBRRH = (BAUD_PRESCALE >>;
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value.. // into the low byte of the UBRR register// 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)) == 0){}; // Do nothing until UDR is ready..// for more data to be written to itUDR = send; // Send the byte}sir plz help me quick….thanx in advance..February 25, 2013 at 6:52 am #9179jagadeesh
ParticipantHi..
check this functions once….
//UART0 initialize// desired baud rate: 9600// actual: baud rate:9600(0.2%)// char size: 8 bit// parity: Disabledvoid UART_Init(void){// At 4MHz oscillatorint baud = 25;/* Set baud rate */UBRRH = (unsigned char)(baud>>;
UBRRL = (unsigned char)baud;/* Enable Receiver and Transmitter *///RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8UCSRB = 0;UCSRB = (1<<RXCIE)| (1<<RXEN) | (1<<TXEN);/* Set frame format: 8data, 1stop bit *///URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOLUCSRC = 0;UCSRC = (1<<URSEL)| (1<<UCSZ1)| (1<<UCSZ0);}void UART_TransmitByte( unsigned char data ){/* Wait for empty transmit buffer */while ( !( UCSRA & (1<<UDRE)) );/* Put data into buffer, sends the data */UDR = data;}February 25, 2013 at 9:18 am #9180Pulkit Prajapati
Participantit show me for p-> x…
February 27, 2013 at 6:09 pm #9192AJISH ALFRED
ParticipantMay be hardware issue. Please post your circuit diagram
March 1, 2013 at 8:12 am #9211Pulkit Prajapati
Participant -
AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.