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