下载频道  >  qq_15067111的资源
  • sht30 基于C51单片机的驱动程序,可能需要修改

    sht30的基于c51单片机驱动程序:#include <intrins.h> #include <reg51.h> #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(); if(++intrcnt==1000) { intrcnt=0; } TH0=0xf8; TL0=0x2f; TR0=1; //开中断 } void display() //LED扫描 { if(displaycnt==1) { DIS_ROME[0]=0; DIS_ROME[1]=Hum_num[4]; DIS_ROME[2]=Hum_num[3]; DIS_ROME[3]=Hum_num[2]; DIS_ROME[4]=Hum_num[1]; DIS_ROME[5]=Hum_num[0]; } else { DIS_ROME[0]=0; DIS_ROME[1]=TEMP_num[4]; DIS_ROME[2]=TEMP_num[3]; DIS_ROME[3]=TEMP_num[2]; DIS_ROME[4]=TEMP_num[1]; DIS_ROME[5]=TEMP_num[0]; } wela=1; P0=SCANF; wela=0; dula=1; P0=tableduan[DIS_ROME[DISP]];//数据端口送数据 dula=0; DISP++;//缓存指针加1 SCANF=_cror_(SCANF,1);//扫描切换 if(DISP==7)//缓存指针到尾 { DISP=0;//计数归零 SCANF=0xDF;//扫完四个数码管,扫描复位 } // delay(5); } void main(void) //主函数 { UartInit(); I2C_inita(); while(1) { Getdat_SHT30(); SHT30_DATEChange(); } }

    2019-04-13
    49
img
qq_15067111

关注 私信