📄 main.lst
字号:
160 5 }
161 4
162 4 }
163 3 }
164 2 }
165 1 }
166
167 void ADC0_ISR (void) interrupt 15
168 {
169 1 static unsigned int_dec=INT_DEC; // integrate/decimate counter
170 1 // we post a new result when
171 1 // int_dec = 0
172 1 static long accumulator=0L; // here's where we integrate the
173 1 // ADC samples
174 1
175 1 AD0INT = 0; // clear ADC conversion complete
176 1 // indicator
177 1
178 1 accumulator += ADC0; // read ADC value and add to running
179 1 // total
C51 COMPILER V6.23a MAIN 04/15/2002 18:18:04 PAGE 4
180 1 int_dec--; // update decimation counter
181 1
182 1 if (int_dec == 0) { // if zero, then post result
183 2 int_dec = INT_DEC; // reset counter
184 2 result = accumulator >> 8;
185 2 accumulator = 0L; // reset accumulator
186 2 }
187 1 }
188 void Delay1ms(unsigned char T)
189 {
190 1 Count1ms=T;
191 1 while (Count1ms);
192 1 }
193
194 void main (void) {
195 1 long temperature; // temperature in hundredths of a degree C
196 1 int temp_int, temp_frac; // integer and fractional portions of temperature
197 1 char ch;
198 1
199 1 WDTCN = 0xde; // disable watchdog timer
200 1 WDTCN = 0xad;
201 1 TimerCount=100;
202 1 TimerCount10=10;
203 1
204 1 Count1ms=1;
205 1 Count100ms=1;
206 1 Count1s=1;
207 1 SYSCLK_Init (); // initialize oscillator
208 1 PORT_Init (); // initialize crossbar and GPIO
209 1
210 1 OpenComm(); // initialize UART0
211 1 OpenComm1(); // initialize UART1
212 1
213 1 SW_UART_INIT0(); // initialize UART2
214 1 SW_UART_ENABLE0();
215 1 SW_UART_INIT1(); // initialize UART3
216 1 SW_UART_ENABLE1();
217 1
218 1
219 1 ClearCommRecBuffer();
220 1 ClearCommRecBuffer1();
221 1 ClearCommRecBuffer2();
222 1 ClearCommRecBuffer3();
223 1
224 1 Timer3_Init (SYSCLK/SAMPLE_RATE); // initialize Timer3 to overflow at sample rate
225 1 Timer0_Init (TIMER0_COUNT);
226 1 ADC0_Init (); // init ADC
227 1 AD0EN = 1; // enable ADC
228 1 EA = 1; // Enable global interrupts
229 1 Delay1ms(2);
230 1 SendCommBuffer("Init OK\r\n",9);
231 1 SendCommString("at\r");
232 1 GetCommCharWait(&ch,10);
233 1 SendCommBuffer1("A",1);
234 1 SendCommString1("A");
235 1 SendCommChar1('A');
236 1 GetCommCharWait1(&ch,1);
237 1
238 1 SendCommChar2('a');
239 1 SendCommBuffer2("t\r",2);
240 1 SendCommBuffer2("at\r",2);
241 1
C51 COMPILER V6.23a MAIN 04/15/2002 18:18:04 PAGE 5
242 1 SendCommChar3('a');
243 1 SendCommBuffer3("t\r",2);
244 1 SendCommBuffer3("at\r",2);
245 1
246 1
247 1 while (1)
248 1 {
249 2 if (Flag1ms)
250 2 {
251 3 Flag1ms=0;
252 3 }
253 2 if (Flag100ms)
254 2 {
255 3 Flag100ms=0;
256 3 }
257 2 if (Flag1s)
258 2 {
259 3 Flag1s=0;
260 3 EIE2 &= ~0x02; // Disenable ADC interrupts
261 3 temperature = result;
262 3 EIE2 |= 0x02; // enable ADC interrupts
263 3 }
264 2 if (SendTempFlag)
265 2 {
266 3 temperature = temperature - 42380;
267 3 temperature = (temperature * 100L) / 156;
268 3 temp_int = temperature / 100;
269 3 temp_frac = temperature - (temp_int * 100);
270 3 SendCommBuffer("T=",2);
271 3 SendCommChar(0x30+temp_int/100);
272 3 SendCommChar(0x30+temp_int%100/10);
273 3 SendCommChar(0x30+temp_int%10);
274 3 SendCommChar('.');
275 3 SendCommChar(0x30+temp_frac%100/10);
276 3 SendCommChar(0x30+temp_frac%10);
277 3 SendCommBuffer("\r\n",2);
278 3 SendTempFlag=0;
279 3 }
280 2 if (FlagRecComm)
281 2 {
282 3 if (GetCommChar(&ch))
283 3 {
284 4 SendCommChar(ch);
285 4 }
286 3 }
287 2 if (FlagRecComm1)
288 2 {
289 3 if (GetCommChar1(&ch))
290 3 {
291 4 SendCommChar1(ch);
292 4 }
293 3 }
294 2 if (FlagRecComm2)
295 2 {
296 3 if (GetCommChar2(&ch))
297 3 {
298 4 SendCommChar2(ch);
299 4 }
300 3 }
301 2 if (FlagRecComm3)
302 2 {
303 3 if (GetCommChar3(&ch))
C51 COMPILER V6.23a MAIN 04/15/2002 18:18:04 PAGE 6
304 3 {
305 4 SendCommChar3(ch);
306 4 }
307 3 }
308 2 }
309 1 }
310
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 990 ----
CONSTANT SIZE = 25 ----
XDATA SIZE = 510 ----
PDATA SIZE = ---- ----
DATA SIZE = 20 11
IDATA SIZE = ---- ----
BIT SIZE = 11 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -