资源描述:
《单片机多机多点温控系统从机模块》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//DS从机程序#include#include12#defineucharunsignedchar#defineuintunsignedint#defineSLAVE0x01#defineBN6sbitLCD_RS=P2^5;/*定义LCD控制端口*/sbitLCD_RW=P2^6;sbitLCD_EN=P2^7;sbitDS1=P1^0;sbitDS2=P1^1;sbitkey3=P3^5;sbittem=P3^3;sbitwin=P3^4;sbitkey1=P3^6;s
2、bitkey2=P3^7;uinttemp1,temp2,tempH,tempL;//variableoftemperatureucharflag1,aa,we;ucharA1,A2,A3,A4,B1,B2,B3,B4;//signoftheresultpositiveornegativeuchardis1[16]={76,45,84,'0','0','.','0',32,32,72,45,84,'0','0','.','0'};uchardis2[16]={48,49,32,'0','0','.','0',32,
3、32,48,50,32,'0','0','.','0'};ucharcodetab[]={'0','1','2','3','4','5','6','7','8','9'};uchartrbuf[6];bittready;bitrready;voidstr(void);voidsre(void);voiddelay(intms){inti;while(ms--){for(i=0;i<250;i++){_nop_();_nop_();_nop_();_nop_();}}}/***********************
4、********************************************//**//*检查LCD忙状态*//*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。*//**//*******************************************************************/bitlcd_busy(){bitresult;LCD_RS=0;12LCD_RW=1;LCD_EN=1;_nop_();_nop_();_nop_();_nop_(
5、);result=(bit)(P0&0x80);LCD_EN=0;returnresult;}/*******************************************************************//**//*写指令数据到LCD*//*RS=L,RW=L,E=高脉冲,D0-D7=指令码。*//**//*******************************************************************/voidlcd_wcmd(ucharcmd){w
6、hile(lcd_busy());LCD_RS=0;LCD_RW=0;LCD_EN=0;_nop_();_nop_();P0=cmd;_nop_();_nop_();_nop_();_nop_();LCD_EN=1;_nop_();_nop_();_nop_();_nop_();LCD_EN=0;}/*******************************************************************//**//*写显示数据到LCD*//*RS=H,RW=L,E=高脉冲,D0-D7=
7、数据。*//**//*******************************************************************/voidlcd_wdat(uchardat){while(lcd_busy());LCD_RS=1;LCD_RW=0;LCD_EN=0;P0=dat;_nop_();12_nop_();_nop_();_nop_();LCD_EN=1;_nop_();_nop_();_nop_();_nop_();LCD_EN=0;}/*********************
8、**********************************************//**//*设定显示位置*//**//*******************************************************************/voidlcd_pos(ucharpos){lcd_wcmd(pos
9、0x80);//数据指