📄 temp_3.lst
字号:
136 //-----------------------------------------------------------------------------
137 // SYSCLK_Init
138 //-----------------------------------------------------------------------------
139 //
140 // This routine initializes the system clock to use an 22.1184MHz crystal
141 // as its clock source.
142 //
143 void SYSCLK_Init (void)
144 {
145 1 int i; // delay counter
146 1
147 1 OSCXCN = 0x67; // start external oscillator with
148 1 // 22.1184MHz crystal
149 1
150 1 for (i=0; i < 256; i++) ; // XTLVLD blanking interval (>1ms)
151 1
152 1 while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
153 1
154 1 OSCICN = 0x88; // select external oscillator as SYSCLK
155 1 // source and enable missing clock
156 1 // detector
157 1 }
158
159 //-----------------------------------------------------------------------------
160 // PORT_Init
161 //-----------------------------------------------------------------------------
162 //
163 // Configure the Crossbar and GPIO ports
164 //
165 void PORT_Init (void)
166 {
167 1 XBR0 = 0x04; // Enable UART0
168 1 XBR1 = 0x00;
169 1 XBR2 = 0x40; // Enable crossbar and weak pull-ups
170 1 P0MDOUT |= 0x01; // enable TX0 as a push-pull output
171 1 P1MDOUT |= 0x40; // enable P1.6 (LED) as push-pull output
172 1 }
173
174 //-----------------------------------------------------------------------------
175 // UART0_Init
176 //-----------------------------------------------------------------------------
177 //
178 // Configure the UART0 using Timer1, for <baudrate> and 8-N-1.
179 //
C51 COMPILER V7.00 TEMP_3 12/23/2003 14:31:55 PAGE 4
180 void UART0_Init (void)
181 {
182 1 SCON0 = 0x50; // SCON0: mode 1, 8-bit UART, enable RX
183 1 TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload
184 1 TH1 = -(SYSCLK/BAUDRATE/16); // set Timer1 reload value for baudrate
185 1 TR1 = 1; // start Timer1
186 1 CKCON |= 0x10; // Timer1 uses SYSCLK as time base
187 1 PCON |= 0x80; // SMOD00 = 1
188 1 TI0 = 1; // Indicate TX0 ready
189 1 }
190
191 //-----------------------------------------------------------------------------
192 // ADC0_Init
193 //-----------------------------------------------------------------------------
194 //
195 // Configure ADC0 to use Timer3 overflows as conversion source, to
196 // generate an interrupt on conversion complete, and to use left-justified
197 // output mode. Enables ADC end of conversion interrupt. Leaves ADC disabled.
198 //
199 void ADC0_Init (void)
200 {
201 1 ADC0CN = 0x05; // ADC0 disabled; normal tracking
202 1 // mode; ADC0 conversions are initiated
203 1 // on overflow of Timer3; ADC0 data is
204 1 // left-justified
205 1 REF0CN = 0x07; // enable temp sensor, on-chip VREF,
206 1 // and VREF output buffer
207 1 AMX0SL = 0x0f; // Select TEMP sens as ADC mux output
208 1 ADC0CF = (SYSCLK/2500000) << 3; // ADC conversion clock = 2.5MHz
209 1 ADC0CF |= 0x01; // PGA gain = 2
210 1
211 1 EIE2 |= 0x02; // enable ADC interrupts
212 1 }
213
214 //-----------------------------------------------------------------------------
215 // Timer3_Init
216 //-----------------------------------------------------------------------------
217 //
218 // Configure Timer3 to auto-reload at interval specified by <counts> (no
219 // interrupt generated) using SYSCLK as its time base.
220 //
221 void Timer3_Init (int counts)
222 {
223 1 TMR3CN = 0x02; // Stop Timer3; Clear TF3;
224 1 // use SYSCLK as timebase
225 1 TMR3RL = -counts; // Init reload values
226 1 TMR3 = 0xffff; // set to reload immediately
227 1 EIE2 &= ~0x01; // disable Timer3 interrupts
228 1 TMR3CN |= 0x04; // start Timer3
229 1 }
230
231 //-----------------------------------------------------------------------------
232 // Interrupt Service Routines
233 //-----------------------------------------------------------------------------
234
235 //-----------------------------------------------------------------------------
236 // ADC0_ISR
237 //-----------------------------------------------------------------------------
238 //
239 // ADC0 end-of-conversion ISR
240 // Here we take the ADC0 sample, add it to a running total <accumulator>, and
241 // decrement our local decimation counter <int_dec>. When <int_dec> reaches
C51 COMPILER V7.00 TEMP_3 12/23/2003 14:31:55 PAGE 5
242 // zero, we post the decimated result in the global variable <result>.
243 //
244 void ADC0_ISR (void) interrupt 15
245 {
246 1 static unsigned int_dec=INT_DEC; // integrate/decimate counter
247 1 // we post a new result when
248 1 // int_dec = 0
249 1 static long accumulator=0L; // here's where we integrate the
250 1 // ADC samples
251 1
252 1 AD0INT = 0; // clear ADC conversion complete
253 1 // indicator
254 1
255 1 accumulator += ADC0; // read ADC value and add to running
256 1 // total
257 1 int_dec--; // update decimation counter
258 1
259 1 if (int_dec == 0) { // if zero, then post result
260 2 int_dec = INT_DEC; // reset counter
261 2 result = accumulator >> 8;
262 2 accumulator = 0L; // reset accumulator
263 2 }
264 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 384 ----
CONSTANT SIZE = 27 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 10 8
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 + -