📄 f32x_usb_main.lst
字号:
186 1 XBR1 = 0x40; // Enable Crossbar
187 1 }
188
189 //-----------------------------------------------------------------------------
190 // Usb0_Init
191 //-----------------------------------------------------------------------------
192 //
193 // Return Value : None
194 // Parameters : None
195 //
196 // - Initialize USB0
197 // - Enable USB0 interrupts
198 // - Enable USB0 transceiver
199 // - Enable USB0 with suspend detection
200 //-----------------------------------------------------------------------------
201 void Usb0_Init(void)
202 {
203 1 BYTE Count;
204 1
205 1 // Set initial values of In_Packet and Out_Packet to zero
206 1 // Initialized here so that WDT doesn't kick in first
207 1 for (Count = 0; Count < 64; Count++)
208 1 {
209 2 Out_Packet[Count] = 0;
210 2 In_Packet[Count] = 0;
211 2 }
212 1
213 1
214 1 POLL_WRITE_BYTE(POWER, 0x08); // Force Asynchronous USB Reset
215 1 POLL_WRITE_BYTE(IN1IE, 0x07); // Enable Endpoint 0-2 in interrupts
216 1 POLL_WRITE_BYTE(OUT1IE, 0x07); // Enable Endpoint 0-2 out interrupts
217 1 POLL_WRITE_BYTE(CMIE, 0x07); // Enable Reset,Resume,Suspend interrupts
218 1 #ifdef _USB_LOW_SPEED_
USB0XCN = 0xC0; // Enable transceiver; select low speed
POLL_WRITE_BYTE(CLKREC, 0xA0); // Enable clock recovery; single-step mode
// disabled; low speed mode enabled
#else
223 1 USB0XCN = 0xE0; // Enable transceiver; select full speed
224 1 POLL_WRITE_BYTE(CLKREC, 0x80); // Enable clock recovery, single-step mode
225 1 // disabled
226 1 #endif // _USB_LOW_SPEED_
227 1
228 1 EIE1 |= 0x02; // Enable USB0 Interrupts
229 1 EA = 1; // Global Interrupt enable
230 1 // Enable USB0 by clearing the USB
231 1 // Inhibit bit
232 1 POLL_WRITE_BYTE(POWER, 0x01); // and enable suspend detection
233 1 }
234
235 //-----------------------------------------------------------------------------
236 // Timer_Init
237 //-----------------------------------------------------------------------------
238 //
239 // Return Value : None
240 // Parameters : None
241 //
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 5
242 // Timer 2 reload, used to check if switch pressed on overflow and
243 // used for ADC continuous conversion
244 //-----------------------------------------------------------------------------
245
246 void Timer_Init(void)
247 {
248 1 TMR2CN = 0x00; // Stop Timer2; Clear TF2;
249 1
250 1 CKCON &= ~0xF0; // Timer2 clocked based on T2XCLK;
251 1 TMR2RL = 0; // Initialize reload value
252 1 TMR2 = 0xffff; // Set to reload immediately
253 1
254 1 ET2 = 1; // Enable Timer2 interrupts
255 1 TR2 = 1; // Start Timer2
256 1 }
257
258 //-----------------------------------------------------------------------------
259 // Adc_Init
260 //-----------------------------------------------------------------------------
261 //
262 // Return Value : None
263 // Parameters : None
264 //
265 // Configures ADC for single ended continuous conversion or Timer2
266 //-----------------------------------------------------------------------------
267
268 void Adc_Init(void)
269 {
270 1 REF0CN = 0x0E; // Enable voltage reference VREF
271 1 AMX0P = 0x1E; // Positive input starts as temp sensor
272 1 AMX0N = 0x1F; // Single ended mode(neginput = gnd)
273 1
274 1 ADC0CF = 0xF8; // SAR Period 0x1F, Right adjusted
275 1
276 1 ADC0CN = 0xC2; // Continuous converion on timer 2
277 1 // overflow; low power tracking mode on
278 1
279 1 EIE1 |= 0x08; // Enable conversion complete interrupt
280 1 }
281
282 //-----------------------------------------------------------------------------
283 // Timer2_ISR
284 //-----------------------------------------------------------------------------
285 //
286 // Called when timer 2 overflows, check to see if switch is pressed,
287 // then watch for release.
288 //
289 //-----------------------------------------------------------------------------
290
291 void Timer2_ISR(void) interrupt 5
292 {
293 1 if (!(P2 & Sw1)) // Check for switch #1 pressed
294 1 {
295 2 if (Toggle1 == 0) // Toggle is used to debounce switch
296 2 { // so that one press and release will
297 3 Switch1State = ~Switch1State; // toggle the state of the switch sent
298 3 Toggle1 = 1; // to the host
299 3 }
300 2 }
301 1 else Toggle1 = 0; // Reset toggle variable
302 1
303 1 if (!(P2 & Sw2)) // Same as above, but Switch2
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 6
304 1 {
305 2 if (Toggle2 == 0)
306 2 {
307 3 Switch2State = ~Switch2State;
308 3 Toggle2 = 1;
309 3 }
310 2 }
311 1 else Toggle2 = 0;
312 1
313 1 TF2H = 0; // Clear Timer2 interrupt flag
314 1 }
315
316 //-----------------------------------------------------------------------------
317 // Adc_ConvComplete_ISR
318 //-----------------------------------------------------------------------------
319 //
320 // Called after a conversion of the ADC has finished
321 // Updates the appropriate variable for potentiometer or temperature sensor
322 // Switches the ADC multiplexor value to switch between the potentiometer
323 // and temp sensor
324 //
325 //-----------------------------------------------------------------------------
326
327 void Adc_ConvComplete_ISR(void) interrupt 10
328 {
329 1 if (AMX0P == 0x1E) // This switches the AMUX between
330 1 { // the temperature sensor and the
331 2 Temperature = ADC0L; // potentiometer pin after conversion
332 2 Temperature += TEMP_ADD; // Add offset to Temperature
333 2 AMX0P = 0x07; // switch to potentiometer
334 2 ADC0CF = 0xFC; // Place ADC0 in left-adjusted mode
335 2 }
336 1 else
337 1 {
338 2 Potentiometer = ADC0H;
339 2 AMX0P = 0x1E; // switch to temperature sensor
340 2 ADC0CF = 0xF8; // place ADC0 in right-adjusted mode
341 2 }
342 1
343 1 AD0INT = 0;
344 1 }
345
346 //-----------------------------------------------------------------------------
347 // Delay
348 //-----------------------------------------------------------------------------
349 //
350 // Used for a small pause, approximately 80 us in Full Speed,
351 // and 1 ms when clock is configured for Low Speed
352 //
353 //-----------------------------------------------------------------------------
354
355 void Delay(void)
356 {
357 1 int x;
358 1 for(x = 0;x < 500;x)
359 1 x++;
360 1 }
361
362 //-----------------------------------------------------------------------------
363 // End Of File
364 //-----------------------------------------------------------------------------
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 7
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 367 ----
CONSTANT SIZE = 1 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 6 ----
IDATA SIZE = 128 ----
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 + -