Up-Down counter on 16*2 LCD using 8051 microcontroller

CIRCUIT DIAGRAM

DESCRIPTION

In this circuit 16*2 lcd IS used to show the value of count using 8051 microcontroller. The maximum value of count is 99 because. In this circuit we are using 8051-microcontroller, 16*2 lcd, 2 switches for up counting button & down counting button.

Data pins of LCD are connected to P1 port of the 8051 microcontroller. UP counter button is connected with P2.6 and down counter button is connected with P2.7.Whenever the UP counter button is pressed the counter increments by one and when the down counter button is pressed it gets reduced by one.

PROJECT CODE

#include< reg51.h >

sfr lcddata=0x90; //LCD DATA PINS
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;
sbit g=P2^6;
sbit h=P2^7;

int m=0;
int a,b;
unsigned char n[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};

void delay(unsigned char b)
{
unsigned char a;
for(b;b>0;b–)
{
for(a=500;a>0;a–);
}
}

void command(unsigned char dost)
{
lcddata=dost;
en=1;
rs=0;
rw=0;
delay(5);
en=0;
}

void lcddisplaydata(unsigned char n)
{
lcddata=n;
en=1;
rs=1;
rw=0;
delay(50);
en=0;
}

void main()
{
P2=0xFF;
command(0x38);
command(0x0C);
while(1)
{
if(g==0)
{
if(m==99)
{
command(0x80);
lcddisplaydata(n[9]);
command(0x81);
lcddisplaydata(n[9]);
}
else
{
m=m+1;
a=m/10;
{
command(0x80);
lcddisplaydata(n[a]);
}
b=m%10;
{
command(0x81);
lcddisplaydata(n[b]);
}
while(g==0);
}
}

if(h==0)
{
if(m==0)
{
command(0x80);
lcddisplaydata(n[0]);
command(0x81);
lcddisplaydata(n[0]);
}
else
{
m=m-1;
a=m/10;
{
command(0x80);
lcddisplaydata(n[a]);
}
b=m%10;
{
command(0x81);
lcddisplaydata(n[b]);
}
while(h==0);
}
}
}
}

Advertisements

2 Digit 7-Segment Up Down Counter Project using 8051 Microcontroller

DESCRIPTION

In this circuit 2 seven segment are used to show the value of count using 8051 microcontroller. The maximum value of count is 99 because 2 seven segments are used. In this circuit we are using 8051-microcontroller, 2 common cathode seven segments, 2 switches for up counting button & down counting button.

7-Segments are connected to P2 & P3 ports of the 8051 microcontroller. UP counter button is connected with P1.6 and down counter button is connected with P1.7.Whenever the UP counter button is pressed the counter increments by one and when the down counter button is pressed it gets reduced by one.

CODE

#include< reg51.h >
sbit h=P1^6; //up counter button
sbit g=P1^7; //down counter button
int m=0;
int n=0;
int a,b;
int arr[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0xFF,0x67};
void main()
{
P2=0x3F;
P3=0x3F;
while(1)
{
P1=0xFF;
if(h==0)
{
if(n==99&&m==99)
{
P2=0x67;
P3=0x67;
}
else
{
m=m+1;
n=n+1;
a=m/10;
b=n%10;
P2=arr[a];
P3=arr[b];
while(h==0);
}
}
if(g==0)
{
if(n==0&&m==0)
{
P2=0x3F;
P3=0x3F;
}
else
{
m=m-1;
n=n-1;
a=m/10;
b=n%10;
P2=arr[a];
P3=arr[b];
while(g==0);
}
}
}
}

How to interface 16*2 LCD with 8051 microcontroller

DESCRIPTION
This post is about to interface 16*2 LCD with 8051 microcontroller.The data pins of LCD is connected to P1 port of controller and the pins RS, R/W, E is connected to P3.2, P3.3, P3.4 respectively

Let’s start with connecting the LCD hardware with microcontroller (P89v51). The following table lists all pins of LCD module (JHD162A) along with their description.

Pin 1 — Vss — Ground
Pin 2 — Vdd — +5v
Pin 3 — Vee — Contrast Adjustment -2V to -5V
Pin 4 — RS — Register Select
Pin 5 — R/W — 1-Read, 0-Write
Pin 6 — E — Enable
Pin 7 — D0 — Data Line
Pin 8 — D1 — Data Line
Pin 9 — D2 — Data Line
Pin 10 — D3 — Data Line
Pin 11 — D4 — Data Line
Pin 12 — D5 — Data Line
Pin 13 — D6 — Data Line
Pin 14 — D7 — Data Line
Pin 15 — LED+ — BackLight LED +V
Pin 16 — LED- — BackLight LED -V

CODE
# include < reg51.h >
unsigned char a;
sfr lcddata=0x90; //p1 port
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;

/**********************start of program functions************************************************/
//________________________________Delay subroutine________________________________________________________________

void delay(unsigned int b)
{
unsigned int a;
for(b;b>0;b–)
for (a=75;a>0;a–);
}

/*************************LCD Routine**************************************/

void command(unsigned char dost)
{
lcddata=dost;
en=1;
rs=0; //initialise of the LCD
rw=0;
delay(5);
en=0;
}

void lcddisplaydata(unsigned char word)
{
lcddata=word;
en=1; //Data writing of the Lcd
rs=1;
rw=0;
delay(5);
en=0;
}

void displaydata(unsigned char *word)
{
int x;
for(x=0;word[x]!=0;x++) //Data writing of the LCD
{
lcddisplaydata(word[x]);
}
}
/********************************************************/

void main()
{
command(0x38);
command(0x0C);
command(0x80);
displaydata(“ELECTRONICS WORK”);
}