Hello, im having big big problems programming usart0 of atmega162. Below is the code of my program. im using stk500.
please could you tell me how can i make it works?
tell me also if its possible the configuration of fuse and lock bits to compare with the one i have.
when i turn on the microcontroller (programmed) conected to the hyperterminal i doesnt anything.
i want 9600bauds, no parity, 8 bits and 1 stop bit.
believe me im dont know what to do because with atmega16 it worked well.
i dont know what im doing wrong but i hope you do. Some part in the code are in spanish, my mother tongue.
thakns you very very much.
#include <avr/io.h>
// PROTOTIPOS DE FUNCIONES UTILIZADAS
void serial_init_0 (void);
unsigned char serial_recv_0 (void);
void serial_send_0 (unsigned char);
void serial_print_0 (const char *);
/* Inicia el puerto de la UART0 */
void serial_init_0(void) {
#define BAUD 3686000/16/9600-1
UBRR0L = 23;//ESTO SE SACA DEL DATASHEET
//ACTIVAR ENVIO Y RECEPCION
UCSR0B = (1<<TXEN0)|(1<<RXEN0);
//TIPO DE FRAME
UCSR0C = (1<<URSEL0)|(1<<USBS0)|(3<<UCSZ00);
return;
}
/* ESPERAR UN CARACTER Y DEVOLVERLO UART0*/
unsigned char serial_recv_0 (void) {
/* Esperar */
while (!(UCSR0A & (1 << RXC0)));
/* Devolver lo recibido*/
return UDR0;
}
/* ENVIAR UN CARACTER UART0*/
void serial_send_0 (unsigned char c) {
/* Esperar a que el buffer de envio esté vacio*/
while (!(UCSR0A & (1 << UDRE0)));
/* poner en UDR para enviarlo */
UDR0 = c;
return;
}
/* ENVIA UNA CADENA POR EL PUERTO SERIE UART0*/
void serial_print_0 (const char *msg) {
while (*msg != 0)
serial_send_0 (*msg++);
return;
}
int main() {
int i;
serial_print_0(“Hello”);
}