lady_krizzie
- Aug 2, 2012
- 30
- Joined
- Aug 2, 2012
- Messages
- 30
Hi,
I'm making a project that will display characters in hyperterminal and in my LCD, whatever I pressed in my keyboard. Unluckily, I can only display right characters in the hyperterminal and strange characters in the LCD. Here is my basic code. I am using AT90USB64, Atmel Studio 6, ADM 3202, RS232 and LCD 16*2... I already search for answers and tutorials but none worked. I also include here UART library, because I learned that USB uC is not supported in free download of Atmel. Thank you in advance.
*UART code library made by my superior
I'm making a project that will display characters in hyperterminal and in my LCD, whatever I pressed in my keyboard. Unluckily, I can only display right characters in the hyperterminal and strange characters in the LCD. Here is my basic code. I am using AT90USB64, Atmel Studio 6, ADM 3202, RS232 and LCD 16*2... I already search for answers and tutorials but none worked. I also include here UART library, because I learned that USB uC is not supported in free download of Atmel. Thank you in advance.
Code:
#include <avr/io.h>
#include "uart.h"
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lcd.h"
//static FILE mystdout = FDEV_SETUP_STREAM (uart_putc, NULL, uart_getc());
int main(void)
{
hw_uart_init();
hw_lcd_init();
char foo;
char *bar;
while (1)
{
{
foo = uart_getc();
//fprintf_P(foo, ("%c"), bar);
lcd_puts_wrap(foo);
}
{
uart_putc(foo, bar);
}
}
return 0;
}
Code:
#include "uart.h"
/*
* Send one character through UART
*/
int uart_putc(char c, FILE *unused)
//int uart_putc(char c)
{
while (!(UCSR1A & (1<<UDRE1)))
;
UDR1 = c;
return 0;
}
/*
* Receive one character from UART
*/
char uart_getc(void)
{
while ((UCSR1A & (1<<RXC1)) == 0)
;
return UDR1;
}
/**
* Enable hardware uart module
*/
void hw_uart_init(void)
{
UCSR1B |= (1<<RXEN1 | 1<<TXEN1);
//UCSR1C |= (1<<UCSZ11 | 1<<UCSZ10);
UBRR1H = (BAUD_PRESCALE>>8);
UBRR1L = BAUD_PRESCALE;
}
Code:
#ifndef UART_H_
#define UART_H_
#include <stdio.h>
#include <avr/io.h>
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#define USART_BAUDRATE 9600
//#define BAUD_PRESCALE (((F_CPU*10 / (USART_BAUDRATE * 16UL+5))) - 1)
#define BAUD_PRESCALE (((((F_CPU * 10) / (16L * USART_BAUDRATE)) + 5) / 10) - 1)
void hw_uart_init(void);
int uart_putc(char c, FILE *unused);
//int uart_putc(char c);
char uart_getc(void);
#endif /* UART_H_ */
*UART code library made by my superior