标题:
led亮度温控风扇系统源程序
[打印本页]
作者:
齐jm
时间:
2017-6-28 15:08
标题:
led亮度温控风扇系统源程序
0.png
(49.52 KB, 下载次数: 62)
下载附件
2017-6-28 17:19 上传
单片机源程序如下:
#include "ds18b20.h"
#include "smg.h"
#include "eepom52.h"
#include"motor_pwm.h"
sbit Reduc = P3^3; //减
sbit Add = P3^4; //加
sbit Mode = P3^5; //设置
sbit fs = P3^6;
uchar m=0;
uint time_when=0,time_points=0,time_seconds=0,time_100ms=0;
void Timer0Init(void) //1000微秒@12.000MHz
{
TMOD |= 0x01; //设置定时器模式
TL0 = 0x80; //设置定时初值
TH0 = 0xD8; //设置定时初值
TR0 = 1; //timer0 start running
ET0 = 1; //enable timer0 interrupt
EA = 1; //open global interrupt switch
}
void tm0_isr() interrupt 1 using 1
{
TL0 = 0x80; //设置定时初值
TH0 = 0xD8; //设置定时初值
time_100ms++;
if (time_100ms==99)
{
time_100ms = 0;
time_seconds++;
m=~m;
if (time_seconds==60)
{
time_seconds=0;
time_points++;
if (time_points==60)
{
time_points=0;
time_when++;
if (time_when==24)
{
TR0 = 0;
}
}
}
}
}
void main(void)
{
uint T_tada;//温度数据变量
char T_L=2,T_H=0;
uchar Mode_project=1,key_count=0;//设置变量
uint disp_count=300;//显示300次采集一次温度数据,解决采集时闪烁
uchar temp_disp[4];//数据缓存
/****DS18B20检测,没有检测到数码管显示四个‘----’****/
while(reset())
{
disp_count=100;while(disp_count--){SMG_setxy(1,11,0);SMG_setxy(2,11,0);SMG_setxy(3,11,0);SMG_setxy(4,11,0);}
disp_count=100;while(disp_count--){SMG_setxy(1,10,0);SMG_setxy(2,10,0);SMG_setxy(3,10,0);SMG_setxy(4,10,0);}
}
/****开机采集温度,避免第一次读取温度为85度误报警****/
disp_count=30;
while(disp_count--)
{
T_tada=read_temp();
}
/***开机把数据从单片机内部eepom中读出来***/
if(byte_read(0x2050)!=0)
{
SectorErase(0x2000);
byte_write(0x2000,T_L);
byte_write(0x2001,T_H);
byte_write(0x2050,1);
}
if(byte_read(0x2050)==1)
{
T_L=byte_read(0x2000);
T_H=byte_read(0x2001);
}
Timer0Init();
pwm_init();
while(1)
{
temp_disp[0]=time_when/10;
temp_disp[1]=time_when%10;
temp_disp[2]=time_points/10;
temp_disp[3]=time_points%10;
/*******加速*******/
if(Add==0)
{
//利用显示延时
key_count=60;
while(key_count--)
{
SMG_setxy(1,temp_disp[0],0);
SMG_setxy(2,temp_disp[1],m);
SMG_setxy(3,temp_disp[2],0);
SMG_setxy(4,temp_disp[3],0);
}
speed+=5;
if(speed>=100)speed=100;
}
/*******减速*******/
if(Reduc==0)
{
//利用显示延时
key_count=60;
while(key_count--)
{
SMG_setxy(1,temp_disp[0],0);
SMG_setxy(2,temp_disp[1],m);
SMG_setxy(3,temp_disp[2],0);
SMG_setxy(4,temp_disp[3],0);
}
speed-=5;
if(speed<=0)speed=0;
}
if(T_tada>3500)//温度大于35度,打开风扇
{
fs=1;
}
else
{
fs=0;
}
if(T_H==time_when && T_L==time_points && time_seconds<0x01)
{
EA=0;
M1=0;
}
// temp_disp[2]=time_seconds/10;
// temp_disp[3]=time_seconds%10;
/****温度数据采集****/
loop:
if(++disp_count>=3000)
{
disp_count=0;
TR1=0;T_tada=read_temp();if(speed==0)TR1=1;
// if(T_tada>20000)//负数
// {
// temp_disp[0]=11;
// T_tada-=20000;
// }
// else temp_disp[0]=T_tada/10000; //正数温度百位
//
// temp_disp[1]=T_tada/1000%10; //温度十位
// temp_disp[2]=T_tada/100%10;//温度个位
// temp_disp[3]=T_tada/10%10;//温度小数第一位
// if(temp_disp[0]==0)temp_disp[0]=10;//百位消隐
}
/****数码管扫描显示****/
SMG_setxy(1,temp_disp[0],0);
SMG_setxy(2,temp_disp[1],m);
SMG_setxy(3,temp_disp[2],0);
SMG_setxy(4,temp_disp[3],0);
/****按下设置键,设置参数****/
if(Mode==0)
{
Mode_project=1;
while(Mode==0);//按键松开
while(1)
{
//设置页面显示
switch(Mode_project)
{
case 1:
SMG_setxy(1,12,0);
SMG_setxy(2,11,0);
SMG_setxy(3,T_H/10,0);
SMG_setxy(4,T_H%10,0);
break;
case 2:
SMG_setxy(1,13,0);
SMG_setxy(2,11,0);
SMG_setxy(3,T_L/10,0);
SMG_setxy(4,T_L%10,0);
break;
}
//按下加键,对设定目标加
if(Add==0)
{
//利用显示延时
key_count=60;
while(key_count--)
{
switch(Mode_project)
{
case 1:
SMG_setxy(1,12,0);
SMG_setxy(2,11,0);
SMG_setxy(3,T_H/10,0);
SMG_setxy(4,T_H%10,0);
break;
case 2:
SMG_setxy(1,13,0);
SMG_setxy(2,11,0);
SMG_setxy(3,T_L/10,0);
SMG_setxy(4,T_L%10,0);
break;
}
}
switch(Mode_project)
{
case 1:T_H+=1;if(T_H>=100)T_H=100;break;
case 2:T_L+=1;if(T_L>=100)T_L=100;break;
}
}
//按下减键,对设定目标减
if(Reduc==0)
{
//利用显示延时
key_count=60;
while(key_count--)
{
switch(Mode_project)
{
case 1:
SMG_setxy(1,12,0);
SMG_setxy(2,11,0);
SMG_setxy(3,T_H/10,0);
SMG_setxy(4,T_H%10,0);
break;
case 2:
SMG_setxy(1,13,0);
SMG_setxy(2,11,0);
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
程序.rar
(48.04 KB, 下载次数: 16)
2017-6-28 15:07 上传
点击文件名下载附件
具体程序
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1