aameer
Full Member level 4
- Joined
- May 12, 2010
- Messages
- 216
- Helped
- 33
- Reputation
- 64
- Reaction score
- 32
- Trophy points
- 1,308
- Location
- Bangalore
- Activity points
- 2,503
i want to interface dc 12v dc fan to micro controller and with 2 switches i want to increase or decrease the speed of the fan ,simultaneously i want to measure the rpm of that fan and display on LCD. i just now started to interface LCD and switches. how to proceed please guide me.
i am using at89c52 micro controller and Kiel u vision 4 for c programming.
Please its urgent
i am using at89c52 micro controller and Kiel u vision 4 for c programming.
Please its urgent
Code:
#include<reg51.h>
#define lcd_data_port P1
sbit lcd_rs = P0^0;
sbit lcd_en = P0^1;
sbit inc_key=P2^0;
sbit dec_key=P2^1;
void lcd_initial(void);
void lcd_initial_msg(void);
void lcd_cmd(unsigned char cmd_value);
void lcd_data(unsigned char data_value);
void lcd_data_string(unsigned char *string);
void delay_ms(unsigned int delay_value);
void main()
{
lcd_initial();
delay_ms(100);
lcd_initial_msg();
delay_ms(100);
while(1)
{
if(inc_key==0)
{
}
else if(dec_key==0)
{
}
}
}
void lcd_initial_msg(void)
{
lcd_cmd(0x01);
lcd_data_string(" PWM & RPM ");
lcd_cmd(0xC1);
lcd_data_string("with DC Fan");
delay_ms(300);
lcd_cmd(0x01);
}
void lcd_initial(void)
{
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x38);
lcd_cmd(0x0C);
}
void lcd_cmd(unsigned char cmd_value)
{
lcd_data_port = cmd_value;
lcd_rs = 0;
lcd_en = 1;
delay_ms(2);
lcd_en = 0;
}
void lcd_data(unsigned char data_value)
{
lcd_data_port = data_value;
lcd_rs = 1;
lcd_en = 1;
delay_ms(2);
lcd_en = 0;
}
void lcd_data_string(unsigned char *string)
{
unsigned char m=0;
while(string[m]!='\0')
{
lcd_data(string[m]);
m++;
}
}
void delay_ms(unsigned int delay_value)
{
unsigned int x,y;
for(x=0;x<delay_value;x++)
for(y=0;y<1275;y++);
}