#include< reg52.h>
void checkconditions();
sbit rs=P3^5;
sbit rw=P3^7;
sbit en=P3^6;
sbit pcount=P2^0;
unsigned int count=0;
void delay(unsigned int no)
{
unsigned int i,j;
for(j=0;j<=no;j++)
for(i=0;i<=2;i++); 
}

void lcdcmd(unsigned int  command){
P1=command;
rw=0;
rs=0;
en=0;
delay(300);
en=1;
delay(300);
en=0;
}

void lcddata(char data1)
{
P1=data1;
rw=0;
rs=1;
en=0;
delay(300);
en=1;
delay(300);
en=0;
}
void lcdint()
{
lcdcmd(0x30);	delay(3000);	lcdcmd(0x30);	delay(3000);	lcdcmd(0x30);	delay(3000);
lcdcmd(0x30);	delay(3000);	lcdcmd(0x30);	delay(3000);	lcdcmd(0x38);	delay(3000);
lcdcmd(0x01);	delay(3000);	lcdcmd(0x0C);	delay(3000);	lcdcmd(0x80);	delay(3000);
}
void checkconditions(){
char ch1,ch2,ch3;
unsigned int Adcvalue1;
while(1){

if(pcount==1)
{
lcdcmd(0xC0);
count++;
ch1=count/100;
if(ch1!=0)
lcddata(ch1+0x30);
delay(100);
Adcvalue1=count%100;
ch2=Adcvalue1/10;
if(ch2!=0)
lcddata(ch2+0x30);
ch3=Adcvalue1-(ch2*10);
lcddata(ch3+0x30);
delay(10000);
//lcddata(count);

while(1){
if(pcount==0)
checkconditions();
}}}}

void main()
{
char u[]={"DOOR COUNTER!!!"};             
P1=0x00;
P2=0xFF;
P3=0x00;
lcdint();
 while(u[count]!='\0'){lcddata(u[count]);count++;}
 count=0;
 delay(100000);    delay(100000);          delay(100000);
 while(1){
 checkconditions();}
}
More counter and security alarm projects using different microconrollers and sensors like PIR(passive infrared), LDR(light dependent resistor), Laser light, Ultrasonic sensor etc. Each project contains free source code and circuit diagram of the project. 
Home security with arduino uno
PIR security system over WiFi using nodemcu
Download the project code and hex file compiled in keil uvision 3 and if you feel any problem in the code or you don't understand the code please write your queries below.write your comment below.
Watch The project Video Here........