//传感器定义
//TFT显示屏定义
//函数声明
void readLDSensorValue(int* temp, int* hum, int* pol);
void drawSensorInformation(int temp, int hum, int pol);
int main()
{
int temp, hum, pol;
//设置GPIO
HW_GPIO_init();
//读取传感器值
readLDSensorValue(&temp, &hum, &pol);
//设置TFT显示屏
HW_TFT_Init();
//在TFT上绘制传感器信息
drawSensorInformation(temp, hum, pol);
return 0;
}
//读取传感器值
void readLDSensorValue(int* temp, int* hum, int* pol)
{
unsigned char data[2];
//读取温度
hwI2CReadBytes(I2C_ADDR_SENSOR, SENSOR_TEMP, data, 2);
*temp = (data[0]<<8)|data[1];
//读取湿度
hwI2CReadBytes(I2C_ADDR_SENSOR, SENSOR_HUM, data, 2);
*hum = (data[0]<<8)|data[1];
//读取环境污染值
hwI2CReadBytes(I2C_ADDR_SENSOR, SENSOR_POLLUTION, data, 2);
*pol = (data[0]<<8)|data[1];
}
//绘制传感器信息
void drawTemperatureHumidityPollution(int temp,int hum,int pol)
{
char buff[20];
//绘制温度
sprintf(buff,"Temp. %dC",temp);
HW_TFT_UsrTextDraw(0,LCD_HEIGH-3*20, buff ,20 ,White, Black );
//绘制湿度
sprintf(buff,"Hum. %d%%",hum);
HW_TFT_UsrTextDraw(0,LCD_HEIGH-2*20, buff ,20 ,White, Black );
//绘制环境污染度
sprintf(buff,"Polution: %dmg/m^3",pol);
HW_TFT_UsrTextDraw(0,LCD_HEIGH-1*20, buff ,20 ,White, Black );
}
END
来源:21ic论坛
→点关注,不迷路←