[vc_row][vc_column width=”1/1″][vc_column_text]LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16×2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on.
In this post, we will look how to use pcDuino to drive a 16×2 LCD display.
[/vc_column_text][vc_tour][vc_tab title=”BOM” tab_id=”1384494514-1-5″][vc_column_text]1. pcDuino experiment platform
2. LCD 16×2 module
3. Potentiometer
4. Resistor with a value of 220ohm
5. Jump wire[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1384494514-2-42″][vc_column_text]
- D4 of LCD to D4 of pcDuino
- D5 of LCD to D5 of pcDuino
- D6 of LCD to D6 of pcDuino
- D7 of LCD to D7 of pcDuino
- RS of LCD to D8 of pcDuino
- E of LCD to D9 of pcDuino
The actual setup is as following:
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1384494864454-2-1″][vc_column_text]The code can be downloaded from here ( lcd1602).
#include "core.h"
#define RS 8
#define EN 9
#define backlight 10
#define RS_L digitalWrite(RS,LOW)
#define RS_H digitalWrite(RS,HIGH)
#define EN_L digitalWrite(EN,LOW)
#define EN_H digitalWrite(EN,HIGH)
int DB[] = {7,6,5,4};
/********************************************************************/
void write_command(int command)
{
int i,temp;
RS_L;
EN_L;
temp=command & 0xf0;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB[i],HIGH);
else digitalWrite(DB[i],LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
temp=(command & 0x0f)<<4;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB[i],HIGH);
else digitalWrite(DB[i],LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
}
/********************************************************************/
void write_data(int dat)
{
int i=0,temp;
RS_H;
EN_L;
temp=dat & 0xf0;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB[i],HIGH);
else digitalWrite(DB[i],LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
temp=(dat & 0x0f)<<4;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB[i],HIGH);
else digitalWrite(DB[i],LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
}
/********************************************************************/
void LCD_write_char( int x,int y,int dat)
{
int address;
if (x ==0) address = 0x80 + y;
else address = 0xC0 + y;
write_command(address);
write_data(dat);
delayMicroseconds(10);
}
/********************************************************************/
void lcd1602_init()
{
int i = 0;
pinMode(RS,OUTPUT);
pinMode(EN,OUTPUT);
pinMode(backlight,OUTPUT);
digitalWrite(backlight,HIGH);
for (i=0; i < 4; i++)
{
pinMode(DB[i],OUTPUT);
}
delay(100);
write_command(0x28);
delay(50);
write_command(0x06);
delay(50);
write_command(0x0c);
delay(50);
write_command(0x80);
delay(50);
write_command(0x01);
delay(100);
}
/********************************************************************/
void setup (void)
{
lcd1602_init();
}
/********************************************************************/
void loop (void)
{
write_command(0x02);
LCD_write_char(0,2,'W');
LCD_write_char(0,3,'e');
LCD_write_char(0,4,'l');
LCD_write_char(0,5,'c');
LCD_write_char(0,6,'o');
LCD_write_char(0,7,'m');
LCD_write_char(0,8,'e');
LCD_write_char(0,10,'t');
LCD_write_char(0,11,'o');
LCD_write_char(1,4,'p');
LCD_write_char(1,5,'c');
LCD_write_char(1,6,'D');
LCD_write_char(1,7,'u');
LCD_write_char(1,8,'i');
LCD_write_char(1,9,'n');
LCD_write_char(1,10,'o');
while(1);
}
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.