📄 adcmain.lst
字号:
C51 COMPILER V7.10 ADCMAIN 06/25/2004 12:07:45 PAGE 1
C51 COMPILER V7.10, COMPILATION OF MODULE ADCMAIN
OBJECT MODULE PLACED IN adcMain.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE adcMain.c DEBUG OBJECTEXTEND
line level source
1 /*--------------------------------------------------------------------------
2 adcMain.c
3
4 Contains a sample program that implements the AD converter for the
5 Amtel Wirless T89C51CC01 and T89C51CC02.
6
7 Copyright (c) 1988-2001 Keil Elektronik GmbH and Keil Software, Inc.
8 All rights reserved.
9 --------------------------------------------------------------------------*/
10 #include <stdio.h>
11
12 sfr ADCON = 0xF3;
13 sfr ADCF = 0xF6;
14 sfr ADCLK = 0xF2;
15 sfr ADDH = 0xF5;
16 sfr ADDL = 0xF4;
17
18 sfr SCON = 0x98;
19 sfr TMOD = 0x89;
20 sfr TH1 = 0x8D;
21 sbit TR1 = 0x88^6;
22 sbit TI = 0x98^1;
23
24 /*=============================================================================
25 =============================================================================*/
26
27 /*=============================================================================
28 This function initializes the A/D Converter on the Atmel WM CC01 using
29 10-bits.
30 =============================================================================*/
31 void init_ADC (void)
32 {
33 1 ADCF = 0xFF; // Setup P1 as 8 ADC inputs
34 1
35 1 ADCLK = 0x1F; // Set AD Clock divisor to 32 (the maximum)
36 1
37 1 ADCON |= 0x20; // Enable the A/D Converter
38 1 }
39
40 /*=============================================================================
41 This function sets the A/D channel to convert and starts a conversion.
42 The 10-bit value is returned.
43 =============================================================================*/
44 unsigned read_ADC (unsigned char channel)
45 {
46 1 ADCON &= ~0x07; // Clear channel bits
47 1 ADCON |= 0x07 & channel; // Set channel to convert
48 1
49 1 ADCON |= 0x08; // Start a Conversion
50 1
51 1 while( ADCON & 0x8 ); //Wait for conversion to end
52 1
53 1 return (((unsigned) ADDH << 2) | (ADDL & 3));
54 1 }
55
C51 COMPILER V7.10 ADCMAIN 06/25/2004 12:07:45 PAGE 2
56 /*=============================================================================
57 =============================================================================*/
58 void main(void)
59 {
60 1 unsigned char i;
61 1
62 1 /*-----------------------------------------------
63 1 Setup the serial port.
64 1 -----------------------------------------------*/
65 1 SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
66 1 TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
67 1 TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
68 1 TR1 = 1; /* TR1: timer 1 run */
69 1 TI = 1; /* TI: set TI to send first char of UART */
70 1
71 1 /*-----------------------------------------------
72 1 Initialize the A/D Converter
73 1 -----------------------------------------------*/
74 1 init_ADC ();
75 1
76 1 /*-----------------------------------------------
77 1 Loop thru each channel and output the converted
78 1 value.
79 1 -----------------------------------------------*/
80 1 while (1)
81 1 {
82 2 for (i = 0; i < 8; i++)
83 2 {
84 3 printf ("Channel %u = %4u\n", (unsigned) i, read_ADC (i));
85 3 }
86 2 }
87 1 }
88
89 /*=============================================================================
90 =============================================================================*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 99 ----
CONSTANT SIZE = 18 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 1
IDATA SIZE = ---- ----
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 + -