上传者: qq_15067111
|
上传时间:2022/9/6 21:13:46
|
文件大小:4KB
|
文件类型:txt
sht30基于C51单片机的驱动程序,可能需要修改
sht30的基于c51单片机驱动程序:#include#include#include"I2C.h"#include"SHT30.h"#defineuintunsignedint#defineucharunsignedcharvoiddisplay();unsignedcharcodetableduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchardataDIS_ROME[6]={0,0,0,0,0,0};//显示缓存区(4)ucharDISP=0;//缓存区指针ucharSCANF=0xDF;//扫描指针sbitLED1=P1^0;sbitLED2=P1^1;sbitLED3=P1^2;sbitLED4=P1^3;sbitVOC_A=P3^5;sbitVOC_B=P3^6;sbitdula=P2^6;//IO口定义sbitwela=P2^7;sbitkey=P3^4;sbitbeep_dr=P2^3;uintpm1=0;uintpm2=0;uintpm10=0;ucharvr=0;uintintrcnt=0;bitF_1HZ;uintvoice_time_cnt;ucharUart_Buf;ucharRec_Addr=0;ucharmode=0;ucharRec_Uart=0;ucharRecive_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};#definekeyP34#defineconst_key_time150unsignedcharucKeySec=0;//被触发的按键编号unsignedintuiKeyTimeCnt1=0;//按键去抖动延时计数器unsignedcharucKeyLock1=0;//按键触发后自锁的变量标志unsignedchardisplaycnt=0;voidkeyscan(){if(key==1)//IO是高电平,说明按键没有被按下,这时要及时清零一些标志位{ucKeyLock1=0;//按键自锁标志清零uiKeyTimeCnt1=0;//按键去抖动延时计数器清零,此行非常巧妙,是我实战中摸索出来的。
}elseif(ucKeyLock1==0)//有按键按下,且是第一次被按下{uiKeyTimeCnt1++;//累加定时中断次数if(uiKeyTimeCnt1>const_key_time1){uiKeyTimeCnt1=0;ucKeyLock1=1;//自锁按键置位,避免不断触发ucKeySec=1;//触发1号键}}}voidkeyservice(){if(ucKeySec){displaycnt=!displaycnt;}ucKeySec=0;}voidUartInit(void)//9600bps@12.000MHz{TMOD=0x01;//设置定时器0为工作方式1TH0=0xf8;//重装初始值(65535-500)=65035=0xfe0bTL0=0x2f;SCON=0x50;TMOD=0X21;IP=0x10;//把串口中断设置为最高优先级,EA=1;ES=1;ET0=1;TR0=1;}voidT0_time(void)interrupt1//定时中断{TF0=0;//清除中断标志TR0=0;//关中断keyscan();keyservice();display();
本软件ID:11112164