源代码
sprintf(date,"temper is %s%d",temper);
sprintf(DATA," humi is %s%d",humi);
更新代码
char str1[]={"temperature:"};
char str2[]={"humidity:"};
sprintf(date," %s%d",str1,temper);
sprintf(DATA," %s%d",str2,humi);
启发
这样有个问题,变量实时更新不了,还没解决,在lcd上是乱码,但是在串口还是可以的
只能用暴力了
unsigned char str1[]={"temper"};
unsigned char str2[]={"humidity"};
sprintf(date," %d",temper);
LCD_DrawFont_GBK24(0, 30, BLACK, WHITE,str1 );
LCD_DrawFont_GBK24(50, 30, BLACK, WHITE, (u8*)date);
sprintf(DATA,"%d",humi);
LCD_DrawFont_GBK24(0, 60, BLACK, WHITE,str2 );
LCD_DrawFont_GBK24(80, 60, BLACK, WHITE,(u8*) DATA);
弄了三个小时,终于弄好了,要给每一个变量规定大小,放置溢出的地址
#include "stm32f10x.h"
#include "led.h"
#include "timer.h"
#include "lcd.h"
#include "stdio.h"
#include "Picture.h"
#include "delay.h"
#include "sys.h"
//#include "pwm.h"
#include "key.h"
#include "usart.h"
#include "dht11.h"
char date[20];
char DATA[20];
u8 str1[7]={"temper:"};
u8 str2[9]={"humidity:"};
int main(void)
{
u8 temper;
u8 humi;
u8 temp;
delay_init();
USART_Config();
LED_Init();
DHT11_Init ();
LCD_Init();
LCD_Clear(WHITE);
// LCD_Clear(BLACK);
// LCD_DrawFont_GBK16(50, 50, BLACK, WHITE,"灯灭");
while(1)
{
temp=DHT11_Read_Data(&temper,&humi);
if(temp==0)
printf("temperature is %d\r\n",temper);
printf("humidity is %d\r\n",humi);
sprintf(date," %.7s%.2d",str1,temper);
LCD_DrawFont_GBK24(0, 50, BLACK, WHITE, (u8*) date);
sprintf(DATA,"%.9s%.2d",str2,humi);
LCD_DrawFont_GBK24(0, 80, BLACK, WHITE,(u8*) DATA);
delay_ms(1000);
}
}
参考http://t.csdn.cn/ndkdt
实验效果