Serial LCD

A serial character output device is very useful for debugging digital electronics. It takes only one pin on the target device and can provide a lot of debugging information easily.

I used an Atmega8 and a Tinsharp TC1602B-08 to create the device. The microcontroller simply accepts characters from its serial input and puts them on the LCD. Here are the interpretation of the bytes it receives:

 Bit  7 6 5 4 3 2 1 0
      0 x x x x x x x    Print ASCII character.
      1 0 0 R C C C C    Go to row R, column CCCC.
      1 1 0 0 0 0 0 0    Clear screen and move to 0,0.
The serial line by default runs at 12.5kbps. This is achieved by setting UBRR=4, normal speed with a 1Mhz system clock. You can modify this setting by reprogramming the device.

The sender needs the following code.

 //
 //  Atmega8(A)
 //
#define USART_DIVIDER 4
static void Lput(uint8_t K, uint8_t dl) 
 { while(!(UCSRA&(1<<UDRE))) ; UDR= K;
   if (dl) _delay_ms(5); else _delay_us(120); }
static void Lchr(uint8_t B) { Lput(B,0); } 
static void Lclear() { Lput(192,1); }
static void Lgoto(uint8_t r,uint8_t c) 
 { Lput(128 | (r<<4) | c, 0); }
static void Lhex(uint8_t K)
 { static const char *he= "0123456789ABCDEF"; 
   Lchr((uint8_t)he[K>>4]); Lchr((uint8_t)he[K&0xf]); }
static void Linit() 
{ UBRRH= USART_DIVIDER>>8; UBRRL= USART_DIVIDER;
  UCSRC= (1<<URSEL) | (3<<UCSZ0); UCSRB= (1<<TXEN); }
You need to modify USART_DIVIDER in order to match the receiver rate if the sender has a different clock than 1Mhz.

Here is the first version.