模拟风扇控制电路(单片机C程序设计)
模拟风扇控制电路
1、定时设置每按一下定时值在0分---2分----4分---6分----8分--10循环
2、主电机工作方式有三种,A、PWM为三分之一
B、PWM为二分之一 C、PWM为三分之二;
3、显示第一位显示风类,第二三四位动态显示定时时间;
4、摇头电机每30秒正转30秒反转;
==================================================
*/
#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;}
//=================
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
}
//=========风机电机===============
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;
}
模拟风扇控制电路单片 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)