📄 analog.lst
字号:
C51 COMPILER V7.09 ANALOG 07/07/2004 14:57:17 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE ANALOG
OBJECT MODULE PLACED IN ANALOG.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ANALOG.C OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // Net ANALOG.C
3 //
4 // This module handles the analog inputs which are external temperature
5 // sensor, the on-chip temperature sensor, and operating voltage.
6 //-----------------------------------------------------------------------------
7 #include <string.h>
8 #include <stdlib.h>
9 #include "C8051f.h"
10 #include "net.h"
11 #include "serial.h"
12 #include "analog.h"
13
14 extern char xdata text[];
15 UINT idata cpu_temperature, air_temperature, cpu_voltage;
16 UCHAR idata mux_select;
17
18 sfr16 ADC0 = 0xbe; // ADC0 data
19
20 //--------------------------------------------------------------------------
21 // Initialize the A/D converter
22 //
23 //--------------------------------------------------------------------------
24 void init_adc(void)
25 {
26 1 ADC0CN = 0x81; // ADC0 enabled; normal tracking
27 1 // mode; ADC0 conversions are initiated
28 1 // on write to AD0BUSY; ADC0 data is
29 1 // left-justified
30 1 REF0CN = 0x07; // enable temp sensor, on-chip VREF,
31 1 // and VREF output buffer
32 1 mux_select = MUX_CPU_TEMP; // CPU on-chip temp sensor
33 1 AMX0SL = MUX_CPU_TEMP;
34 1
35 1 ADC0CF = (SYSCLK/2500000) << 3; // ADC conversion clock = 2.5MHz
36 1 // ADC0CF |= 0x01; // PGA gain = 2
37 1 EIE2 &= ~0x02; // disable ADC0 EOC interrupt
38 1 EIE1 &= ~0x04; // disable ADC0 window compare interrupt
39 1 }
40
41
42
43 //--------------------------------------------------------------------------
44 // This function is a little state machine which reads one analog
45 // inputs at a time, out of the 3 possible inputs
46 // 1. On-chip temperature
47 // 2. External air temperature
48 // 3. CPU operating voltage
49 //--------------------------------------------------------------------------
50 void read_analog_inputs(void)
51 {
52 1 ULONG idata temp_long;
53 1
54 1 AD0INT = 0; // clear conversion complete indicator
55 1 AD0BUSY = 1; // initiate conversion
C51 COMPILER V7.09 ANALOG 07/07/2004 14:57:17 PAGE 2
56 1 while (AD0INT == 0); // wait for conversion complete
57 1 switch (mux_select)
58 1 {
59 2 case MUX_CPU_TEMP:
60 2 temp_long = ADC0 - 42380/2;
61 2 temp_long= (temp_long * 200L) / 156;
62 2 cpu_temperature=temp_long;
63 2 AMX0SL = MUX_CPU_VOLTS; // Select AIN1 for next read
64 2 mux_select = MUX_CPU_VOLTS;
65 2 break;
66 2
67 2 case MUX_CPU_VOLTS:
68 2 temp_long = ADC0;
69 2 temp_long = 24*temp_long/655*10;
70 2 cpu_voltage = temp_long;
71 2 AMX0SL = MUX_AIR_TEMP; // Select on-chip temp sensor
72 2 mux_select = MUX_AIR_TEMP;
73 2 break;
74 2
75 2 case MUX_AIR_TEMP:
76 2 temp_long = ADC0;
77 2 temp_long = 24*temp_long/655*2;
78 2 air_temperature = temp_long;
79 2 AMX0SL = MUX_CPU_TEMP;
80 2 mux_select = MUX_CPU_TEMP;
81 2 break;
82 2
83 2 default:
84 2 AMX0SL = MUX_CPU_TEMP;
85 2 mux_select = MUX_CPU_TEMP;
86 2 break;
87 2 }
88 1 }
89
90
91
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 207 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 7 4
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -