Microcontroller › 8051 › IR based Vehicle over speed detector using 89c51 microcontroller
- This topic has 1 reply, 2 voices, and was last updated 7 years, 7 months ago by Ashutosh Bhatt.
-
AuthorPosts
-
April 10, 2017 at 10:23 pm #4641bandaParticipant
am trying to make an automatic speed checker for final year project using IR sensor and a microcontroller interfaced with RF TxRX module for remote reporting. however, my code in which am using interrupts is only able to detect the first car then it fails to reset. how can i go about it?
below is the code.help
/// almost done///
#include<reg51.h>
#include<string.h>
sfr LCD=0x80;
sbit RS=P2^7;
sbit EN=P2^6;
sbit led=P2^5;
unsigned int a=0, i=0, v;
unsigned int flag=0,d;
void tm();
void delay(unsigned char time)
{
unsigned int a,b;
for(a=0;a<time;a++)
for(b=0;b<1275;b++);
}
void lcdcmd(unsigned char value)
{
LCD=value;
RS=0;
EN=1;
delay(10);
EN=0;
}
void lcddata(unsigned char value)
{
LCD=value;
RS=1;
EN=1;
delay(10);
EN=0;
}
void lcd_init()
{lcdcmd(0x38);
delay(20);
lcdcmd(0x0c);
delay(20);
lcdcmd(0x01);
delay(20);
lcdcmd(0x06);
delay(20);
}
void writestr(unsigned char*s)
{
unsigned char l,i;
l=strlen(s);
for(i=0; i<l;i++)
{
lcddata(*s);
s++;
}
}
void ISR_ex0(void) interrupt 0
{
while(P3^3!=0)
{ led=0;
tm();
a++;
}
led=1;
a=0;
}
void display()
{ unsigned char m,n,temp,o;
while(IE1==0)
{
v=100/a;
m=v/100;
temp=v%100;
n=temp/10;
o=temp%10;
if (v>=60)
{lcdcmd(0x3C);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x80);
writestr("OVERSPEED DETECTED");
lcdcmd(0xc6);
lcdcmd(0x84);
lcdcmd(0xc0);
lcddata(m+48);
lcddata(n+48);
lcddata(o+48);
lcddata('K');
lcddata('M');
lcddata('/');
lcddata('H');
lcddata(' ');
lcddata(' ');
delay(1500);}
else if(v<=50)
{
lcdcmd(0x01);
writestr("SPEED:");
lcdcmd(0xc6);
lcddata(m+48);
lcddata(n+48);
lcddata(o+48);
lcddata('K');
lcddata('M');
lcddata('/');
lcddata('H');
lcddata(' ');
lcddata(' ');
EX0=0;
}
}
}
void ISR_ex1(void) interrupt 2
{
delay(1500);
display();
v=100/a;
EX0=0;
led=1;
}
void main()
{
IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
EX0 = 1; // Enable EX0 Interrupt
IT1 = 1; // Configure interrupt 1 for falling edge on /INT0 (P3.2)
EX1 = 1; // Enable EX1 Interrupt
EA=1; // Enable Global Interrupt Flag
PX1=1; // Priority of ex1 high
led=0;
led=1;
lcd_init();
lcdcmd(0x84);
lcdcmd(0xc0);
writestr("SPEED DETECTOR");
delay(1500);
while(i);
}
void tm()
{
int y=0;
for(y=0;y<15;y++)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
}
April 20, 2017 at 12:01 pm #14573Ashutosh BhattParticipanthave you disabled interrupt?
have you enabled interrupts again?
-
AuthorPosts
- You must be logged in to reply to this topic.