📄 f411_vr.lst
字号:
137 // System and peripheral initialization functions
138 void System_Init (void);
139 void VDDMon_Init (void);
140 void Port_Init (void);
141 void ADC0_Init (void);
142 void DAC0_Init (void);
143 void PCA_Init (void);
144 void SPI0_Init (void);
145 void RTC_Init (void);
146 void Timer0_Init (int period);
147 void Timer1_Init (int period);
148 void Timer2_Init (int period);
149 void Timer3_Init (int period);
150 void Recording_Search (void);
151
152 // Interrupt service routines
153 void Timer0_ISR (void); // LED updates
154 void Timer1_ISR (void); // Switch polling
155 void ADC0_ISR (void); // Recording
156 void Timer3_ISR (void); // Playback
157
158 //-----------------------------------------------------------------------------
159 // MAIN Routine
160 //-----------------------------------------------------------------------------
161 void main (void)
162 {
163 1 unsigned char i;
164 1
165 1 // Watchdog timer disabled in VR_STARTUP.A51
166 1
167 1 System_Init (); // Initialize system clock
168 1 Port_Init (); // Initialize crossbar and GPIO
169 1 ADC0_Init (); // Initialize ADC0 (microphone)
170 1 DAC0_Init (); // Initialize DAC0 (speaker)
171 1 PCA_Init (); // Initialize the PCA for 8-bit PWM
172 1 // in modules 0, 1, and 2
173 1 SPI0_Init(); // Initialize the interface to the flash
174 1
175 1 RTC_Init (); // Stop the RTC from causing a wake-up
176 1 // from suspend
177 1
178 1 Timer0_Init (LED_PWM); // Initialize timer 0 to provide a
179 1 // 76 Hz interrupt rate for the LEDs
C51 COMPILER V7.06 F411_VR 02/18/2009 16:30:48 PAGE 4
180 1
181 1 Timer1_Init (POLLING); // Initialize timer 1 to provide a
182 1 // 64 Hz interrupt rate for the switches
183 1
184 1 Timer2_Init (SAMP_FREQ); // Initialize the timer to provide an
185 1 // 8KHz interrupt rate for sampling
186 1
187 1 Timer3_Init (SAMP_FREQ); // Initialize the timer to provide an
188 1 // 8KHz interrupt rate for sampling
189 1
190 1 EA = 1; // enable global interrupts
191 1
192 1 SSTFlash_Init (); // disable the write protection in the
193 1 // external SST flash memory
194 1 Recording_Search (); // search for a recording already
195 1 // present in memory
196 1
197 1 TR1 = 1; // start polling the switches
198 1
199 1 // loop forever
200 1 while (1)
201 1 {
202 2 if (ENTER_SUSPEND == 1) // check if no interaction has occurred
203 2 { // for some time
204 3 // disable everything to save the most power and set everything to a
205 3 // dormant state
206 3 ENTER_SUSPEND = 0;
207 3
208 3 TR1 = 0; // stop polling the switches
209 3
210 3 EA = 0; // disable all interrupts
211 3
212 3 XBR1 = 0x40; // disable the PCA
213 3 XBR0 = 0x00; // disable the SPI
214 3
215 3 SCK = 0; // drive the SPI pins low so the
216 3 MISO = 0; // external Flash won't attempt to draw
217 3 MOSI = 0; // current while unpowered
218 3
219 3 IDA0CN &= ~0x80; // disable DAC0
220 3 REF0CN &= ~0x01; // disable VREF
221 3
222 3 LED0 = 1; // turn the LEDs off
223 3 LED1 = 1;
224 3
225 3 TRANS = 1; // turn off the external circuitry
226 3
227 3 RSTSRC = 0x00; // disable missing clock detector
228 3 VDM0CN &= ~0x80; // disable the VDD Monitor
229 3
230 3 OSCICN |= 0x20; // enter suspend mode and wait
231 3 // until a port match event occurs
232 3
233 3 // re-enable and reinitialize the system
234 3 VDDMon_Init ();
235 3
236 3 TRANS = 0; // turn on the external circuitry
237 3
238 3 REF0CN |= 0x01; // re-enable VREF
239 3 IDA0CN |= 0x80; // re-enable DAC0
240 3
241 3 XBR0 = 0x02; // re-enable SPI
C51 COMPILER V7.06 F411_VR 02/18/2009 16:30:48 PAGE 5
242 3 XBR1 = 0x42; // re-enable PCA0_0 and PCA0_1
243 3
244 3 // wait 10us until the Flash is ready to receive writes and reads
245 3 for (i = 0; i < 64; i++);
246 3
247 3 SSTFlash_Init (); // re-initialize the SST flash
248 3
249 3 EA = 1; // enable global interrupts
250 3
251 3 // wait until the button that woke the system is released
252 3 while ((REC_PLAY == 0) || (ERASE == 0));
253 3
254 3 TR1 = 1; // begin polling the buttons again
255 3 }
256 2 }
257 1 }
258
259 /////////////////////////// INITIALIZATION ROUTINES ///////////////////////////
260
261 //-----------------------------------------------------------------------------
262 // System_Init
263 //-----------------------------------------------------------------------------
264 //
265 // Return Value : None
266 // Parameters : None
267 //
268 // This routine initializes the system clock to use the internal 24.5MHz / 4
269 // oscillator as its clock source and enables the missing clock detector reset.
270 // Additionally, this routine sets up VREF, the internal regulator, and the
271 // VDD monitor.
272 //
273 void System_Init (void)
274 {
275 1 OSCICN = 0x85; // configure internal oscillator打开内部24.5M振荡器并实行4分频
276 1 RSTSRC = 0x04; // enable missing clock detector.如果丢掉时钟将引起复位
277 1
278 1 REF0CN = 0x01; // set up and enable VREF pin 输出参考电压参考电压为1.5V
279 1
280 1 REG0CN = 0x10; // set up and enable 2.5V VDD from the 开启内部VDD电压产生电路并设
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -