📄 humidity.c.bak
字号:
/****************************************************************************/
/* */
/* Copyright (c) 2005, 老树工作室 */
/* All rights reserved. */
/* */
/* http://www.saintone.net Email:hxm0902@163.com */
/* QQ:112431149 Tel:010-62966630 */
/* */
/****************************************************************************/
/****************************************************************************/
/* 文件名:humidity.c */
/* 版 本:Version 1.0 */
/* 描 述:利用hs1101与tlc555检测湿度的代码 */
/* 根据数据手册,简化湿度计算公式如下: */
/* humidity = (hum_const - 0.702*(fhz_tlc555-40)) / 10 */
/* fhz_tlc555>=7000: hum_const=5143.7 */
/* 6700<=fhz_tlc555<7000: hum_const=5183.7 */
/* fhz_tlc555<6700: hum_const=5203.7 */
/* */
/* 作 者:spot */
/* 函 数: */
/* time0_over_int */
/* ext1_int_proc */
/* system_init */
/* */
/* 历史记录: */
/* spot 2005-06-25 Creat Inital version. (Version 1.0) */
/****************************************************************************/
#include <reg52.h>
#include <absacc.h>
#include <intrins.h>
#include "../includes/types.h"
/* 函数声明 */
void time0_over_int(void); /* 定时器0中断服务程序 ,使用第1组寄存器 */
void ext1_int_proc(void); /* 外部中断1中断服务程序,使用第2组寄存器 */
void system_init(void); /* 系统上电初始化 */
void display_humidity(u_int current_humidity);/* 在数码管上显示当前湿度 */
extern void load_number(u_char number, bit dp);
extern void send_latch_clock(void);
extern void clear_led(void);
/* 声明结束 */
u_int fhz_tlc555; /* tlc555输出频率 */
u_char timer_count; /* 定时计数 */
bit timer_int; /* 定时标志 */
float hum_const; /* 计算湿度的常数 */
/* 定时器0中断服务程序 ,使用第1组寄存器 */
void time0_over_int(void) interrupt 1 using 1
{
TF0=0;
timer_int=1;
TH0 = -(46080 / 256);
TL0 = -(46080 % 256);
}
/* 外部中断1中断服务程序,使用第2组寄存器 */
void ext1_int_proc(void) interrupt 2 using 2
{
fhz_tlc555++;
}
/* 系统上电初始化 */
void system_init(void)
{
EA = 0;
timer_int = 0;
timer_count = 0;
TMOD = 0x01; /*定时器0工作于方式1*/
TCON = 0x04; /*外部中断下降沿触发*/
TH0 = -(46080 / 256); /*定时50毫秒*/
TL0 = -(46080 % 256);
PT0 = 1; /*定时器0高优先级*/
TR0 = 1; /*定时器0启动计数*/
IE = 0x86; /*定时器0,外部中断1,CPU开中断*/
}
/* 计算当前湿度 */
u_int get_humidity(u_int fhz) /* 输入fhz为tlc555的频率计数 */
{
u_int humidity = 0;
if(fhz >= 7000)
{
hum_const = 5143.7;
}
else if ( (fhz >= 6700) && (fhz < 7000) )
{
hum_const = 5183.7;
}
else if(fhz < 6700)
{
hum_const = 5203.7;
}
humidity = (u_int)( (hum_const - 0.702*(fhz - 40)) / 10);
return humidity;
}
/* 在数码管上显示当前湿度 */
void display_humidity(u_int current_humidity)
{
load_number( (current_humidity %10), 0);
load_number( (current_humidity /10), 0);
send_latch_clock();
}
main()
{
u_int real_hum;
system_init();
while(1)
{
if (timer_int == 1) /* 50毫秒定时到 */
{
timer_int = 0;
timer_count++;
if (timer_count == 100) /* 5秒定时到 */
{
timer_count = 0;
fhz_tlc555 /= 5;
real_hum = get_humidity(fhz_tlc555);
clear_led();
display_humidity(real_hum);
fhz_tlc555 = 0;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -