📄 adcmain.lst
字号:
C51 COMPILER V6.14g ADCMAIN 07/15/2001 18:08:54 PAGE 1
C51 COMPILER V6.14g, COMPILATION OF MODULE ADCMAIN
OBJECT MODULE PLACED IN adcMain.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE adcMain.c DEBUG OBJECTEXTEND
stmt level source
1 /*--------------------------------------------------------------------------
2 adcMain.c
3
4 Contains a sample program that implements the AD converter for the
5 Amtel Wirless T87C5111 and T87C5112.
6
7 Copyright (c) 1988-2001 Keil Elektronik GmbH and Keil Software, Inc.
8 All rights reserved.
9 --------------------------------------------------------------------------*/
10
11 #include <stdio.h>
12
13 sfr ADCLK = 0xF2;
14 sfr ADCON = 0xF3;
15 sfr ADDL = 0xF4;
16 sfr ADDH = 0xF5;
17 sfr ADCF = 0xF6;
18
19 sfr IE1 = 0xB1;
20 sbit EA = 0xA8^7;
21
22 sfr SCON = 0x98;
23 sbit TI = SCON^1;
24
25 sfr TMOD = 0x89;
26 sfr TH1 = 0x8D;
27
28 sbit TR1 = 0x88^6;
29
30 /******************************************************************************
31 This function is called when the AD conversion is finished by the CPU. This
32 is only used when in Accurate or Precision mode.
33 ******************************************************************************/
34 void ADC_INT( void ) interrupt 9
35 {
36 1 ADCON &= ~0x10;
37 1 }
38
39
40 /******************************************************************************
41 This function Initializes all values required to run the AD converter.
42 ******************************************************************************/
43
44 void Init_ADC( void )
45 {
46 1 ADCF |= 0xFF; //Sets all channels for available input
47 1 ADCLK |= 0x7F; //Sets clock to second slowest value
48 1 ADCON |= 0x20; //Enables the ADC
49 1 //ADCON |= 0x80; //Sets QUIETM bit for Accurate conversion (10bit)
50 1 //ADCON |=0x40; //Sets PSIDLE bit for Precision conversion (9bit)
51 1
52 1 IE1 |= 0x20; //Enable ADC Interrupt
53 1 EA = 1; //Enable Global Interrupts
54 1 }
55
C51 COMPILER V6.14g ADCMAIN 07/15/2001 18:08:54 PAGE 2
56
57 /******************************************************************************
58 This function reads a channel and starts the AD conversion
59 ******************************************************************************/
60 unsigned Read_ADC( unsigned char channel )
61 {
62 1 ADCON &= ~0x07; //Clear channel bits
63 1 ADCON |= 0x07 & channel; //Sets channel to be read in ADCON
64 1
65 1 ADCON |= 0x8; //Start Conversion
66 1 while( ADCON & 0x8 );
67 1 return( ((unsigned) ADDH << 2) | (ADDL & 3) );
68 1 }
69 /******************************************************************************
70 Main Function. Read each channel and outputs the converted value
71 ******************************************************************************/
72
73 void main( void )
74 {
75 1 unsigned char i;
76 1
77 1
78 1 /*------------------------------------------------
79 1 Setup the serial port for 1200 baud at 16MHz.
80 1 ------------------------------------------------*/
81 1 SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
82 1 TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
83 1 TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
84 1 TR1 = 1; /* TR1: timer 1 run */
85 1 TI = 1; /* TI: set TI to send first char of UART */
86 1
87 1 Init_ADC();
88 1
89 1 while(1)
90 1 {
91 2 for( i = 0; i <8; i++ )
92 2 {
93 3 printf("Channel %u = %4u\n", (unsigned)i,Read_ADC( i ));
94 3 }
95 2 }
96 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 108 ----
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 + -