標題:
led亮度溫控風扇系統(tǒng)源程序
[打印本頁]
作者:
齊jm
時間:
2017-6-28 15:08
標題:
led亮度溫控風扇系統(tǒng)源程序
0.png
(49.52 KB, 下載次數(shù): 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;//溫度數(shù)據(jù)變量
char T_L=2,T_H=0;
uchar Mode_project=1,key_count=0;//設置變量
uint disp_count=300;//顯示300次采集一次溫度數(shù)據(jù),解決采集時閃爍
uchar temp_disp[4];//數(shù)據(jù)緩存
/****DS18B20檢測,沒有檢測到數(shù)碼管顯示四個‘----’****/
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();
}
/***開機把數(shù)據(jù)從單片機內(nèi)部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;
/****溫度數(shù)據(jù)采集****/
loop:
if(++disp_count>=3000)
{
disp_count=0;
TR1=0;T_tada=read_temp();if(speed==0)TR1=1;
// if(T_tada>20000)//負數(shù)
// {
// temp_disp[0]=11;
// T_tada-=20000;
// }
// else temp_disp[0]=T_tada/10000; //正數(shù)溫度百位
//
// temp_disp[1]=T_tada/1000%10; //溫度十位
// temp_disp[2]=T_tada/100%10;//溫度個位
// temp_disp[3]=T_tada/10%10;//溫度小數(shù)第一位
// if(temp_disp[0]==0)temp_disp[0]=10;//百位消隱
}
/****數(shù)碼管掃描顯示****/
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);
/****按下設置鍵,設置參數(shù)****/
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, 下載次數(shù): 16)
2017-6-28 15:07 上傳
點擊文件名下載附件
具體程序
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1