sbit rs=P0^2;
sbit rw=P0^1;
sbit en=P0^0;
sfr ldata=0x0A0;
void lcdcmd(unsigned char);
void lcdwrt(unsigned int);
void lcddisp(unsigned char *); // for lcd
sbit cs=P3^2;
sbit wr=P3^3;
sbit rd=P3^5;
sbit intr=P3^4;
void convert(unsigned int);
void adc();
unsigned int value; // for adc0848 ic.
void delay(unsigned int);
sbit rf1=P0^4;
sbit rf2=P0^5;
sbit rf3=P0^6;
sbit rf4=P0^7; // for rf using only 3 swithches
sbit alr1=P3^6; // alarm if the bike falls left
sbit alr2=P3^7; // alarm if the bike falls right
void main()
{
P3=0xFF;
lcdcmd(0x38);
delay(10);
lcdcmd(0x0E);
delay(10);
lcdcmd(0x01);
delay(10);
lcdcmd(0x06);
delay(10);
lcdcmd(0x80);
delay(10);
lcdcmd(0xC0);
delay(10);
lcddisp("BANG BANG ");
delay(10); // LCD general initialization
adc(); // calling adc funtion;
}
void adc()
{
int check=0;
intr=1;
cs=1;
wr=1;
rd=1;
while(1)
{
P1=0x08; // Initiating the channel in among control lines
cs=0;
wr=0;
delay(50);
wr=1;
cs=1;
P1=0xFF;
while(intr==1);
cs=0;
rd=0;
delay(50);
rd=1;
value=P1;
cs=1;
convert(value);
if(rf1==1&&rf2==0&&rf3==1&&rf4==1)
{
check=20; // switch to switch off parking mode
}
if(rf1==0&&rf2==1&&rf3==1&&rf4==1)
{
check=30; // switch to switch on parking mode
}
if(rf1==1&&rf2==1&&rf3==0&&rf4==1)
{
check=40; // switch to switch on IDLE mode i.e, nothing works
}
if(check==20)
{
if(value>120)
{
lcdcmd(0xC0);
delay(10);
lcddisp("BIKE STOLEN ");
delay(10);
}
else if(value<109)
{
lcdcmd(0xC0);
delay(10);
lcddisp("BIKE PADINDHI RA ");
delay(10);
}
else
{
lcdcmd(0xC0);
delay(10);
lcddisp("SECURE ");
delay(10);
}
}
if(check==30)
{
if(value>155)
{
alr1=1;
lcdcmd(0xC0);
delay(10);
lcddisp("FALLEN RIGHT ");
delay(10);
}
else if(value<115)
{
alr2=1;
lcdcmd(0xC0);
delay(10);
lcddisp("FALLEN LEFT ");
delay(10);
}
else
{
lcdcmd(0xC0);
delay(10);
lcddisp("NORMAL POSITION ");
delay(10);
alr1=0;
alr2=0;
}
}
if(check==40)
{
lcdcmd(0xC0);
delay(10);
lcddisp("IDLE MODE ");
delay(10);
}
}
}
void convert(unsigned int temp)
{
int x,y,j;
unsigned int arr[10],i=0;
while(temp!=0)
{
x=temp/10;
y=temp%10;
arr[i++]=y;
temp=x;
}
lcdcmd(0x80);
delay(10);
for(j=i-1;j>=0;j--)
{
lcdwrt(arr[j]);
delay(10);
}
}
void lcdcmd(unsigned char val)
{
ldata=val;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcdwrt(unsigned int m)
{
ldata=0x30+m;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void delay(unsigned int x)
{
int i,j;
for(i=0;i<=x;i++)
for(j=0;j<=1275;j++);
}
void lcddisp(unsigned char *value)
{
while(*value!='\0')
{
ldata=*value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
value++;
}
}
this code is not the complete one for my project but this can display about the bike condition on the lcd screen few more changes are to be presented in my next post.
No comments:
Post a Comment