Microcontroller › 8051 › Speed Calculation using 8051 uC
- This topic has 4 replies, 3 voices, and was last updated 9 years, 5 months ago by
Ashutosh Bhatt.
Viewing 5 posts - 1 through 5 (of 5 total)
-
AuthorPosts
-
July 9, 2012 at 12:02 am #3859
talal
ParticipantHello everybody,
I am trying to measure the speed of a machine using IR sensor interfaced with the 8051 microcontroller. I am using proteus for simulation. While running the simulation, when I provide external interrupt using push button, the value displayed on LCD is in thousands while I am only using a counter to increment once for each external interrupt so that I can know the distance through number of interrutions and divede it with time(using a timer for this purpose) to calculate the speed. I don't seem to understand the problem. It is probably due to the reason that external interrupt duration should be only for a few microseconds !!
Need your help on this. Here is the code:
#include <reg51.h>#include <stdio.h>sfr output= 0x90;sbit RS= P2^0;sbit RW= P2^1;sbit EN= P2^2;sbit test= P1^7;int timer;int counter;void InitializeLCD(void);void datadisplay(unsigned char value);void command(unsigned char num);void ready(void);void delay(void);void func_ext_intr() interrupt 2{counter = counter + 1;}void timer0(void) interrupt 1{TF0 = 0;TH0 = 0x00;TL0 = 0x00;TR0 = 1;timer = timer + 1;if (timer == 420){timer = 0;}}//////////////////////////////Main Routine////////////////////////////////int main(void){int i=0;unsigned int count=0;unsigned int speed=0;unsigned int test;char onscreen[]="SPEED";char value[6];IE = 0x8E;////////////////////////////STARTING TIMER///////////////////////////////TMOD = 0x21; // setting timer 1 for serial communication and timer 0 for timeTH0 = 0x00;TL0 = 0x00;TR0 = 1;InitializeLCD();for(i=0;onscreen!='