原程序是利用4位数码管显示温湿度怎么修改成8位数码管显示
时间:10-02
整理:3721RD
点击:
#include "dht11.h"
#include <reg52.h>
//数码管位定义
sbit DULA = P2^6;
sbit WELA = P2^7;
#define SET_DULA() (DULA = 1)
#define RESET_DULA() (DULA = 0)
#define SET_WELA() (WELA = 1)
#define RESET_WELA() (WELA = 0)
//中断计数标志
static unsigned char flag;
//数码管编码
static unsigned char code array[]= {
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f
};
extern int temp_value, humi_value;
static void InitTime(void);
void Delay_1ms(unsigned int ms);
static void SMG_Display(unsigned int value);
int main(void)
{
unsigned char mark = 0;
//先等上电稳定
Delay_1ms(1000);
//因为读一次数据dht11 才会触发一次采集数据.
//即在先使用数据时采集一次数据
ReadTempAndHumi();
//因为在两次采集数据需一定的时间间隔,这里还可减少
Delay_1ms(1000);
//设定定时器
InitTime();
while(1)
{
//三秒读一次温湿度
if(flag == 60)
{
flag = 0;
mark++;
/*
//读温湿度,可检测函数调用是否失败,
//函数返回OK(1)表示成功,返回ERROR(0)表示失败
//OK和ERROR是在DHT11.H中定义的宏
*/
ReadTempAndHumi();
}
if(mark % 2 == 0)
{
//显示温度
SMG_Display(temp_value);
}
else
{
//显示湿度
SMG_Display(humi_value);
}
}
return 0;
}
//设定定时器
static void InitTime(void)
{
TH0 = (unsigned char)((65535U - 50000) >> 8);
TL0 = (unsigned char)(65535U - 50000) ;
TMOD = 0X01;
TR0 = 1;
ET0 = 1;
EA = 1;
}
//数码管显示函数
static void SMG_Display(unsigned int value)
{
unsigned char ge, bai, shi;
ge = value % 10;
shi = value % 100 / 10;
bai = value % 1000 / 100;
SET_WELA();
P0 = 0XFE;
RESET_WELA();
P0 = 0XFF;
SET_DULA();
P0 = array[bai];
RESET_DULA();
Delay_1ms(2);
SET_WELA();
P0 = 0XFD;
RESET_WELA();
P0 = 0XFF;
SET_DULA();
P0 = array[shi];
P0 |= 0x80; /*显示小数点*/
RESET_DULA();
Delay_1ms(2);
SET_WELA();
P0 = 0XFB;
RESET_WELA();
P0 = 0XFF;
SET_DULA();
P0 = array[ge];
RESET_DULA();
Delay_1ms(2);
}
//中断函数
void timer(void) interrupt 1
{
TH0 = (unsigned char)((65535 - 50000) >> 8);
TL0 = (unsigned char)(65535 - 50000);
flag++;
}
#include <reg52.h>
//数码管位定义
sbit DULA = P2^6;
sbit WELA = P2^7;
#define SET_DULA() (DULA = 1)
#define RESET_DULA() (DULA = 0)
#define SET_WELA() (WELA = 1)
#define RESET_WELA() (WELA = 0)
//中断计数标志
static unsigned char flag;
//数码管编码
static unsigned char code array[]= {
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f
};
extern int temp_value, humi_value;
static void InitTime(void);
void Delay_1ms(unsigned int ms);
static void SMG_Display(unsigned int value);
int main(void)
{
unsigned char mark = 0;
//先等上电稳定
Delay_1ms(1000);
//因为读一次数据dht11 才会触发一次采集数据.
//即在先使用数据时采集一次数据
ReadTempAndHumi();
//因为在两次采集数据需一定的时间间隔,这里还可减少
Delay_1ms(1000);
//设定定时器
InitTime();
while(1)
{
//三秒读一次温湿度
if(flag == 60)
{
flag = 0;
mark++;
/*
//读温湿度,可检测函数调用是否失败,
//函数返回OK(1)表示成功,返回ERROR(0)表示失败
//OK和ERROR是在DHT11.H中定义的宏
*/
ReadTempAndHumi();
}
if(mark % 2 == 0)
{
//显示温度
SMG_Display(temp_value);
}
else
{
//显示湿度
SMG_Display(humi_value);
}
}
return 0;
}
//设定定时器
static void InitTime(void)
{
TH0 = (unsigned char)((65535U - 50000) >> 8);
TL0 = (unsigned char)(65535U - 50000) ;
TMOD = 0X01;
TR0 = 1;
ET0 = 1;
EA = 1;
}
//数码管显示函数
static void SMG_Display(unsigned int value)
{
unsigned char ge, bai, shi;
ge = value % 10;
shi = value % 100 / 10;
bai = value % 1000 / 100;
SET_WELA();
P0 = 0XFE;
RESET_WELA();
P0 = 0XFF;
SET_DULA();
P0 = array[bai];
RESET_DULA();
Delay_1ms(2);
SET_WELA();
P0 = 0XFD;
RESET_WELA();
P0 = 0XFF;
SET_DULA();
P0 = array[shi];
P0 |= 0x80; /*显示小数点*/
RESET_DULA();
Delay_1ms(2);
SET_WELA();
P0 = 0XFB;
RESET_WELA();
P0 = 0XFF;
SET_DULA();
P0 = array[ge];
RESET_DULA();
Delay_1ms(2);
}
//中断函数
void timer(void) interrupt 1
{
TH0 = (unsigned char)((65535 - 50000) >> 8);
TL0 = (unsigned char)(65535 - 50000);
flag++;
}
请问小编的意思是 前四位显示温度 后四位显示湿度么? 各显示几位数?
就是前四位显示温度,后四位显示湿度
怎么用四位数码管显示啊