I am trying to program arduino's atmega328p serial communication registers myself. After referring to several resources on the internet I have arrived at the following code:
I am trying to transmit 'a' to a serial lcd. Though the serial lcd displays 'a', the data on the lcd resets continuously.
Is there any solution to this issue ? Is there any error in the code written.
Is this problem specific to arduino.
Code:
#define BAUDRATE(BAUD) (((F_CPU/(BAUD*16UL)))-1)
class serials
{
serials()
{
UBRR0H = BAUDRATE(9600) >> 8;
UBRR0L = BAUDRATE(9600);
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(TXCIE0);
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
}
void transmit(unsigned char);
};
void serials::transmit(unsigned char data)
{
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = data;
}
Code:
void loop()
{
serials lcdtransmit;
lcdtransmit.transmit(254);
lcdtransmit.transmit(1);
lcdtransmit.transmit(254);
lcdtransmit.transmit(128);
lcdtransmit.transmit('a');
while(1);
}
Is there any solution to this issue ? Is there any error in the code written.
Is this problem specific to arduino.