analog.c

来自「这是为51单片机编的tcpip协议栈」· C语言 代码 · 共 63 行

C
63
字号
//-----------------------------------------------------------------------------
// Net ANALOG.C
//
// This module handles the analog inputs which are external temperature
// sensor, the on-chip temperature sensor, and operating voltage.
//-----------------------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include "AT89X52.h"
#include "net.h"
#include "serial.h"
#include "analog.h"

extern char xdata text[];
UINT idata cpu_temperature, air_temperature, cpu_voltage;
UCHAR idata mux_select;

//--------------------------------------------------------------------------
// Initialize the A/D converter
// 
//--------------------------------------------------------------------------
void init_adc(void)
{
	
}



//--------------------------------------------------------------------------
// This function is a little state machine which reads one analog
// inputs at a time, out of the 3 possible inputs
//  1. On-chip temperature
//  2. External air temperature
//  3. CPU operating voltage
//--------------------------------------------------------------------------
void read_analog_inputs(void)
{
   	switch (mux_select)
	{
		case MUX_CPU_TEMP:
	      	cpu_temperature++;
			mux_select = MUX_CPU_VOLTS;
		break;

		case MUX_CPU_VOLTS:
			cpu_voltage++;
			mux_select = MUX_AIR_TEMP;
		break;

		case MUX_AIR_TEMP:
			air_temperature++;
			mux_select = MUX_CPU_TEMP;
		break;

		default:
			mux_select = MUX_CPU_TEMP;
		break;
  	}
}
 

 

⌨️ 快捷键说明

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