Wednesday, 18 November 2015

Petrol pump automation using PIC


#include<pic.h>
void cmd(int);
void data(char);
void delay(int);
char keypad();
void gate();
void display(const char*);

void main()
{
int i,f=0,y,r=0;
char d[4],e[]="2234",l[]="000",n[]="000",s[3];

TRISB=0XF0;
TRISC=0XF0;
TRISD=0X00;
//TXSTA=0X24;
//RCSTA=0X90;
//SPBRG=0X19;
ADCON1=0X07;
TRISA=0X00;
cmd(0X38);
cmd(0X01);
cmd(0X0E);
cmd(0X06);
cmd(0X80);


if(RC5==1)
{
display("Car");
gate();
r=1;
}

else if(RC6==1)
{
display("Bus");
gate();
r=1;
}

else if(RC7==1)
{
display("Truck");
gate();
r=1;
}



if(r==1)

{
cmd(0X01);
cmd(0X80);
delay(50);

for(i=0;i<4;i++)
{
d[i]=keypad();
data(d[i]);
delay(100);
}

cmd(0X01);
cmd(0X80);


for(i=0;i<4;i++)
if(d[i]!=e[i])
f=1;
if(f==0)
{
display("Pay ");
delay(50);

cmd(0X01);
cmd(0X80);
delay(100);
for(i=0;i<3;i++)
{

s[i]=keypad();
data(s[i]);
delay(100);
}
cmd(0X01);
cmd(0X80);

y=(s[0]-48)*100+(s[1]-48)*10+(s[2]-48);
switch(y)
{
case 100:
{
PORTA=0X01;
delay(50);
PORTA=0X00;
break;
}
case 200:
{
PORTA=0X01;
delay(100);
PORTA=0X00;
break;
}
case 300:
{
PORTA=0X01;
delay(200);
PORTA=0X00;
break;
}
}
}

else
display("invalid");
delay(100);
}
}

char keypad()
{
int e;
PORTB=0XF7;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return '1';
break;
case 0XD0:
return '2';
break;
case 0XB0:
return '3';
break;
case 0X70:
return '4';
break;
}
PORTB=0XFB;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return '5';
break;
case 0XD0:
return '6';
break;
case 0XB0:
return '7';
break;
case 0X70:
return '8';
break;
}
PORTB=0XFD;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return '9';
break;
case 0XD0:
return '0';
break;
case 0XB0:
return 'A';
break;
case 0X70:
return 'B';
break;
}
PORTB=0XFE;
e=PORTB&0XF0;
switch(e)
{
case 0XE0:
return 'C';
break;
case 0XD0:
return 'D';
break;
case 0XB0:
return 'E';
break;
case 0X70:
return 'F';
break;
}
}

void display(const char *p)
{
while(*p!='\0')
{
data(*p);
p++;
}
}


void gate()
{
PORTA=0X02;
delay(100);
PORTA=0X01;
delay(100);
PORTA=0X00;
}

void cmd(int s)
{
PORTD=s;
RC0=0;
RC1=0;
RC2=1;
delay(10);
RC2=0;
}

void data(char a)
{
PORTD=a;
RC0=1;
RC1=0;
RC2=1;
delay(10);
RC2=0;
}
void delay(int a)
{
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<a;j++);
}

No comments:

Post a Comment