⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 多点温度检测系统
💻 C
字号:
#include <reg51.h>
#include <stdio.h>
#include <string.h>
#include "TMP100.h"
#include "Led.h"
#include "I2C.h"

int tempbuf;
char tempjust;

char UartRec(void)
{
	while(RI == 0);
	RI = 0;
	return(SBUF);
}
void UartPut(char dd)
{
	while(TI == 0);
	TI = 0;
	SBUF = dd;
}

void main(void)
{	
	char idata uartbuf[10];
	char uartpoint = 0;
//	char ttmp;
	unsigned int i;

	TMOD |= 0x01;
	TH0 = 0x4b;
	TL0 = 0xfd;
	TR0 = 1;
	ET0 = 1;
	EA = 1;

    SCON  = 0x50;
    TMOD |= 0x20;
    TH1   = 0xfd;
    TR1   = 1;   
    TI    = 1;   

	Tmp100Init();

//	UartPut(0x01);
//	if(UartRec() == 0x02)
//		UartPut(0x02);
	while(1)
	{
	uartbuf[0] = UartRec();
	uartbuf[1] = UartRec();
	uartbuf[2] = UartRec();
	uartbuf[3] = '\0';
	if(strcmp(uartbuf,"ge0") == 0)
	{
		for(i = 0; i < 5000; i++);
		UartPut(0x00);	
		for(i = 0; i < 5000; i++);
		UartPut(tempbuf>>8);				//第一次送出高八位
		for(i = 0; i < 5000; i++);
		UartPut(tempbuf&0xff);				//第二次送出低八位
	}
	else if(strncmp(uartbuf,"s0",2) == 0)
		tempjust = uartbuf[2];				//取出缓冲区中的校正值
	}
}

void time0_isr(void) interrupt 1
{
	static unsigned char i;
	char ledbuf[3];

	TR0 = 0;
	TH0 = 0x4b;	  //50ms
	TL0 = 0xfd;

	if(i++ == 10)					//每0.5秒读一次
	{
		i = 0;
    	tempbuf = Tmp100Get();	//读取Tmp100当前温度

		tempbuf >>= 4;
		tempbuf += tempjust;
		tempbuf <<= 4;

		if((tempbuf >> 8) >= 100)
		{
			ledbuf[0] = 9;
			ledbuf[1] = 9;
			ledbuf[2] = 9;
			LedSet(ledbuf);
		}
		else
		{
			ledbuf[0] =  (unsigned char)(tempbuf >> 8) / 10;			//取出十位
			ledbuf[1] =  (unsigned char)(tempbuf >> 8) % 10;			//取出个位
			ledbuf[2] =  (unsigned char)((float)((tempbuf >> 4) & 0x0f) * 10 * 0.0625);
			LedSet(ledbuf);
		}
	}		
	TR0 = 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -