I am using a PCI1602F-B from Powertip as an LCD and an ATmega8 to communicate with it.
Connection:
-PORT D of ATmega8 with data-bus of LCD
-PORT B0 of ATmega8 with Rs pin
-PORT B1 of ATmega8 with R/W pin
-PORT B2 of ATmega8 with Eneble (E) pin
-I potentiometer is connected to the Contrast Adjust pin (Vo) and I can give it 0 volt to 5 volt.
-The Backlight LED works fine.
-I also give 5 volt to Vss-Vpp
My code is as followes:
#define F_CPU 1000000UL // 1 MHz
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
void En(int bit)
{
if (bit==0)
PORTB |= 0b00000100;
else
PORTB &= ~0b0000100;
}
void RS(int bit)
{
if (bit==0)
PORTB |= 0b00000001;
else
PORTB &= ~0b0000001;
}
void RW(int bit)
{
if (bit==0)
PORTB |= 0b00000010;
else
PORTB &= ~0b0000010;
}
void is_busy (void)
{
DDRD = 0b00000000;
RW(1);
RS(0);
En(1);
while (PORTD == 0b10000000)
{
En(0);
_delay_ms(1);
En(1);
}
DDRD = 0b11111111;
}
void send_command(unsigned char command)
{
is_busy();
PORTD = command;
RW(0);
RS(0);
En(1);
_delay_ms(2);
En(0);
PORTD = 0b00000000;
}
void send_char(unsigned char character)
{
is_busy();
PORTD = character;
RW(0);
RS(1);
En(1);
_delay_ms(2);
En(0);
PORTD = 0b00000000;
}
void init(void)
{
En(0);
_delay_ms(100);
send_command(0b00110000);
_delay_ms(30);
send_command(0b00110000);
_delay_ms(10);
send_command(0b00110000);
_delay_ms(10);
send_command(0b00111000); //Function Set - DL=N=1, F=0
is_busy();
send_command(0b00000001); //Clear Display
is_busy();
send_command(0b00010100); //Cursor of Display Shift - S/C=0, R/L=1
is_busy();
send_command(0b00001100); //Display ON/OFF - D=1, C=B=0
is_busy();
send_command(0b00000110); //Entry Mode Set - I/D=1, S=0
}
int main(void)
{
init();
send_char(0x81);
while(1)
{
}
return(0);
}
As you can see I am only trying to print one letter. The letter I am trying to print it "Q". I am sending the Hex ASCII code immediately to the microcontroller.
The LCD does not show anything, have I done something wrong? Is the initialization correct?
RW
for example should be low for writing soRW(0)
looks OK, but in the function you're setting the pin high. \$\endgroup\$