上传者: 15067111
|
上传时间: 2019-12-24 03:12:20
|
文件大小: 4KB
|
文件类型: txt
sht30的基于c51单片机驱动程序:#include
#include
#include "I2C.h"
#include "SHT30.h"
#define uint unsigned int
#define uchar unsigned char
void display();
unsigned char code tableduan[]= {
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
uchar data DIS_ROME[6]= {0,0,0,0,0,0}; //显示缓存区(4)
uchar DISP=0;//缓存区指针
uchar SCANF=0xDF;//扫描指针
sbit LED1=P1^0;
sbit LED2=P1^1;
sbit LED3=P1^2;
sbit LED4=P1^3;
sbit VOC_A=P3^5;
sbit VOC_B=P3^6;
sbit dula=P2^6; //IO口定义
sbit wela=P2^7;
sbit key=P3^4;
sbit beep_dr=P2^3;
uint pm1 = 0;
uint pm2 = 0;
uint pm10 = 0;
uchar vr=0;
uint intrcnt=0;
bit F_1HZ;
uint voice_time_cnt;
uchar Uart_Buf;
uchar Rec_Addr=0;
uchar mode=0;
uchar Rec_Uart=0;
uchar Recive_Buf[30]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#define key P34
#define const_key_time1 50
unsigned char ucKeySec=0; //被触发的按键编号
unsigned int uiKeyTimeCnt1=0; //按键去抖动延时计数器
unsigned char ucKeyLock1=0; //按键触发后自锁的变量标志
unsigned char displaycnt=0;
void keyscan()
{
if(key==1)//IO是高电平,说明按键没有被按下,这时要及时清零一些标志位
{
ucKeyLock1=0; //按键自锁标志清零
uiKeyTimeCnt1=0;//按键去抖动延时计数器清零,此行非常巧妙,是我实战中摸索出来的。
}
else if(ucKeyLock1==0)//有按键按下,且是第一次被按下
{
uiKeyTimeCnt1++; //累加定时中断次数
if(uiKeyTimeCnt1>const_key_time1)
{
uiKeyTimeCnt1=0;
ucKeyLock1=1; //自锁按键置位,避免一直触发
ucKeySec=1; //触发1号键
}
}
}
void keyservice()
{
if(ucKeySec)
{
displaycnt=!displaycnt;
}
ucKeySec=0;
}
void UartInit(void) //9600bps@12.000MHz
{
TMOD=0x01; //设置定时器0为工作方式1
TH0=0xf8; //重装初始值(65535-500)=65035=0xfe0b
TL0=0x2f;
SCON=0x50;
TMOD=0X21;
IP =0x10; //把串口中断设置为最高优先级,
EA=1;
ES=1;
ET0=1;
TR0=1;
}
void T0_time(void) interrupt 1 //定时中断
{
TF0=0; //清除中断标志
TR0=0; //关中断
keyscan();
keyservice();
display();