📄 hal_adc.lst
字号:
\ In segment CODE_C, align 1
81 static __code const uint16 HalAdcVddLimit[] =
\ ??HalAdcVddLimit:
\ 000000 9C36063A DW 13980, 14854, 15728, 16601, 17475, 18349, 19223, 20097, 20970
\ 703DD940
\ 4344AD47
\ 174B814E
\ EA51
82 {
83 0x369C, /* VDD Limit - 1.6v */
84 0x3A06, /* VDD Limit - 1.7v */
85 0x3D70, /* VDD Limit - 1.8v */
86 0x40D9, /* VDD Limit - 1.9v */
87 0x4443, /* VDD Limit - 2.0v */
88 0x47AD, /* VDD Limit - 2.1v */
89 0x4B17, /* VDD Limit - 2.2v */
90 0x4E81, /* VDD Limit - 2.3v */
91 0x51EA, /* VDD Limit - 2.4v */
92 };
93
94
95 /**************************************************************************************************
96 * MACROS
97 **************************************************************************************************/
98 #define HAL_ADC_CLR_EOC() asm("PUSH A"); asm("MOV A,ADCL"); asm("MOV A,ADCH"); asm("POP A");
99
100 /**************************************************************************************************
101 * TYPEDEFS
102 **************************************************************************************************/
103
104 /**************************************************************************************************
105 * GLOBAL VARIABLES
106 **************************************************************************************************/
107
108 /**************************************************************************************************
109 * FUNCTIONS - API
110 **************************************************************************************************/
111 extern bool HalAdcCheckVdd (uint8 limit);
112
113 /**************************************************************************************************
114 * @fn HalAdcInit
115 *
116 * @brief Initialize ADC Service
117 *
118 * @param None
119 *
120 * @return None
121 **************************************************************************************************/
\ In segment BANKED_CODE, align 1, keep-with-next
122 void HalAdcInit (void)
\ HalAdcInit:
123 {
\ 000000 C082 PUSH DPL
\ 000002 C083 PUSH DPH
\ 000004 ; Saved register size: 2
\ 000004 ; Auto size: 1
\ 000004 74FF MOV A,#-0x1
\ 000006 12.... LCALL ?ALLOC_XSTACK8
124 #if (HAL_ADC == TRUE)
125 volatile uint8 tmp;
126
127 ADCCON1 = HAL_ADC_STSEL | HAL_ADC_RAND_GEN | 0x03;
\ 000009 75B43F MOV 0xb4,#0x3f
128 ADCCON2 = HAL_ADC_REF_VOLT | HAL_ADC_DEC_RATE | HAL_ADC_SCHN;
\ 00000C 75B58F MOV 0xb5,#-0x71
129 /*
130 * After reset, the first ADC reading of the extra conversion always reads GND level.
131 * We will do a few dummy conversions to bypass this bug.
132 */
133 tmp = ADCL; /* read ADCL,ADCH to clear EOC */
\ 00000F E5BA MOV A,0xba
\ 000011 85..82 MOV DPL,?XSP + 0
\ 000014 85..83 MOV DPH,?XSP + 1
\ 000017 F0 MOVX @DPTR,A
134 tmp = ADCH;
\ 000018 E5BB MOV A,0xbb
\ 00001A F0 MOVX @DPTR,A
135 ADCCON3 = HAL_ADC_REF_VOLT | HAL_ADC_DEC_RATE | HAL_ADC_ECHN;
\ 00001B 75B68C MOV 0xb6,#-0x74
136 while ((ADCCON1 & HAL_ADC_EOC) != HAL_ADC_EOC); /* Wait for conversion */
\ ??HalAdcInit_0:
\ 00001E E5B4 MOV A,0xb4
\ 000020 A2E7 MOV C,0xE0 /* A */.7
\ 000022 50FA JNC ??HalAdcInit_0
137 tmp = ADCL; /* read ADCL,ADCH to clear EOC */
\ 000024 E5BA MOV A,0xba
\ 000026 F0 MOVX @DPTR,A
138 tmp = ADCH;
\ 000027 E5BB MOV A,0xbb
\ 000029 F0 MOVX @DPTR,A
139 ADCCON3 = HAL_ADC_REF_VOLT | HAL_ADC_DEC_RATE | HAL_ADC_ECHN;
\ 00002A 75B68C MOV 0xb6,#-0x74
140 while ((ADCCON1 & HAL_ADC_EOC) != HAL_ADC_EOC); /* Wait for conversion */
\ ??HalAdcInit_1:
\ 00002D E5B4 MOV A,0xb4
\ 00002F A2E7 MOV C,0xE0 /* A */.7
\ 000031 50FA JNC ??HalAdcInit_1
141 tmp = ADCL; /* read ADCL,ADCH to clear EOC */
\ 000033 E5BA MOV A,0xba
\ 000035 F0 MOVX @DPTR,A
142 tmp = ADCH;
\ 000036 E5BB MOV A,0xbb
\ 000038 F0 MOVX @DPTR,A
143 #endif
144 }
\ 000039 7401 MOV A,#0x1
\ 00003B 12.... LCALL ?DEALLOC_XSTACK8
\ 00003E REQUIRE ?Subroutine0
\ 00003E ; // Fall through to label ?Subroutine0
\ In segment BANKED_CODE, align 1, keep-with-next
\ ?Subroutine0:
\ 000000 D083 POP DPH
\ 000002 D082 POP DPL
\ 000004 02.... LJMP ?BRET
145
146 /**************************************************************************************************
147 * @fn HalAdcRead
148 *
149 * @brief Read the ADC based on given channel and resolution
150 *
151 * @param channel - channel where ADC will be read
152 * @param resolution - the resolution of the value
153 *
154 * @return 16 bit value of the ADC in offset binary format.
155 * Note that the ADC is "bipolar", which means the GND (0V) level is mid-scale.
156 **************************************************************************************************/
\ In segment BANKED_CODE, align 1, keep-with-next
157 uint16 HalAdcRead (uint8 channel, uint8 resolution)
\ HalAdcRead:
158 {
\ 000000 74F6 MOV A,#-0xa
\ 000002 12.... LCALL ?BANKED_ENTER_XDATA
\ 000005 ; Saved register size: 10
\ 000005 ; Auto size: 1
\ 000005 74FF MOV A,#-0x1
\ 000007 12.... LCALL ?ALLOC_XSTACK8
159 int16 reading = 0;
160
161 #if (HAL_ADC == TRUE)
162
163 uint8 i, resbits;
164 uint8 adctemp;
165 volatile uint8 tmp;
166 uint8 adcChannel = 1;
\ 00000A 7C01 MOV R4,#0x1
167
168 /*
169 * If Analog input channel is AIN0..AIN7, make sure corresponing P0 I/O pin is enabled. The code
170 * does NOT disable the pin at the end of this function. I think it is better to leave the pin
171 * enabled because the results will be more accurate. Because of the inherent capacitance on the
172 * pin, it takes time for the voltage on the pin to charge up to its steady-state level. If
173 * HalAdcRead() has to turn on the pin for every conversion, the results may show a lower voltage
174 * than actuality because the pin did not have time to fully charge.
175 */
176 if (channel < 8)
\ 00000C E9 MOV A,R1
\ 00000D C3 CLR C
\ 00000E 9408 SUBB A,#0x8
\ 000010 500E JNC ??HalAdcRead_0
177 {
178 for (i=0; i < channel; i++)
\ 000012 7B00 MOV R3,#0x0
\ 000014 8005 SJMP ??HalAdcRead_1
179 {
180 adcChannel <<= 1;
\ ??HalAdcRead_2:
\ 000016 EC MOV A,R4
\ 000017 C3 CLR C
\ 000018 33 RLC A
\ 000019 FC MOV R4,A
181 }
\ 00001A 0B INC R3
\ ??HalAdcRead_1:
\ 00001B EB MOV A,R3
\ 00001C C3 CLR C
\ 00001D 99 SUBB A,R1
\ 00001E 40F6 JC ??HalAdcRead_2
182 }
183
184 /* Enable channel */
185 ADCCFG |= adcChannel;
\ ??HalAdcRead_0:
\ 000020 EC MOV A,R4
\ 000021 45F2 ORL A,0xf2
\ 000023 F5F2 MOV 0xf2,A
186
187 /* Convert resolution to decimation rate */
188 switch (resolution)
\ 000025 EA MOV A,R2
\ 000026 12.... LCALL ?UC_SWITCH_DENSE
\ `?<Jumptable for HalAdcRead>_0`:
\ 000029 01 DB 1
\ 00002A 02 DB 2
\ 00002B .... DW ??HalAdcRead_3
\ 00002D .... DW ??HalAdcRead_4
\ 00002F .... DW ??HalAdcRead_5
\ 000031 .... DW ??HalAdcRead_6
189 {
190 case HAL_ADC_RESOLUTION_8:
191 resbits = HAL_ADC_DEC_064;
\ ??HalAdcRead_4:
\ 000033 7B00 MOV R3,#0x0
\ 000035 800A SJMP ??HalAdcRead_7
192 break;
193 case HAL_ADC_RESOLUTION_10:
194 resbits = HAL_ADC_DEC_128;
\ ??HalAdcRead_5:
\ 000037 7B10 MOV R3,#0x10
\ 000039 8006 SJMP ??HalAdcRead_7
195 break;
196 case HAL_ADC_RESOLUTION_12:
197 resbits = HAL_ADC_DEC_256;
\ ??HalAdcRead_6:
\ 00003B 7B20 MOV R3,#0x20
\ 00003D 8002 SJMP ??HalAdcRead_7
198 break;
199 case HAL_ADC_RESOLUTION_14:
200 default:
201 resbits = HAL_ADC_DEC_512;
\ ??HalAdcRead_3:
\ 00003F 7B30 MOV R3,#0x30
202 break;
203 }
204
205 /* read ADCL,ADCH to clear EOC */
206 tmp = ADCL;
\ ??HalAdcRead_7:
\ 000041 E5BA MOV A,0xba
\ 000043 85..82 MOV DPL,?XSP + 0
\ 000046 85..83 MOV DPH,?XSP + 1
\ 000049 F0 MOVX @DPTR,A
207 tmp = ADCH;
\ 00004A E5BB MOV A,0xbb
\ 00004C F0 MOVX @DPTR,A
208
209 /* Setup Sample */
210 adctemp = ADCCON3;
\ 00004D E5B6 MOV A,0xb6
211 adctemp &= ~(HAL_ADC_CHN_BITS | HAL_ADC_DEC_BITS | HAL_ADC_REF_BITS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -