Mantra counting machine using 8051 micro- controller.

SOFTWARE: KEIL MICRO VISION 4

SIMULATOR:  PROTEUS 8.0

CIRCUIT DIAGRAM:



WORKING:

This project is about Mantra counting machine using 8051.In this project,user will be able to count upto 5000 mantras.

Lcd display is used to display the count.Data pins of the display are connected to port 1 and control pins (RS,R/W,E) are connected to p3.7,p3.6,p3.5 respectively.

Three buttons(start,stop,reset) are used which are connected to p2.0,p2.6,p3.4 respectively.

Working of the buttons are as follows:

START:

Whenever user presses this button after chanting a mantra counter get incremented by one.Thus mantras get counted.

This button needs to be pressed after chanting a mantra otherwise counter will not get incremented and lcd will display the present value of the count.

STOP:

When this button is pressed,counter stops counting and LCD will displayed the total count of mantras.

If the user pressed the 'START' button after pressing this button counter will start counting from the last value of the count.

RESET:

When this button is pressed counter gets reset and it will started counting from the first count.

This is how the project get worked.

PROGRAM:

LCD header file:

#include<reg51.h>

sbit RS = P3^7;

sbit RW = P3^6;

sbit EN = P3^5;

void delay(int t);

void lcd_init(void);

void lcd_command(char c);

void lcd_data(char d);

void str(char a[]);

void lcd_init(void)     // function for initialization of lcd

{

lcd_command(0x38);

lcd_command(0x01);

lcd_command(0x0f);

lcd_command(0x06);

lcd_command(0x0c);

lcd_command(0x80);

}

void lcd_command(char c) // function to execute command

{

P1=c;

RS=0;

RW=0;

EN=1;

delay(5);

EN=0;

delay(5);

}

void lcd_data(char d)  // function to display data

{

P1=d;

RS=1;

RW=0;

EN=1;

delay(5);

EN=0;

delay(5);

}

void delay(int t)         // delay function

{

int j;

for(j=0;j<t*1275;j++);

}

void str(char a[]) // function to display string

{

int j;

for(j=0;a[j]!='\0';j++)

{

lcd_data(a[j]);

}

}

一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一

Main Program:

#include<reg51.h>

#include<string.h>

#include<LCD.h>


sbit start=P2^0;         // START button

sbit stop=P2^6;        // STOP button

sbit reset=P3^4;      // RESET button

unsigned int q,r,s,t,i=0;

void print(unsigned int p);

void main()

{

lcd_init();             // initialization of lcd

while(1)

{

if((start==0)&&(stop==1)&&(reset==1))  // start button

{

i++;

if(i<=5000)

{

while(start==0)

{

print(i);

}

start=1;

}

}

if((reset==0)&&(start==1)&&(stop==1)) // reset button

{

i=0;

}

if((stop==0)&&(start==1)&&(reset==1)) // stop button

{

lcd_command(0x80);

str("Total count:");

print(i);

}

}

}

void print(unsigned int p)  // function to display number upto 5000

{

if(p<10)

{

q=p+48;

lcd_data(q);

lcd_command(0x01);

}

else if((p>=10)&&(p<=99))

{

q=p/10;

q=q+48;

r=p%10;

r=r+48;

lcd_data(q);

lcd_data(r);

lcd_command(0x01);

}

else if((p>=100)&&(p<=999))

{

q=p/100;

q=q+48;

r=((p%100)/10);

r=r+48;

s=p%10;

s=s+48;

lcd_data(q);

lcd_data(r);

lcd_data(s);

lcd_command(0x01);

}

else if((p>=1000)&&(p<=5000))

{

q=p/1000;

q=q+48;

r=((p%1000)/100);

r=r+48;

t=(((p%1000)%100)/10);

t=t+48;

s=p%10;

s=s+48;

lcd_data(q);

lcd_data(r);

lcd_data(t);

lcd_data(s);

lcd_command(0x01);

}


VIDEO:








Note:

1.Please refer the below link to know the interfacing of lcd.

http://embeddedprojects222.blogspot.com/2020/07/lcd-interfacing-using-8051-micro.html

2.Please refer the below link to know how to display numbers on an lcd.

http://embeddedprojects222.blogspot.com/2020/07/how-to-display-number-on-lcd.html


Comments

Popular posts from this blog

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

how to display numbers on lcd?

Introduction of IODIR,PINSEL,IOSET and IOCLR Registers