📄 82x54ad_test.lst
字号:
C51 COMPILER V7.01 82X54AD_TEST 01/04/2007 02:33:19 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE 82X54AD_TEST
OBJECT MODULE PLACED IN 82x54AD_test.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 82x54AD_test.c BROWSE
stmt level source
1 // Megawin MPC82X54 A/D Converter Demo code
2 // Edited by Peter_Lin Date:12-20-2005
3 #include "reg82xx.h"
4 idata unsigned int pause;
5 sbit DLIT= P2^3;
6 unsigned int get_channel_value(unsigned char);
7 unsigned char key_sel, key_status;
8 void init_ad(void);
9 void erase_IAP(unsigned int);
10 void write_IAP(unsigned int, unsigned char);
11 unsigned char read_IAP(unsigned int);
12 sbit test_T2= P2^6;
13
14 void ADC_int(void) interrupt 5
15 {
16 1
17 1 test_T2 ^=1;
18 1 DLIT=0;
19 1 for(pause=0;pause<0x39; pause++)
20 1 {}
21 1 DLIT=1;
22 1 }
23
24
25 unsigned int get_channel_value(unsigned char channel)
26 {
27 1
28 1 ADCTL = channel ;
29 1 ADCTL &= 0x07 ; // clear ADCI
30 1 ADCTL |= 0x80 ; // enable A/D Converter
31 1 ADCTL |= 0x08 ; // set ADCS to start A/D conversion
32 1 while (1) {
33 2 ACC = ADCTL ;
34 2 if (ACC^4) break ;
35 2 }
36 1 ADCTL &= 0x67; // Stop A/D Converter .and. ADCI
37 1 return( ((unsigned int) ADCV << 2) | (ADCVL & 3) );
38 1 }
39
40
41 void init_ad(void)
42 {
43 1 AUXR |= 0x10; // Enable "ENADCI" bit, Select the ADC function block to generate interrup
-t to the MCU.
44 1 IE |= 0xA0; // Enable "EA" & "ESPI" Bit, Select the A/D function.
45 1 IP |= 0x20; // Enable "PSPI" Bit, Set priority for A/D inturrept higher.
46 1 IPH |= 0x20; // Enable "PSPIH" Bit, Set priority for A/D inturrept higher.
47 1
48 1 }
49
50 void erase_IAP(unsigned int iap_address)
51 {
52 1 IFADRL = iap_address & 0xFF; //get low bytes adress
- ; // MPC89X52 IAP Start address 0x2000 ~0x2BFF
53 1 IFADRH = (iap_address >> 8) & 0x1F; //get high byte address
C51 COMPILER V7.01 82X54AD_TEST 01/04/2007 02:33:19 PAGE 2
54 1 IFMT = 0x03 ; // command page-erase
55 1 ISPCR = 0x84 ; // supposed 6MHz X's oscillator applied
56 1 SCMD = 0x46 ; //Trigger IAP memory
57 1 SCMD = 0xB9 ; //
58 1 }
59
60
61 void write_IAP(unsigned int iap_address, unsigned char value)
62 {
63 1 ; //Byte writing
64 1 IFADRH = (iap_address >> 8) & 0x1F; // get high byte address
65 1 IFADRL = iap_address & 0xFF; // get low bytes adress
66 1 IFD = value ; // Flash data buffer
67 1 IFMT = 0x02 ; // command byte-writing
68 1 ISPCR = 0x84 ; // supposed 6MHz X's oscillator applied
69 1 SCMD = 0x46 ;
70 1 SCMD = 0xB9 ;
71 1 }
72
73
74 unsigned char read_IAP(unsigned int iap_address)
75 {
76 1 ; //Byte writing
77 1 IFADRH = (iap_address >> 8) & 0x1F; // get high byte address
78 1 IFADRL = iap_address & 0xFF; // get low bytes adress
79 1 IFMT = 0x01; // command byte-reading
80 1 ISPCR = 0x84; // supposed 6MHz X's oscillator applied
81 1 SCMD = 0x46;
82 1 SCMD = 0xB9;
83 1 return(IFD); //return Flash data
84 1 }
85
86
87 void main(void)
88 {
89 1 unsigned int ad_result;
90 1 unsigned int iap_addr;
91 1 data unsigned int time; //delay
92 1
93 1 P1M0 = 0x03; //P1 bit 0 set to input only
94 1 P1M1 = 0x00; // P1M0 Bit0 set to "1"/P1M1 bit0 set to "0"
95 1 iap_addr=0x1000;
96 1 init_ad();
97 1 erase_IAP(iap_addr);
98 1 while(1)
99 1 {
100 2 ad_result=get_channel_value((unsigned char) 0x01); //select channel 1
101 2 write_IAP(iap_addr,ad_result & 0x03);
102 2 write_IAP(iap_addr+1,ad_result >> 4 & 0x08);
103 2 ad_result=read_IAP(iap_addr);
104 2 if (ad_result > 200) {
105 3 for(time=0;time<0x1000;time++)
106 3 { }
107 3 test_T2 ^=1; }
108 2
109 2 }
110 1 }
111
112
113
114
115
C51 COMPILER V7.01 82X54AD_TEST 01/04/2007 02:33:19 PAGE 3
116
117
118
119
120
121
122
123
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 291 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 2
IDATA SIZE = 2 ----
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 + -