Mam dwa mikrokontrolery Atmega8 i podłączony wyświetlacz LCD do jednego z nich. Chciałbym wysłać zdanie "Hello World!" z jednego i wyświetlić na drugim. To są moje kody, które niestety nie działają - na lcd'ku wyświetlają się "krzaki".
Transmiter:
#include <avr/io.h>
//header to enable data flow control over pins
#define F_CPU 8000000UL
//telling controller crystal frequency attached
#include <util/delay.h>
//header to enable delay function in program
int main(void)
{
DDRD |= 1 << PIND1;//pin1 of portD as OUTPUT
DDRD &= ~(1 << PIND0);//pin0 of portD as INPUT
PORTD |= 1 << PIND0;
int UBBRValue = 51;//AS described before setting baud rate
//Put the upper part of the baud number here (bits 8 to 11)
UBRRH = (unsigned char) (UBBRValue >> 8);
//Put the remaining part of the baud number here
UBRRL = (unsigned char) UBBRValue;
//Enable the receiver and transmitter
UCSRB = (1 << RXEN) | (1 << TXEN);
//Set 2 stop bits and data bit length is 8-bit
UCSRC = (1 << USBS) | (3 << UCSZ0);
while (1)
{
while (! (UCSRA & (1 << UDRE)) );
{
UDR = "Hello World!";
}
}
}
Receiver:
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
int main(void)
{
LCD_Inicjuj();
DDRD |= (1 << PIND0);//PORTD pin0 as INPUT
DDRC=0xFF;//PORTC as OUTPUT
int UBRR_Value = 51; // 2400 baud rate
UBRRH = (unsigned char) (UBRR_Value >> 8);
UBRRL = (unsigned char) UBRR_Value;
UCSRB = (1 << RXEN) | (1 << TXEN);
UCSRC = (1 << USBS) | (3 << UCSZ0);
unsigned char receiveData;
while (1)
{
while (! (UCSRA & (1 << RXC)) );
receiveData = UDR;
LCD_Wyswietl(receiveData);
_delay_ms(100);
LCD_Czysc();
}
}