You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
6.0 KiB
166 lines
6.0 KiB
C51 COMPILER V8.02 A2D 02/07/2008 21:06:49 PAGE 1
|
|
|
|
|
|
C51 COMPILER V8.02, COMPILATION OF MODULE A2D
|
|
OBJECT MODULE PLACED IN A2D.OBJ
|
|
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE A2D.c OMF2 ROM(COMPACT) OPTIMIZE(9,SPEED) ORDER NOINTPROMOTE NOINTVECTOR
|
|
|
|
line level source
|
|
|
|
1 #include "StdAfx.h"
|
|
2 #include "SysClock.h"
|
|
3 #include "A2D.h"
|
|
4 #include "Timer.h"
|
|
5
|
|
6 static WORD wValueA2D;
|
|
7
|
|
8 sfr16 ADC0 = 0xBE; // ADC0 data
|
|
9
|
|
10 #define ADC_SAR_CLOCK 2500000L
|
|
11
|
|
12 void ADC0_Init()
|
|
13 {
|
|
14 1 // Save Current SFR page
|
|
15 1 XBYTE SFRPAGE_SAVE = SFRPAGE;
|
|
16 1
|
|
17 1 XBYTE nSAR = SYSCLK / (2 * ADC_SAR_CLOCK) - 1;
|
|
18 1
|
|
19 1 // Set ADC page
|
|
20 1 SFRPAGE = ADC0_PAGE;
|
|
21 1
|
|
22 1 // enable temp sensor, on-chip VREF,
|
|
23 1 // and VREF output buffer
|
|
24 1 REF0CN = 0x07;
|
|
25 1
|
|
26 1 // select TEMP sens as ADC mux output
|
|
27 1 AMX0SL = 0x0F;
|
|
28 1
|
|
29 1 // all inputs a independant
|
|
30 1 AMX0CF = 0x00;
|
|
31 1
|
|
32 1 // ADC0 disabled; normal tracking
|
|
33 1 // mode; ADC0 conversions are initiated
|
|
34 1 // on Busy bit; ADC0 data is
|
|
35 1 // right-justified
|
|
36 1 ADC0CN = 0x00;
|
|
37 1 // ADC conversion clock = 2.5 MHz
|
|
38 1 ADC0CF = 0x20;//nSAR << 3;
|
|
39 1 // PGA gain = 1
|
|
40 1 ADC0CF |= 0x00;
|
|
41 1
|
|
42 1 // set tracking mode
|
|
43 1 AD0TM = 0;//1; // for mirror was 1, for normal system is 0. ???
|
|
44 1
|
|
45 1 // enable ADC
|
|
46 1 AD0EN = 1;
|
|
47 1
|
|
48 1 // Restore SFR page
|
|
49 1 SFRPAGE = SFRPAGE_SAVE;
|
|
50 1 }
|
|
51 /*
|
|
52 void ADC0_Start( BYTE bChannel )
|
|
53 {
|
|
54 XBYTE SFRPAGE_SAVE = SFRPAGE;
|
|
55
|
|
C51 COMPILER V8.02 A2D 02/07/2008 21:06:49 PAGE 2
|
|
|
|
56 SFRPAGE = ADC0_PAGE;
|
|
57
|
|
58 AMX0SL = bChannel;
|
|
59 AD0INT = 0;
|
|
60 AD0BUSY = 1;
|
|
61
|
|
62 SFRPAGE = SFRPAGE_SAVE;
|
|
63 }
|
|
64
|
|
65 BOOL ADC0_GetValue( PWORD pValue )
|
|
66 {
|
|
67 XBYTE SFRPAGE_SAVE = SFRPAGE;
|
|
68 SFRPAGE = ADC0_PAGE;
|
|
69
|
|
70 if( !AD0INT )
|
|
71 {
|
|
72 SFRPAGE = SFRPAGE_SAVE;
|
|
73
|
|
74 return FALSE;
|
|
75 }
|
|
76
|
|
77 AD0INT = 0;
|
|
78
|
|
79 *pValue = ADC0;
|
|
80
|
|
81 SFRPAGE = SFRPAGE_SAVE;
|
|
82
|
|
83 return TRUE;
|
|
84 }
|
|
85 */
|
|
86 WORD ADC0_Convert( BYTE bChannel )
|
|
87 {
|
|
88 1 static BYTE SFRPAGE_SAVE;
|
|
89 1 SFRPAGE_SAVE = SFRPAGE;
|
|
90 1 SFRPAGE = ADC0_PAGE;
|
|
91 1
|
|
92 1 // select channel
|
|
93 1 AMX0SL = bChannel;
|
|
94 1 AD0INT = 0;
|
|
95 1
|
|
96 1 // settling time for accurate conversion (around 2.5 uS on 100 MHz)
|
|
97 1 // HiResTimer0_Wait( MICRO_SEC_TO_HIRES(2) );
|
|
98 1 HiResTimer1_Wait( 5 );
|
|
99 1
|
|
100 1 // start conversion
|
|
101 1 AD0BUSY = 1;
|
|
102 1
|
|
103 1 // wait for end of conversion
|
|
104 1 while( !AD0INT );
|
|
105 1
|
|
106 1 // clear condition
|
|
107 1 AD0INT = 0;
|
|
108 1
|
|
109 1 // copy result
|
|
110 1 wValueA2D = ADC0;
|
|
111 1
|
|
112 1 SFRPAGE = SFRPAGE_SAVE;
|
|
113 1
|
|
114 1 return wValueA2D;
|
|
115 1 }
|
|
116
|
|
117 /*
|
|
C51 COMPILER V8.02 A2D 02/07/2008 21:06:49 PAGE 3
|
|
|
|
118 LONG ADC0_Adc2Temperature( WORD wValue )
|
|
119 {
|
|
120 LONG lTemperature = ( ((LONG)(INT)wValue) * V_REF * 1000L - 7760L * MAX_ADC * PGAIN ) / ( 286L * MAX_ADC
|
|
- * PGAIN / 10L );
|
|
121
|
|
122 // compensate self heating
|
|
123 return lTemperature;// * 10000L / 11875L;
|
|
124 }
|
|
125
|
|
126 WORD ADC0_Temperature2Adc( LONG lTemperature )
|
|
127 {
|
|
128 wValueA2D = (lTemperature * ( 286L * MAX_ADC * PGAIN / 10L ) + 7760L * MAX_ADC * PGAIN) / (V_REF * 1000L
|
|
-);
|
|
129
|
|
130 // compensate self heating
|
|
131 return wValueA2D;// * 11875L / 10000L;
|
|
132 }
|
|
133 */
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE
|
|
CODE SIZE = 74 ----
|
|
CONSTANT SIZE = ---- ----
|
|
XDATA SIZE = ---- 2
|
|
PDATA SIZE = ---- ----
|
|
DATA SIZE = 3 ----
|
|
IDATA SIZE = ---- ----
|
|
BIT SIZE = ---- ----
|
|
EDATA SIZE = ---- ----
|
|
HDATA SIZE = ---- ----
|
|
XDATA CONST SIZE = ---- ----
|
|
FAR CONST SIZE = ---- ----
|
|
END OF MODULE INFORMATION.
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|