measure.c

来自「这是一个远程温度计 MCU: AT89S52 温度传感器: DS18B20」· C语言 代码 · 共 51 行

C
51
字号
/*------------------------------------------------------------------------------
MCOMMAND.C:  Time Set Commands for the Remote Measurement
------------------------------------------------------------------------------*/

#include <stdio.h>		/* standard ANSI I/O .h-file         */
#include <reg52.h>		/* special function register 80515   */
#include "type.h"
#include "measure.h"		/* global project definition file    */

struct mrec current;		/* current measurements           */



/******************************************************************************/
/*                           Display measurements                             */
/******************************************************************************/
void measure_display(struct mrec display)
{
	P1 ^= 0x01;				/* Toggle P1.0 each time we print */	
	printf("\r当前系统时间: %2bd:%02bd:%02bd    当前温度: %s 摄氏度",
	  display.time.hour,	/* display hour                      */
	  display.time.min,	/* display minute                    */
	  display.time.sec,	/* display second                    */
	  display.temper);	    /* display thermometer value         */
}


/******************************************************************************/
/*                           Set Current Time                                 */
/******************************************************************************/
void set_time(uchar *buffer)
{
	struct clock time;	/* temporary time values             */
	uchar args;	/* number of arguments               */

	time.sec = 0;		/* preset seconds...                 */
	args = sscanf(buffer, "%bd:%bd:%bd",	/* scan input line for               */
		      &time.hour,	/* hour, minute and second           */
		      &time.min, &time.sec);
	if (time.hour > 23 || time.min > 59 ||	/* check for valid inputs      */
	    time.sec > 59 || args < 2 || args == EOF) {
		printf(ERROR, "INVALID TIME FORMAT");
	} else {		/* if inputs valid then              */
		DISABLE();	/* disable interrupts while          */
		current.time = time;	/* setting the new time              */
		ENABLE();	/* enable interrupts again           */
	}
}


⌨️ 快捷键说明

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