Tuesday, 17 November 2015

Automatic Toll system using ATMEGA32

Identify the vehicle >> authenticate the customer >> give access >> give the amount to be paid ...

#include <avr/io.h>
#include <util/delay.h>
void cmd(char);
void dat(char);
int password();
void motor();
void lcdstring(const char*);
char key();
int main(void)
{
DDRD=0xf0;
DDRA=0xff;
DDRC=0xff;
DDRB=0x00;
cmd(0x38);
cmd(0x01);
cmd(0x06);
cmd(0x0e);
cmd(0x80);
{
if ((PINB&0x01)==0)
{
lcdstring("bus");
_delay_ms(50);
cmd(0x01);
password();
}
else if ((PINB&0x02)==0)
{
lcdstring("car");
_delay_ms(100);
cmd(0x01);
password();
}
else if ((PINB&0x04)==0)
{
lcdstring("bike");
_delay_ms(100);
cmd(0x01);
password();
}
}
}
char key()
{
int e;
while(1)
{
_delay_ms(100);
PORTD=0x7f;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('1');
case 0x0b:
return('2');
case 0x0d:
return('3');
case 0x0e:
return('4');
}
PORTD=0xbf;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('5');
case 0x0b:
return('6');
case 0x0d:
return('7');
case 0x0e:
return('8');
}
PORTD=0xdf;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('9');
case 0x0b:
return('0');
case 0x0d:
return('f');
case 0x0e:
return('a');
}
PORTD=0xef;
e=PORTD&0x0f;
switch(e)
{
case 0x07:
return('s');
case 0x0b:
return('x');
case 0x0:
return('b');
case 0x0e:
return('v');
}
}
}
int password()
{
char i,a[]="123",d[4],f,S;
while(1)
{
lcdstring("enter the password");
cmd(0xc0);
for (i=0;i<=3;i++)
{
d[i]=key();
dat(d[i]);
}
for(i=0;i<=3;i++)
{
if (a[i]==d[i])
{
f=1;
}
else
{
f=0;
break;
}
}
if (f==1)
{
lcdstring("access granted");
motor();
}
else if(f==0)
{
lcdstring("not granted");
}
}
}
void motor()
{
cmd(0x01);
cmd(0x80);
if ((PINB&0x01)==0)
{
PORTA=0xff;
_delay_ms(100);
lcdstring("your bill");
cmd(0xc0);
lcdstring("rs 1000");
}
else if((PINB&0x02)==0)
{
PORTA=0xf6;
_delay_ms(100);
lcdstring("your bill");
cmd(0xc0);
lcdstring("rs 500");
}
else if((PINB&0x04)==0)
{
PORTA=0x77;
_delay_ms(100);
lcdstring("your bill");
cmd(0xc0);
lcdstring("rs 100");
}
}
void cmd(char p)
{
PORTC=p;
PORTA=0x20;
_delay_ms(100);
PORTA=0x00;
}
void dat(char e)
{
PORTC=e;
PORTA=0x30;
_delay_ms(100);
PORTA=0x10;
}
void lcdstring(const char*s)
{
while(*s)
{
dat(*s++);
}
}

No comments:

Post a Comment