单片机源程序如下:
#include #include"MLX906.h" #include"LCD1602.h" #include"EEPROM.h" #include"I2C.h" #include"WT558D.h" #include"USART.h" sbit red =P3^3; sbit green =P3^4; sbit blue =P3^5; sbit key =P3^6; uchar tab[] ="Temp:"; int main() { uchar i; uint wendu; //存储读取的值 uint xiaoshu,zhengshu; //存储小数和整数 uchar ge,shi,bai,fyi,fer; //存储个,十,百,分数的第一位,分数的第二位 double num; UsartInit(); Lcd_init(); for(i=0;i<5;i++) { write_data(tab[i]); } bai = EEPROM_read_data(0); shi = EEPROM_read_data(1); ge = EEPROM_read_data(2); fyi = EEPROM_read_data(3); fer = EEPROM_read_data(4); if(bai!=0) { write_data(bai+0x30); } write_data(shi+0x30); write_data(ge+0x30); write_data(0x2e); write_data(fyi+0x30); write_data(fer+0x30); write_data(0xdf); write_data('C'); write_com(0x85); key=1; while(1) { if(key==0) { delay(10); if(key==0) { wendu=read_temp(); wendu=wendu*2; if(wendu>=27315) { wendu=wendu-27315+530; //530是进行温度补偿 zhengshu=wendu/100; //整数部分 xiaoshu=wendu-zhengshu*100; //小数部分 bai = zhengshu/100; shi = zhengshu%100/10; ge = zhengshu%10; fyi = xiaoshu/10; fer = xiaoshu%10; num = wendu*1.0/100; EEPROM_write_data(0,bai); delay(20); EEPROM_write_data(1,shi); delay(20); EEPROM_write_data(2,ge); delay(20); EEPROM_write_data(3,fyi); delay(20); EEPROM_write_data(4,fer); delay(20); } if(bai!=0) { write_data(bai+0x30); } write_data(shi+0x30); write_data(ge+0x30); write_data(0x2e); write_data(fyi+0x30); write_data(fer+0x30); write_data(0xdf); //write_data('C'); }while(!key); write_com(0x85); if(num<36.0) { blue = 0; red = 1; green = 1; } else if(num>=36.0&&num<=38.0) { green = 0; red = 1; blue = 1; } else if(num>38.0) { red = 0; green =1; blue = 1; }
上一篇:基于单片机的IC卡智能水表控制系统设计
下一篇:单片机主机通过DS18B20测温,从机接收并且实时显示温度
推荐阅读最新更新时间:2024-11-12 11:43