📄 cd_ad.lst
字号:
C51 COMPILER V7.07 CD_AD 03/06/2009 19:29:32 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE CD_AD
OBJECT MODULE PLACED IN cd_ad.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE cd_ad.c ROM(COMPACT) OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include "reg922.h"
2 #include "stdio.h"
3 #include "stdlib.h"
4 #include "cd_ad.h"
5 #include "stdarg.h"
6
7 //cclk=osc/2 = 7.3728M/2 = 3.6864 M; PCLK = CCLK/2 = 1.8432M
8 #define STAND_RC_OSC 1843200UL
9 #define RC_OSC 1866800UL
10
11 void init_para()
12 {
13 1 count = 0 ;
14 1 Frequence = 0 ;
15 1 }
16
17 //初始化系统时钟,内部RC振荡器
18 void init_clock()
19 {
20 1 DIVM=1; //cclk=osc/2 = 7.3728M/2 = 3.6864 M; PCLK = CCLK/2 = 1.8432M ;
21 1 TRIM |= 0x40 ;
22 1 }
23
24 void init_io()
25 {
26 1 PT0AD=0x3E; //P0.1--P0.5 数字输入禁能
27 1 P0= 0xFF;
28 1
29 1 P0M1= 0x3e; //P0.0,P0.6,P0.7 准双向 00110110
30 1 P0M2= 0x00;
31 1
32 1 P1M1=0; //P1准双向
33 1 P1M2=0;
34 1
35 1 P3M1=0; //P3准双向
36 1 P3M2=0;
37 1
38 1 P1M1 |= 0x0c; //SCL SDA开漏
39 1 P1M2 |= 0x0c;
40 1 }
41
42 void init_uart()
43 {
44 1 // AUXR1 |= 0x40; //enable reset on break detect
45 1 SCON = 0x50; //select the BRG as UART baud rate source
46 1 SSTAT = 0x00;
47 1 BRGR0 = 0x70; //9600 BAUD at (7.3728)/2 MHZ
48 1 BRGR1 = 0x01;
49 1 // BRGR0 = 0xf0; //4800 BAUD at (7.3728)/2 MHZ
50 1 // BRGR1 = 0x02;
51 1 BRGCON = 0x03; //enable BRG
52 1 TI=1;
53 1 }
54
55 void int_i2c(void)
C51 COMPILER V7.07 CD_AD 03/06/2009 19:29:32 PAGE 2
56 {
57 1 I2ADR=0xae; //从 ADR 装入
58 1 I2CON=0X44; //EN I2C WAIT 从ADD
59 1 EI2C=1; //EN I2C INTERRUPT
60 1 }
61
62 void init_ext1()
63 {
64 1 IT1 = 1 ; //设置外部中断为边沿触发
65 1 EX1 = 1 ; //外部中断1使能
66 1 }
67
68 //用做系统定时,25ms中断一次 25ms/(1/PCLK) = 36864 16位模式
69 void init_time0()
70 {
71 1 unsigned int value ;
72 1 value = RC_OSC/40;
73 1 value = 65535 - value ;
74 1
75 1 sys_th0 = value/256;
76 1 sys_tl0 = value%256;
77 1 TH0 = sys_th0;
78 1 TL0 = sys_tl0;
79 1 // TH0=0x6F; //定时器初值 65535 - 36864 = 28671 = 0x6FFF
80 1 // TL0=0xFF;
81 1 TMOD &= 0xF0; //T0 16位定时器
82 1 TMOD |= 0x01 ;
83 1 ET0 = 1 ; //使能T0中断
84 1 }
85
86 void init_time1()
87 {
88 1 TH1 = 0 ;
89 1 TL1 = 0 ;
90 1 TMOD &= 0x0F;
91 1 TMOD |= 0x50 ;
92 1 ET1 = 1 ;
93 1 }
94
95 void i2c_interrupt() interrupt 6
96 {
97 1 SI = 0 ;
98 1 }
99
100 //计数器
101 void time1_interrupt(void) interrupt 3
102 {
103 1 // count ++ ;
104 1 TF1 = 0 ;
105 1 }
106
107 //25ms 定时
108 void time0_intrrupt(void) interrupt 1
109 {
110 1 TR0 = 0 ; //关定时器
111 1 test_pin = ~test_pin ;
112 1 systimer ++ ;
113 1 if(systimer>=40) //1s
114 1 {
115 2 TR1 = 0 ;//停止记数
116 2 count=TH1<<8;
117 2 count += TL1 ;
C51 COMPILER V7.07 CD_AD 03/06/2009 19:29:32 PAGE 3
118 2 Frequence = count ;
119 2 TH1 = 0 ;
120 2 TL1 = 0 ;
121 2 count = 0 ; //清零计数
122 2 systimer = 0 ;
123 2 TR1 = 1 ; //重新计数
124 2 }
125 1 TH0=0x49;//sys_th0; //定时器初值 65535 - 36864 = 28671 = 0x6FFF
126 1 TL0=0xE1;//sys_tl0;
127 1
128 1 TF0 = 0 ;
129 1 TR0 = 1 ; //重新定时20ms
130 1 }
131
132 void ext1_interrupt(void) interrupt 2
133 {
134 1 IE1 = 0 ;
135 1 }
136
137 float measure()
138 {
139 1 int freq ;
140 1 float RH;
141 1 freq = Frequence ;
142 1 if(freq >=7351 )
143 1 {
144 2 RH = 0.0 ;
145 2 }
146 1 else if(freq >= 7224)
147 1 {
148 2 RH = 10*(freq-7224)/(7351.0-7224.0);
149 2 }
150 1 else if(freq >= 7100)
151 1 {
152 2 RH = 10*(freq-7100)/(7224.0-7100.0)+10;
153 2 }
154 1 else if(freq >= 6976)
155 1 {
156 2 RH = 10*(freq-6976)/(7100.0-6976.0)+20;
157 2 }
158 1 else if(freq >= 6853)
159 1 {
160 2 RH = 10*(freq-6853)/(6976.0-6853.0)+30;
161 2 }
162 1 else if(freq >= 6728)
163 1 {
164 2 RH = 10*(freq-6728)/(6853.0-6728.0)+40;
165 2 }
166 1 else if(freq >= 6600)
167 1 {
168 2 RH = 10*(freq-6600)/(6728.0-6600.0)+50;
169 2 }
170 1 else if(freq >= 6468)
171 1 {
172 2 RH = 10*(freq-6468)/(6600.0-6468.0)+60;
173 2 }
174 1 else if(freq >= 6330)
175 1 {
176 2 RH = 10*(freq-6330)/(6468.0-6330.0)+70;
177 2 }
178 1 else if(freq >= 6186)
179 1 {
C51 COMPILER V7.07 CD_AD 03/06/2009 19:29:32 PAGE 4
180 2 RH = 10*(freq-6186)/(6330.0-6186.0)+80;
181 2 }
182 1 else if(freq >= 6033)
183 1 {
184 2 RH = 10*(freq-6033)/(6186.0-6033.0)+90;
185 2 }
186 1 else
187 1 {
188 2 RH = 100.0 ;
189 2 }
190 1 return RH;
191 1 }
192
193 void Uart_Printchar(char c)
194 {
195 1 unsigned int idata j;
196 1 while(!TI);
197 1 TI=0;
198 1 SBUF=c;
199 1 for(j=0;j<100;j++) ;
200 1 }
201
202 void Uart_SendString(char *s)
203 {
204 1 while(*s)
205 1 {
206 2 Uart_Printchar(*s++);
207 2 }
208 1 }
209
210 void Uart_Printf( char *fmt,... )
211 {
212 1 va_list ap;
213 1 char string[20];
214 1
215 1 va_start(ap,fmt);
216 1 vsprintf(string,fmt,ap);
217 1 Uart_SendString(string);
218 1 va_end(ap);
219 1 }
220
221 void main()
222 {
223 1 int i;
224 1
225 1 init_para();
226 1 init_clock();
227 1 init_io();
228 1 int_i2c();
229 1 init_uart();
230 1 // init_ext1();
231 1 init_time0();
232 1 init_time1();
233 1
234 1 EA=1; //中断开
235 1 TR0 = 1 ; //开始记时
236 1 TR1 = 1 ; //开始计数
237 1
238 1 Uart_Printf("System initialization!\r\n");
239 1 while(1)
240 1 {
241 2 // P0 &= 0x7F;
C51 COMPILER V7.07 CD_AD 03/06/2009 19:29:32 PAGE 5
242 2 for(i=0;i<9000;i++) ;
243 2 // P0 |= 0x80;
244 2 RH = measure();
245 2 Uart_Printf("F = %d\r\n" , Frequence);
246 2 Uart_Printf("RH = %.1f\r\n" , RH);
247 2 }
248 1
249 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 937 ----
CONSTANT SIZE = 46 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 16 46
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 + -