德州做名片的网站,永久免费库存管理软件,成品网站nike源码1688,淘宝电脑版登录入口一、系统方案 本设计采用STC15单片机作为主控器#xff0c;液晶1602显示#xff0c;DS18B20采集温度#xff0c;光敏电阻采集光照、按键设置温度上下限#xff0c;测量温度小于下限#xff0c;启动加热#xff0c;测量温度大于上限#xff0c;启动降温。 二、硬件设计 …一、系统方案 本设计采用STC15单片机作为主控器液晶1602显示DS18B20采集温度光敏电阻采集光照、按键设置温度上下限测量温度小于下限启动加热测量温度大于上限启动降温。 二、硬件设计 原理图如下
三、单片机软件设计 1、首先是系统初始化 uint count0; uint16 TempPhoto; uint8 strPhoto[6]; uint wendu0; P3M0 0x00; P3M1 0x00; lcd_init(); //LCD1602初始化 delay_ms(10); //初始化后延时 DisplayListChar(0, 0, table1); //在LCD1602屏第一行显示table1内容 DisplayListChar(0, 1, table2); //在LCD1602屏第二行显示table2内容
InitADC();InitUart(); //初始化串口 2、液晶显示程序 /************************************** 功能描述LCD1602写命令函数 入口参数int8 com 返回值无 ***************************************/ void lcd_wcom(uint8 com) { lcd1602_rs0; //选择指令寄存器 lcd1602_rw0; //选择写 P0com; //把命令字送入P0 delay_ms(1); //延时一小会儿让1602准备接收数据 lcd1602_en1; //使能线电平变化命令送入1602的8位数据口 lcd1602_en0; }
/************************************** 功能描述LCD1602写数据函数 入口参数uint8 dat 返回值无 ***************************************/ void lcd_wdat(uint8 dat) { lcd1602_rs1; //选择数据寄存器 lcd1602_rw0; //选择写 P0dat; //把要显示的数据送入P0 delay_ms(1); //延时一小会儿让1602准备接收数据 lcd1602_en1; //使能线电平变化数据送入1602的8位数据口 lcd1602_en0; }
/************************************** 功能描述LCD1602初始化函数 入口参数无 返回值无 **************************************/ void lcd_init(void) { lcd_wcom(0x38); //8位数据双列57字形 lcd_wcom(0x0c); //开启显示屏关光标光标不闪烁 lcd_wcom(0x06); //显示地址递增即写一个数据后显示位置右移一位 lcd_wcom(0x01); //清屏 }
3、按键程序 void keyscan() //按键扫描 { if(K10) //功能键 { delayms(5); if(K10) { keyflag_1; //键一按下标志位加1 if(keyflag_13) keyflag_10; lcd_init(); if( keyflag_10) { DisplayListChar(0, 0, table1); //在LCD1602屏第一行显示table1内容 DisplayListChar(0, 1, table2); //在LCD1602屏第二行显示table2内容 } if( keyflag_11) { DisplayListChar(0, 0, SET TEMP HIGH); } if( keyflag_12){DisplayListChar(0, 0, SET TEMP LOW); } while(!K1);}
}if(keyflag_1!0)
{ if(K20) //限值加键{ delayms(5); //按键消除抖动判断if(K20){if(keyflag_11) //进入设置模式 {max;if(max100) max0; }if(keyflag_12) //进入设置模式 {min;if(min100) min0; }while(!K2); //松手检测}} if(K30) //限值减键{delayms(5); //按键消除抖动判断if(K30){if(keyflag_11) //进入设置模式 {max--;if(max0) max99; }if(keyflag_12) //进入设置模式 {min--;if(min0) min99; }while(!K3); //松手检测}}
} } /*** 4、核心算法程序 int main(void) { uint count0; uint16 TempPhoto; uint8 strPhoto[6]; uint wendu0; P3M0 0x00; P3M1 0x00; lcd_init(); //LCD1602初始化 delay_ms(10); //初始化后延时 DisplayListChar(0, 0, table1); //在LCD1602屏第一行显示table1内容 DisplayListChar(0, 1, table2); //在LCD1602屏第二行显示table2内容
InitADC();InitUart(); //初始化串口 Init_DS18B20();
while (1)
{ keyscan();if(keyflag_10){count;if(count10)//读取温度值{wenduReadTemperature(); count0; } Disp_Temperature(wendu) ; memset(strPhoto, 0, sizeof(strPhoto)); //strTemp数组清零 TempPhoto GetADCResultint(1); //实时读取P1.1通道的AD转换结果 TempPhotoTempPhoto5.020/1023; strPhoto[0] TempPhoto/100048; //千位strPhoto[1] (TempPhoto%1000)/10048; //百位strPhoto[2] (TempPhoto%1000)%100/1048; //十位strPhoto[3] (TempPhoto%10)48; //个位//在LCD1602上显示DisplayOneChar(6, 0, strPhoto[0]); //在LCD1602屏第二行显示千位值 DisplayOneChar(7,0, strPhoto[1]); //在LCD1602屏第二行显示百位值 DisplayOneChar(8, 0, strPhoto[2]); //在LCD1602屏第二行显示十位值 DisplayOneChar(9, 0, strPhoto[3]); //在LCD1602屏第二行显示个位值 DisplayOneChar(10,0,l); DisplayOneChar(11,0,u); DisplayOneChar(12,0,x); }if(keyflag_11){DisplayOneChar(6, 1, max/1000x30); //在LCD1602屏第二行显示百位值 DisplayOneChar(7,1, max%100/100x30); //在LCD1602屏第二行显示十位值 DisplayOneChar(8, 1, max%100x30); //在LCD1602屏第二行显示个位值 }if(keyflag_12){DisplayOneChar(6, 1, min/1000x30); //在LCD1602屏第二行显示百位值 DisplayOneChar(7,1, min%100/100x30); //在LCD1602屏第二行显示十位值 DisplayOneChar(8, 1, min%100x30); //在LCD1602屏第二行显示个位值 }SendString(guangz:);SendData( strPhoto[0]);//显示湿度值SendData( strPhoto[1]);SendData( strPhoto[2]);SendData( strPhoto[3]);SendData( l);SendData( u);SendData( x);SendData( 0x0d);SendData( 0x0a);}} 四、 proteus仿真设计 Proteus软件是一款应用比较广泛的工具它可以在没有硬件平台的基础上通过自身的软件仿真出硬件平台的运行情况这样就可以通过软件仿真来验证我们设计的方案有没有问题如果有问题可以重新选择器件连接器件直到达到我们设定的目的避免我们搭建实物的时候如果当初选择的方案有问题我们器件都已经焊接好了再去卸载下去再去焊接新的方案的器件测试这样会浪费人力和物力也给开发者带来一定困惑Proteus仿真软件就很好的解决这个问题我们在设计之初就使用该软件进行模拟仿真测试选择满足我们设计的最优方案。最后根据测试没问题的仿真图纸焊接实物调试最终完成本设计的作品。