CALCULATIION:
CODE:
#include<reg51.h>
#include<string.h>
#include<stdio.h>
#define LCD_clear() LCD_command(0x01) // Clear LCD Display
#define LCD_orgin()LCD_command(0x02) //set to orgin LCD
#define LCD_row1() LCD_command(0x80) // Begin at 1st line
#define LCD_row2()LCD_command(0xc0) // Begin at 2nd line
sbit port10=P1^7; //IR Sensor Input
sbit rs=P1^0; //Lcd Register Select Pin
sbit en=P1^2; //Lcd Enable Pin
void lcd_en() //Funtion for LCD Enable
{
en=1;
en=0;
}
void LCD_delay(unsigned char ms) //Function for create Time Delay
{
unsigned int n,i;
for(n=0;n<ms;n++)
{
for(i=0;i<100;i++);
}
}
void LCD_command(unsigned char command) //LCD Command Pass Funtion
{
rs=0;
P0=command;
lcd_en();
LCD_delay(1);
}
void LCD_init() //LCD intialization funtion
{
LCD_command(0x38);
LCD_command(0x06);
LCD_command(0x0c);
LCD_command(0x01);
}
void LCD_putc(unsigned char ascii)
{
rs=1;
P0=ascii;
lcd_en();
LCD_delay(2);
}
void LCD_puts(unsigned char *lcd_string)
{
while(*lcd_string)
{
LCD_putc(*lcd_string++);
}
}
void disp(unsigned char name1)
{
rs=1;
P0=name1;
lcd_en();
LCD_delay(300);
}
void main()
{
int cnt=0;
port10=0; //make P1.0 as init=0, initially all port pins are high
LCD_init(); //call LCD initialization function
LCD_command(0x80); //LCD command for display 1st line
LCD_puts("By-krishnaraj");
LCD_command(0xc0); //LCD command for display secondline
LCD_puts("RPM="); //String display in the LCD
disp(((cnt%10000)/1000)+48);
disp(((cnt%1000)/100)+48);
disp(((cnt%100)/10)+48);
disp(((cnt%10)/1)+48);
while(1) //Run forever always true
{
if(port10==1) //check condition P2.0 is high P2.0==1
{
while(port10==1)
{ ;}
cnt=cnt+1;
LCD_command(0xc0); //LCD command for display second line
LCD_puts("RPM="); //String display in the LCD
disp(((cnt%10000)/1000)+48);
disp(((cnt%1000)/100)+48);
disp(((cnt%100)/10)+48);
disp(((cnt%10)/1)+48);
}
}
}
Working Tested ok:
- 11.0592 crystal frequency
- Microcontroller takes 12 machine cycles for execution one function.
- 1 machine cycle time = 11.0592/12 = 0.9216 Mhz
- Time= 1/0.9216 Mhz = 1.085 uS
- So when timer counts from 0000H to FFFFH (65535 counts) it take => 1.085 uS X 65535 = 0.071105 seconds
- So for a dealay of 5 seconds we should give a count value => 5 sec / 0.071105 seconds = 70.3185
- For 10 sec delay = 10 sec/ 0.071105
CODE:
#include<reg51.h>
#include<string.h>
#include<stdio.h>
#define LCD_clear() LCD_command(0x01) // Clear LCD Display
#define LCD_orgin()LCD_command(0x02) //set to orgin LCD
#define LCD_row1() LCD_command(0x80) // Begin at 1st line
#define LCD_row2()LCD_command(0xc0) // Begin at 2nd line
sbit port10=P1^7; //IR Sensor Input
sbit rs=P1^0; //Lcd Register Select Pin
sbit en=P1^2; //Lcd Enable Pin
void lcd_en() //Funtion for LCD Enable
{
en=1;
en=0;
}
void LCD_delay(unsigned char ms) //Function for create Time Delay
{
unsigned int n,i;
for(n=0;n<ms;n++)
{
for(i=0;i<100;i++);
}
}
void LCD_command(unsigned char command) //LCD Command Pass Funtion
{
rs=0;
P0=command;
lcd_en();
LCD_delay(1);
}
void LCD_init() //LCD intialization funtion
{
LCD_command(0x38);
LCD_command(0x06);
LCD_command(0x0c);
LCD_command(0x01);
}
void LCD_putc(unsigned char ascii)
{
rs=1;
P0=ascii;
lcd_en();
LCD_delay(2);
}
void LCD_puts(unsigned char *lcd_string)
{
while(*lcd_string)
{
LCD_putc(*lcd_string++);
}
}
void disp(unsigned char name1)
{
rs=1;
P0=name1;
lcd_en();
LCD_delay(300);
}
void main()
{
int cnt=0;
port10=0; //make P1.0 as init=0, initially all port pins are high
LCD_init(); //call LCD initialization function
LCD_command(0x80); //LCD command for display 1st line
LCD_puts("By-krishnaraj");
LCD_command(0xc0); //LCD command for display secondline
LCD_puts("RPM="); //String display in the LCD
disp(((cnt%10000)/1000)+48);
disp(((cnt%1000)/100)+48);
disp(((cnt%100)/10)+48);
disp(((cnt%10)/1)+48);
while(1) //Run forever always true
{
if(port10==1) //check condition P2.0 is high P2.0==1
{
while(port10==1)
{ ;}
cnt=cnt+1;
LCD_command(0xc0); //LCD command for display second line
LCD_puts("RPM="); //String display in the LCD
disp(((cnt%10000)/1000)+48);
disp(((cnt%1000)/100)+48);
disp(((cnt%100)/10)+48);
disp(((cnt%10)/1)+48);
}
}
}
Working Tested ok: