📄 ad1.lst
字号:
C51 COMPILER V7.50 AD1 08/18/2006 11:05:49 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE AD1
OBJECT MODULE PLACED IN AD1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE AD1.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------------------
2 AD_Interrupt.C: MSC 1210 A/D Conversion for 1 input signals (-2.5V ... +2.5V)
3 Inputs pairs AIN0-AIN1 read in an interrupt service routine
4 Copyright 2003 Keil Software, Inc.
5 ------------------------------------------------------------------------------*/
6
7 #include <REG1210.H>
8 #include <stdio.h>
9 #include "ISD51.H"
10
11 #ifndef XTAL // if no XTAL defined use:
12 #define XTAL 11059200 // XTAL frequency 11.0592 MHz
13 #endif
14
15
16
17 sbit RedLed = P2^4;
18 sbit YellowLed = P2^5;
19
20
21
22 // defines for UART BAUDRATE
23 #define BAUDRATE 9600 // 9600bps communication baudrate
24 #define T2RELOAD (65536-(XTAL/32/BAUDRATE))
25
26 // defines for A/D Converter setup
27 #define A_CLK (((XTAL+500000)/1000000)-1) // about 1MHz Analog Clock
28 #define ANA_CLK (XTAL/(A_CLK+1)) // precise Analog Clock
29 #define DECIMATION (ANA_CLK/64/10) // 10 Hz Decimation
30 #define CONV_FREQ (ANA_CLK/64/DECIMATION) // Conversion Frequency
31
32 // defines for conversion to Volts
33 #define VBIT (2.5 / 0x800000) // 0x800000 represents 2.5 Volts
34
35 // Helper structure to read in ADC values
36 static union {
37 unsigned char c[4]; // bytes
38 signed int i[2]; // signed words
39 signed long l; // signed long
40 } res;
41
42
43 /*static bit Second_Interrupt;
44
45 static void AUXinterrupts (void) interrupt 6 {
46 unsigned char x;
47
48 switch (PAI) {
49 case 6: // A/D interrupt
50 res.c[3] = ADRESL;
51 res.c[2] = ADRESM;
52 res.i[0] = (char) ADRESH; // make sign extension
53 break;
54
55 case 8: // Second Interrupt
C51 COMPILER V7.50 AD1 08/18/2006 11:05:49 PAGE 2
56 x = SECINT; // Dummy Read to Clear SEC Interrupt
57 Second_Interrupt = 1;
58 break;
59 }
60 AI = 0; // Clear AI before returning
61 } */
62
63
64
65 void delay(void) {
66 1 long i;
67 1
68 1 i = 0x1000;
69 1 while(i--);
70 1 }
71
72
73
74 void main(void) {
75 1 T2CON = 0x34; // Use Timer 2 as baudrate generator
76 1 RCAP2H = 0xFF;
77 1 RCAP2H = (T2RELOAD >> 8); // baudrate reload factor
78 1 RCAP2L = T2RELOAD;
79 1
80 1 SCON0 = 0x50; // enable serial uart & receiver
81 1 PCON |= 0x80; // double baudrate for UART0
82 1 P3DDRL &= 0xF0; // P3DDRL set port pins of UART0 to input/strong drive output
83 1 P3DDRL |= 0x07; // P3DDRL set port pins of UART0 to input/strong drive output
84 1
85 1
86 1 USEC = ((XTAL+500000)/1000000)-1; // USEC timer factor
87 1 ONEMS = (XTAL/1000)-1; // (MSECH+MSCL) MS Timer counting at 1.0ms
88 1
89 1 HMSEC = 100-1; // Hundred MS Timer to 100.0ms
90 1 SECINT = (10-1) | 0x80; // SECINT= 10 * HMS Timer Rate = 1 sec
91 1 // '0x80' will set the MSB for write immediate
92 1 MSINT = (10-1) | 0x80; // MSINT = 10ms for Tone period time base
93 1 PDCON = 0x1D; // Powerup SysTimer
94 1
95 1 FTCON = 0xA5; // setup flash programming times
96 1
97 1 EICON = 0x40; //DIS enable all auxiliary interrupts
98 1
99 1 EA = 1; //DIS Enable global interrupt flag
100 1
101 1
102 1 ISDwait (); // wait for connection to uVision2 Debugger
103 1
104 1 PDCON = 0x15; // ON -> ADC-Vref, SPI Systimers. OFF -> PWM, Watchdog
105 1 EA = 1; // Enable global interrupt flag
106 1
107 1
108 1
109 1 // Setup ADC
110 1 ADCON0 = 0x30; // Vref On, Vref Hi, Buff off, BOD off, PGA
111 1 ACLK = A_CLK; // set ACLK factor for about 1MHz
112 1
113 1 ADCON2 = DECIMATION & 0xFF; // LSB of decimation
114 1 ADCON3 =(DECIMATION>>8) & 0x07; // MSB of decimation
115 1 ADCON1 = 0x01; // bipolar, auto, self calibration (offset, gain)
116 1
117 1 ADMUX = 0x68; // AINP = AIN0, AINN = AIN1
C51 COMPILER V7.50 AD1 08/18/2006 11:05:49 PAGE 3
118 1 AIE = 0x00; // Enable the A/D Interrupt
119 1 EAI = 0; // Enable Auxiliary interrupts
120 1
121 1 printf("\nInput -2.5V to +2.5V on AIN1-AIN2 channel pair\n\n");
122 1
123 1 while (1) {
124 2 RedLed = !RedLed; // toggle red LED
125 2 delay();
126 2 delay();
127 2 while((AIE&0x20) != 0x20) ;
128 2 res.c[3] = ADRESL;
129 2 res.c[2] = ADRESM;
130 2 res.i[0] = (char) ADRESH; // make sign extension
131 2 YellowLed = !YellowLed;
132 2
133 2 // Repeat Output Forever
134 2 printf ("%+7.5f Volts\r", res.l * VBIT);
135 2 }
136 1
137 1
138 1 /* while (1) {
139 1 RedLed = !RedLed; // toggle red LED
140 1 delay();
141 1 delay();
142 1 delay();
143 1
144 1 YellowLed = !YellowLed;
145 1
146 1 delay();
147 1 delay();
148 1
149 1 // Repeat Output Forever
150 1 while (!Second_Interrupt) { // Wait for Second Interrupt
151 1 #ifndef ISD51
152 1 PCON |= 1; // Put into Idle Mode
153 1 #endif
154 1 }
155 1 Second_Interrupt = 0;
156 1 printf ("%+7.5f Volts\r", res.l * VBIT);
157 1 } */
158 1
159 1 }
160
161
162
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 202 ----
CONSTANT SIZE = 64 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 4 4
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 + -