#include <ioCC2530.h> #include <string.h> #include <stdio.h> #include "DHT11.h" #include "OLED.h" void clock_setup(void) { CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振 while(CLKCONSTA & 0x40); //等待晶振稳定 CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ } void init_sensor_io(void) { //1.设置IO为普通IO P0SEL |= 0xC0; P1SEL |= 0x07; //2.设置编码口为输入 P0DIR &= ~0xC0; P1DIR &= ~0x07; } uchar get_sensor_id(void) { volatile uchar temp = P0_6<<4|P0_7<<3|P1_0<<2|P1_1<<1|P1_2; return temp; } void main(void) { uint temp16; uchar buf[16]; clock_setup(); //系统时钟设置,精确延时必须要设置 Delay_ms(1000); //让设备稳定 port_init(); initial_lcd(); init_sensor_io(); clear_screen(); //清屏 disp_string_8x16_16x16(1,1,"武汉唯众智创科技"); //显示字符串,括号里的参数分别为(PAGE,列,字符串指针) disp_string_8x16_16x16(3,1,"有限公司荣耀创造"); Delay_ms(500); while(1) { temp16 = DHT11(); //获取温湿度 clear_screen(); //清屏 sprintf(buf,"编号:%d",get_sensor_id()); disp_string_8x16_16x16(1,1,buf); //显示字符串,括号里的参数分别为(PAGE,列,字符串指针) sprintf(buf,"温度:%d 湿度:%d",temp16>>8,(uchar)temp16); disp_string_8x16_16x16(3,1,buf); Delay_ms(1000); //延时,1S读取1次 } } |