Sunday, April 25, 2010

Program for accelerometer

#include
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.

Saturday, April 24, 2010

My project about to end

Its been a long long time since i wrote a blog . hmmm yes i am certainly busy with project. There are many things which i shd share firstly i shd share the problems that i had. First and the foremost is the problem due to loose connection about 2 days got wasted first was the loose connection was with whole circuit. I got the accelerometre output on lcd screen in my home but problem is that when i tried to show that to kotesh sir i could get it. I tried it for the whole day and still not good enuf at the end of the day when i tried to bend the circuit i found the output that was a big joke becoz on the whole day i couldn find the idea to do that more over lcd is showing some number that is 255 constantly which is actually misleading me .
Next problem was with rf previously i along with pragna done the rf module but i changed the ic this time i am using ht12d and e. And guess what i spent the whole day to get the link established that is vt of decoder but couldn do that even kotesh sir dont know this so he got that kit which he brought it frm outside and started comparing constantly at the end of the day the faculty who got all those kits came to us when kotesh sir asked him to check out the problem . he just came in and pressed the rf receiver inside and every thing started working well. Bull shit we wasted almost a day for this rit now i am doing with my accelerometer to get conformed when the bike fells down . It is on its way. I will try to complete by tomorrow