Demo entry 6363960

py

   

Submitted by lu on May 15, 2017 at 07:45
Language: C. Code size: 1.5 kB.

#include "reg52.h"
#include "stdio.h"
#include <string.h>
#include "lcd1602.h"
#include "ds1.h"
#include "keyscan.h"

sbit beep = P2^4;
sbit relay = P3^2;

unsigned int TLP1;    //储存暂存器的温度低位
unsigned int THP1;    //储存暂存器的温度高位
unsigned int TNP1;    //储存温度的整数部分
unsigned int TDP1;    //储存温度的小数部分

unsigned char keynum = 0;
int flag = 0,cnt = 0;
int set=30;
int startflag;

unsigned char str1[16]=" ";
unsigned char str2[8]= " ";




void main() 
{ 

LCD_Init(); 
LCD_Clear();//清屏	



while (1) 
 {  
	 
		ReadyReadTemp_1();     //读温度准备
		TLP1=ReadOneChar_1();    //先读的是温度值低位
		THP1=ReadOneChar_1();    //接着读的是温度值高位
		TNP1=THP1*16+TLP1/16;      //实际温度值=(TH*256+TL)/16,即:TH*16+TL/16									
		TDP1=(TLP1%16)*10/16;    //计算温度的小数部分,将余数乘以10再除以16取整,
	 
		sprintf(str1, "Temp=%d.%dC",TNP1,TDP1);
		LCD_Write_String(0,0,&str1);
	 	sprintf(str2, "Set =%2dC",set);
		LCD_Write_String(0,1,&str2);
	 
		keynum=keyscan(0);
	 
		switch(keynum)
	  {
		case 1:	
							startflag=1;
							break;
		case 2:	
							if(startflag)
							{
								set+=1;
								if(set>=60)
								set=60;
							}
							break;
		case 3:	
							if(startflag)
							{
							set-=1;
							if(set<=0)
							set=0;
							}
							break;
		case 4:	
							startflag=0;
							break;
		
	 }
	 
	
	 if(TNP1>=set)
	 {
				beep=0;
		  	LCD_Write_String(12,1,"OFF");
	 }
	 else
	 {
		  	beep=1;
	    	LCD_Write_String(12,1,"ON ");

		}
			
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).