查看:8498|回复:8
分享一个自己做的单片机设计
智能风扇控制系统仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
功能非常多多,带三挡风速调节,还有正常,睡眠,自然3个模式,是按键控制的。
![0.jpg](http://cdn-img.sm-tc.cn/?src=l4uLj8XQ0JzRys6XmpbRnJCS0JvQmZCNipLQzc%2FOx8%2FL0M3P0M%2FMzMfPy4WHipychYqcjJ2MzomcnJzRlY%2BY&restype=3&from=derive&pi=&v=1)
单片机风扇源程序如下:
复制代码
复制代码
复制代码
![0.jpg](http://cdn-img.sm-tc.cn/?src=l4uLj8XQ0JzRys6XmpbRnJCS0JvQmZCNipLQzc%2FOx8%2FL0M3P0M%2FMzMbOy5aampeXz5uGzYyUxpfGk5nRlY%2BY&restype=3&from=derive&pi=&v=1)
调试中的代码与Proteus7.8版本的仿真下载(代码存在一些Keil版本兼容性问题):
STC89C51_风扇控制系统.zip(433.14 KB, 下载次数: 281)
智能风扇控制系统仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
功能非常多多,带三挡风速调节,还有正常,睡眠,自然3个模式,是按键控制的。
单片机风扇源程序如下:
- //数码管低电平有效
- #include< reg51.h>
- #include< absacc.h>
- #include< ctype.h>
- #include< math.h>
- #include< stdio.h>
- #include< string.h>
- #include "set.h"
- #include "myinit.h"
- #include "function.h"
- uint signal;
- uint q; //用于DS18B20 j秒读取一次数据
- uchar code a[]={ //定义数组,用于数码管显示
- 0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x40
- };
-
/*******************************************************************************/
- uchar TH=50,TL=10; //定义温度上下限
- uchar t[2]={20,20},*pt; //用来存放温度值,测温程序就是通过这个数组与主函数通信的
-
uchar TempBuffer1[9]={0x2b,0x31,0x32,0x32,0x2e,0x30,0x30,0x43,'\0'};
- //显示实时温度,上电时显示+125.00C
-
uchar TempBuffer0[17]={0x54,0x48,0x3a,0x2b,0x31,0x32,0x35,0x20,
-
0x54,0x4c,0x3a,0x2b,0x31,0x32,0x34,0x43,'\0'};
- //显示温度上下限,上电时显示TH:+125 TL:+124C
- uchar code dotcode[4]={0,25,50,75};
-
/*******************************************************************************/
- void main()
- {
- // unsigned char TH=50,TL=10; //定义温度上下限
- init_timer(); //初始化
- init(); //初始化
-
pt=ReadTemperature(TH,TL,0x3f); //上限温度-22,下限-24,分辨率10位,也就是0.25C
- //读取温度,温度值存放在一个两个字节的数组
- covert1(); //将温度转换为LCD显示的据数
- while(1) //等待启动
- {
- scan();
- if(flag_modle==1)
- {
- led_normal=1;
- led_style=1;
- break;
- }
- }
- close_motor=1; //打开电机电源
- while(1) //启动后进入循环扫面状态
- {
- scan();
- switch(flag_modle)
- {
- case 1:
- choice_speed();
- break;
- case 2:
- choice_modle();
- flag_modle=1;
- break;
- case 3:
- stop_operation();
- break;
- }
- /* if(q>60) //3S读取一次温度
- {
-
pt=ReadTemperature(TH,TL,0x3f); //上限温度-22,下限-24,分辨率10位,也就是0.25C
- //读取温度,温度值存放在一个两个字节的数组
- covert1();
- } */
- }
- }
- //中断函数
- void timer0() interrupt 1
- {
- if(i>=20) //定时1S
- {
- i=0;
- time--;
- if(time<=0)
- time=0;
- }
- if(q>20) //定时3S,3S测一次温度
- {
- q=0;
-
pt=ReadTemperature(TH,TL,0x3f);
- covert1();
- }
- if((t[1]>TH)|(t[1]<TL)) //温度 TL<t[1]<TH 时,关闭电机
- {
- close_motor=0; //关闭电机电源
- init(); //初始化
- }
- else
- close_motor=1; //打开电机电源
- i++,q++;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- }
- #include "function.h"
- #include "set.h"
- //按键扫描函数
- void scan(void)
- {
- if(speed==1)//风速
- {
- delay(10);
- if(speed==1)
- {
- while(speed);
- flag_modle=1; //模式标志位
- flag_speed++;
- signal=1; //按键信号标志,用于选择模式
- if(flag_speed>4)
- flag_speed=1;
- }
- }
- if(style==1)//模式
- {
- delay(10);
- if(style==1)
- {
- while(style);
- flag_modle=2; //模式标志位
- flag_style++;
- signal=1; //按键信号标志,用于选择模式
- if(flag_style>3)
- flag_style=1;
- }
- }
- if(stop==1)//停止
- {
- delay(10);
- if(stop==1)
- {
- while(stop);
- flag_modle=3; //模式标志位
- signal=1; //按键信号标志,用于选择模式
- }
- }
- }
- #include "function.h"
- //风速选择 1:弱 2:中 3:强 4:超强
- void choice_speed(void)
- {
- switch(flag_speed)
- {
- case 1:
- // led_style=0;
- led_stop=0;
- time=0;
- display();
- o_spuerhigh=0;
- o_high=0;
- o_middle=0;
- o_low=1; //开——低
- led_speed=1;
- c_display=0;
-
- if(flag_style==3) //nature
- {
- led_style=1;
- time=8;
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_low=1;
- scan();
- if(signal)
- {
- break;
- }
- }
- c_display=1;
- time=8;//停转
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_low=0;
- scan();
- if(signal)
- {
- break;
- }
- }
- c_display=1;
- signal=0;
- }
- if(flag_style==2) //sleep
- {
- led_normal=0;
- led_sleep=1;
- led_nature=0;
- led_style=1;
- time=4;//转4s
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_low=1;
- scan();
- if(signal)
- break;
- }
- c_display=1;
- time=8;//停转
- while(signal==0&& (time))
- {
- c_display= 0;
- display();
- o_low=0;
- scan();
- if(signal)
- break;
- }
- c_display=1;
- signal=0;
- }
- break;
- case 2:
- //led_style=0;
- c_display=0;
- time=0;
- display();
- led_stop=0;
- o_low=0;
- o_high=0;
- o_spuerhigh=0;
- o_middle=1; //开——中
- led_speed=1;
-
- if(flag_style==3) //nature
- {
- led_style=1;
- time=8;
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_middle=1;
- scan();
- if(signal)
- {
- break;
- }
- }
- c_display=1;
- time=8;//停转
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_middle=0;
- scan();
- if(signal)
- {
- break;
- }
- }
- c_display=1;
- signal=0;
- }
- if(flag_style==2) ///////////
- {
- led_sleep=0;
- led_normal=1;
- led_nature=0;
- }
- break;
- case 3:
- // led_style=0;
- c_display=0;
- time=0;
- display();
- led_stop=0;
- o_low=0;
- o_middle=0;
- o_spuerhigh=0;
- led_speed=1;//开——强
- o_high=1;
-
- if(flag_style==3) ////////////////
- {
- led_style=1;
- time=8;
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_high=1;
- scan();
- if(signal)
- break;
- }
- c_display=1;
- time=8;//停转
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_high=0;
- scan();
- if(signal)
- break;
- }
- c_display=1;
- signal=0;
- }
- if(flag_style==2) /////////////
- {
- led_sleep=0;
- led_normal=1;
- led_nature=0;
- }
- break;
- case 4:
- // led_style=0;
- c_display=0;
- time=0;
- display();
- led_stop=0;
- o_low=0;
- o_middle=0;
- o_high=0;
- led_speed=1;//开——超强
- o_spuerhigh=1;
-
- if(flag_style==3) ////////////////
- {
- led_style=1;
- time=8;
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_spuerhigh=1;
- scan();
- if(signal)
- break;
- }
- c_display=1;
- time=8;//停转
- while(signal==0&& (time))
- {
- c_display=0;
- display();
- o_spuerhigh=0;
- scan();
- if(signal)
- break;
- }
- c_display=1;
- signal=0;
- }
- if(flag_style==2) /////////////
- {
- led_sleep=0;
- led_normal=1;
- led_nature=0;
- }
- break;
- }
- }
-
/*******************************************************************************/
- //模式选择 1:正常 2:睡眠 3:自然
- void choice_modle(void)
- {
- switch(flag_style)
- {
- case 1: //正常
- led_style=1;
- led_normal=1;
- led_nature=0;
- led_sleep=0;
- break;
- case 2: //睡眠 //////////
- led_style=1;
- time=4;//转4s
- flag_speed=1;
- led_normal=0;
- led_nature=0;
- led_sleep=1;
- case 3: //自然风 /////
- led_style=1;
- time=8;//转8s
- led_normal=0;
- led_nature=1;
- led_sleep=0;
- break;
-
- break;
- }
- }
调试中的代码与Proteus7.8版本的仿真下载(代码存在一些Keil版本兼容性问题):