新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 模擬風(fēng)扇控制電路(單片機C程序設(shè)計)

模擬風(fēng)扇控制電路(單片機C程序設(shè)計)

作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
/*

模擬風(fēng)扇控制電路
1、定時設(shè)置每按一下定時值在0分---2分----4分---6分----8分--10循環(huán)
2、主電機工作方式有三種,A、PWM為三分之一
B、PWM為二分之一 C、PWM為三分之二;
3、顯示第一位顯示風(fēng)類,第二三四位動態(tài)顯示定時時間;
4、搖頭電機每30秒正轉(zhuǎn)30秒反轉(zhuǎn);
==================================================
*/
#include
#define uint unsigned int
#define uchar unsigned char
unsigned char code table[]={0x3f,0x06,0x5b,
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar flag,flag1,flag2,flag3,fen,miao,flagfen;
uchar fenglei1,dingshi1,yaotu1;
uchar num1,num2,temp;
uint aa,bb,cc;
sbit fenglei=P3^0;
sbit dingshi=P3^1;
sbit yaotu=P3^2;
sbit wei1=P2^3;
sbit wei2=P2^4;
sbit wei3=P2^5;
sbit wei4=P2^6;
sbit pwmh1=P3^3;
sbit pwml1=P3^4;
sbit pwmh2=P3^5;
sbit pwml2=P3^6;
void delay(uint z);
void keyscan();
void disp();
void intc();
void dispfenlei();
void dispdingshi();
void dianji1();
void dianji2();
//=====================
void main()
{
intc();
while(1)
{
keyscan();
dispfenlei();
dispdingshi();
dianji1();
//dianji2();

}
}
//=================
void intc()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
ET0=1;
ET1=1;
EA=1;
TR1=1;
pwml1=0;
pwml2=0;
}
//======================
void timer0()
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
{
aa=0;
miao++;}
if(miao>60)
{ miao=0;
fen++;flagfen=1;}
if(fen==dingshi1)
{ TR0=0;
miao=0;
fen=0;
aa=0;}

本文引用地址:http://butianyuan.cn/article/201611/315590.htm



}
//=================
void timer1()
{
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
aa++;
if(aa==10)
{aa=0;bb++;}
if(bb==100)
{bb=0;cc++;}
if(cc==60)
cc=0;


}
//==============
void keyscan()
{
if(fenglei==0)
delay(100);
if(fenglei==0)
{
while(!fenglei);
fenglei1++;
if(fenglei1>2)
fenglei1=0;
}
if(dingshi==0)
delay(100);
if(dingshi==0)
{
while(!dingshi);
TR0=1;
dingshi1++;
temp=dingshi1;
if(dingshi1>5)
dingshi1=0;
}
if(yaotu==0)
delay(100);
if(yaotu==0)
{
while(!yaotu);
yaotu1=~yaotu1;
}
if(dingshi1!=0)
TR0=1;
else
TR0=0;

}

//============
void dispfenlei()
{


P0=table[fenglei1];
P2=0xf7;
delay(5);
}

//=============
void dispdingshi()
{if(flagfen==1)
{flagfen=0;
if(temp==0)
temp==0;
else
temp--;
}
P2=0xfb;
P0=table[0];
P2=0xfb;
delay(5);
P0=0xff;

P0=table[(temp*2)/10];
P2=0xfd;
delay(5);
P0=0xff;

P0=table[(temp*2)%10];
P2=0xfe;
delay(5);
P0=0xff;
}
//===============
void delay(uint z)
{
uint x;
uchar y;
for(x=0;x for(y=0;y<100;y++);
}
//=========風(fēng)機電機===============
void dianji1()
{
switch(fenglei1)
{
case 0: if(aa<=3)
pwmh1=1;
if(aa>3&&aa<=10)
pwmh1=0;break;
case 1: if(aa<=5)
pwmh1=1;
if(aa>5&&aa<=10)
pwmh1=0;
case 2: if(aa<=7)
pwmh1=1;
if(aa>7&&aa<=10)
pwmh1=0;

}

}

//=========搖頭電機==================
void dianji2()
{
if(yaotu1==1)
{if(cc<30)
pwmh2=1;
else
pwmh2=0;}
else
pwmh2=0;

}



評論


技術(shù)專區(qū)

關(guān)閉