www.pudn.com > tcpip5151.rar > Analog.c
//----------------------------------------------------------------------------- // Net ANALOG.C // // This module handles the analog inputs which are external temperature // sensor, the on-chip temperature sensor, and operating voltage. //----------------------------------------------------------------------------- #include#include #include #include #include "net.h" #include "serial.h" #include "analog.h" #include sbit adclk=P1^5; sbit addata=P1^6; sbit adcs=P1^7; #define uchar unsigned char #define uint unsigned int extern char xdata text[]; UINT idata cpu_temperature, air_temperature, cpu_voltage; UCHAR idata mux_select; /*********TLC549子程序***********************/ unsigned char ad(void) //TLC549的采样子程序 { // unsigned char i,sample_data; // bit ea_flag; // // ea_flag=EA; // EA=0; // adcs=0; // _nop_(); // _nop_(); // if(addata==1) // { // sample_data=1; // } // else // { // sample_data=0; // } // for(i=0;i<7;i++) // { // sample_data=(sample_data<<1); // adclk=1; // _nop_(); // _nop_(); // adclk=0; // if(addata==1) // { // sample_data=(sample_data|0x01); // } // } // adclk=1; // _nop_(); // _nop_(); // adclk=0; // _nop_(); // _nop_(); // // adcs=1; // EA=ea_flag; return 2500; } //-------------------------------------------------------------------------- // 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) { cpu_temperature=2500; air_temperature=(uint)ad()*19; cpu_voltage=50; }