Simple 16*2 LCD driver with PIC16F887

In good old days,using a LCD display on a DIY project was quite trouble some.But now it has become much cheaper and simpler to use a LCD in a such project.Here,we are going to use industry defacto Hitachi HD44780 controller base one from ebay.fro US$ 2.89 including shipping.You can see it here.

Next part is the microcontroller base driver unit.I’m using PIC16F887 as the microcontroller here as I’m going to do some other stuffs with it in upcoming posts Winking smile. PIC16F887 is really nice uC with internal oscillator upto 8Mhz.So,we don’t have to use external clock source or crystal for non-timing critical application Smile The whole circuit will be simpler to be build and cheaper due to less components.

My choice of programming language is Mikro C Pro as it has many in-built functions.You can get the free demo version as on my previous post.

Let’s look at the schematic diagram Smile


I’m using PicKit2 programmer I built earlier to program the uC using ICSP.The variable resistor connected to VO pin of the LCD is used to change contrast of the LCD.For testing,I’m going to powerup the whole thing using the ICSP port(from +5V via the USB port itself to the PK2 programmer).The LED used for just for monitoring Winking smile 

Let’s look at the MikroC code,

sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;

sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;

void main() {
    osccon = 0x70;
    ansel  = 0;
    anselh  = 0;
    trisb = 0;
    trisd = 0;


The first few lines are used to define the pins used for the LCD library.You can find more information about that from here.Then,I have set the internal clock to 8Mhz as on the 4.2 section(page 62) of the PIC16F887 datasheet.Check there to find information on how to set different internal clock frequencies other than 8Mhz.Then,ANSEL registered are selected to disable analog input pins(ANx) as I use them as Digital IO pins on my project.The LCD is initialized and Lcd_Out(row,column,”text”) command is used to output characters to the LCD display.Isn’t that so simple Winking smile (I think the above syntax is self explanatory Winking smile )

Make sure to select appropriate configuration bits for the project.We have to used oscillator type as internal as below.


Now it is the time to check the built and tested circuit Winking smile




Share on Google Plus
    Blogger Comment


Post a Comment