Fan Speed With Adc

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include<reg51.

h>
#define DATA P0
#define ADC P3
sbit rs=P2^0;
sbit e=P2^1;
sbit triac=P2^2;
sbit
sbit
sbit
sbit
sbit
sbit
sbit
sbit

ALE=P1^2;
SOC=P1^1;
OE=P1^0;
EOC=P1^3;
SET0=P1^4;
SET1=P1^5;
SET2=P1^6;
CLOCK=P1^7;

unsigned char adc_val;


unsigned char temp[5];
void delay(int x)
{
int i,j;
for(j=0;j<x;j++)
for(i=0;i<1275;i++);
}
void clock(void)
{
int a,b;
for(b=0;b<=1000;b++)
{
for(a=0;a<30;a++);
CLOCK=~CLOCK;
}
}
void lcd_cmd(unsigned char dat)
{
DATA=dat;
rs=0;
e=0;
delay(5);
e=1;
}
void lcd_data(unsigned char dat)
{
DATA=dat;
rs=1;
e=0;
delay(5);
e=1;
}
void lcd_init(void)
{
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0e);
delay(5);
lcd_cmd(0x06);
delay(5);

lcd_cmd(0x01);
delay(5);
lcd_cmd(0x80);
delay(5);
}
void lcd_put(unsigned char *str)
{
while(*str!='\0')
{
lcd_data(*str);
str++;
}
}
void pwm (unsigned char speed)
{
triac=0;
delay(speed);
triac=1;
delay(255-speed);
}
void main(void)
{
lcd_init();
lcd_put("DIGITAL O/P ");
while(1)
{
SET0=0;
SET1=0;
SET2=0;
ALE=1;
SOC=1;
clock();
ALE=0;
SOC=0;
clock();
while(!EOC);
OE=1;
adc_val=ADC;
lcd_cmd(0x8c);
delay(250);
lcd_data(0x30+(adc_val/100));
delay(100);
lcd_data(0x30+((adc_val%100)/10));
delay(100);
lcd_data(0x30+((adc_val%100)%10));
delay(100);
pwm(adc_val);
}
}

//for the select line

You might also like