📄 f32x_usb_main.lst
字号:
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE F32X_USB_MAIN
OBJECT MODULE PLACED IN F32x_USB_Main.OBJ
COMPILER INVOKED BY: D:\keil\C51\BIN\c51.exe F32x_USB_Main.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F32x_USB_Main.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2005 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This application note covers the implementation of a simple USB application
10 // using the interrupt transfer type. This includes support for device
11 // enumeration, control and interrupt transactions, and definitions of
12 // descriptor data. The purpose of this software is to give a simple working
13 // example of an interrupt transfer application; it does not include
14 // support for multiple configurations or other transfer types.
15 //
16 // How To Test: See Readme.txt
17 //
18 //
19 // FID: 32X000024
20 // Target: C8051F32x
21 // Tool chain: Keil C51 7.50 / Keil EVAL C51
22 // Silicon Laboratories IDE version 2.6
23 // Command Line: See Readme.txt
24 // Project Name: F32x_USB_Interrupt
25 //
26 //
27 // Release 1.3
28 // -All changes by GP
29 // -22 NOV 2005
30 // -Changed revision number to match project revision
31 // No content changes to this file
32 // -Modified file to fit new formatting guidelines
33 // -Changed file name from USB_MAIN.c
34
35 // Release 1.1
36 // -All changes by DM
37 // -22 NOV 2002
38 // -Added support for switches and sample USB interrupt application.
39 //
40 // Release 1.0
41 // -Initial Revision (JS)
42 // -22 FEB 2002
43 //
44
45 //-----------------------------------------------------------------------------
46 // Includes
47 //-----------------------------------------------------------------------------
48
49 #include <c8051f320.h>
50 #include "F32x_USB_Register.h"
51 #include "F32x_USB_Main.h"
52 #include "F32x_USB_Descriptor.h"
53
54 //-----------------------------------------------------------------------------
55 // 16-bit SFR Definitions for 'F32x
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 2
56 //-----------------------------------------------------------------------------
57
58 sfr16 TMR2RL = 0xca; // Timer2 reload value
59 sfr16 TMR2 = 0xcc; // Timer2 counter
60
61 //-----------------------------------------------------------------------------
62 // Globals
63 //-----------------------------------------------------------------------------
64
65 sbit Led1 = P2^5; // LED='1' means ON
66 sbit Led2 = P2^6;
67
68 #define Sw1 0x01 // These are the port2 bits for Sw1
69 #define Sw2 0x02 // and Sw2 on the development board
70
71 BYTE Switch1State = 0; // Indicate status of switch
72 BYTE Switch2State = 0; // starting at 0 == off
73
74 BYTE Toggle1 = 0; // Variable to make sure each button
75 BYTE Toggle2 = 0; // press and release toggles switch
76
77 BYTE Potentiometer = 0x00; // Last read potentiometer value
78 BYTE Temperature = 0x00; // Last read temperature sensor value
79
80 idata BYTE Out_Packet[64]; // Last packet received from host
81 idata BYTE In_Packet[64]; // Next packet to sent to host
82
83 code const BYTE TEMP_ADD = 112; // This constant is added to Temperature
84
85
86 //-----------------------------------------------------------------------------
87 // Main Routine
88 //-----------------------------------------------------------------------------
89 void main(void)
90 {
91 1 PCA0MD &= ~0x40; // Disable Watchdog timer
92 1
93 1 Sysclk_Init(); // Initialize oscillator
94 1 Port_Init(); // Initialize crossbar and GPIO
95 1 Usb0_Init(); // Initialize USB0
96 1 Timer_Init(); // Initialize timer2
97 1 Adc_Init(); // Initialize ADC
98 1
99 1 while (1)
100 1 {
101 2 // It is possible that the contents of the following packets can change
102 2 // while being updated. This doesn't cause a problem in the sample
103 2 // application because the bytes are all independent. If data is NOT
104 2 // independent, packet update routines should be moved to an interrupt
105 2 // service routine, or interrupts should be disabled during data updates.
106 2
107 2 if (Out_Packet[0] == 1) Led1 = 1; // Update status of LED #1
108 2 else Led1 = 0;
109 2 if (Out_Packet[1] == 1) Led2 = 1; // Update status of LED #2
110 2 else Led2 = 0;
111 2 P1 = (Out_Packet[2] & 0x0F); // Set Port 1 pins
112 2
113 2
114 2 In_Packet[0] = Switch1State; // Send status of switch 1
115 2 In_Packet[1] = Switch2State; // and switch 2 to host
116 2 In_Packet[2] = (P0 & 0x0F); // Port 0 [0-3]
117 2 In_Packet[3] = Potentiometer; // Potentiometer value
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 3
118 2 In_Packet[4] = Temperature; // Temperature sensor value
119 2 }
120 1 }
121
122 //-----------------------------------------------------------------------------
123 // Initialization Subroutines
124 //-----------------------------------------------------------------------------
125
126 //-----------------------------------------------------------------------------
127 // Sysclk_Init
128 //-----------------------------------------------------------------------------
129 //
130 // Return Value : None
131 // Parameters : None
132 //
133 // Initialize the system clock and USB clock
134 //
135 //-----------------------------------------------------------------------------
136 void Sysclk_Init(void)
137 {
138 1 #ifdef _USB_LOW_SPEED_
OSCICN |= 0x03; // Configure internal oscillator for
// its maximum frequency and enable
// missing clock detector
CLKSEL = SYS_INT_OSC; // Select System clock
CLKSEL |= USB_INT_OSC_DIV_2; // Select USB clock
#else
147 1 OSCICN |= 0x03; // Configure internal oscillator for
148 1 // its maximum frequency and enable
149 1 // missing clock detector
150 1
151 1 CLKMUL = 0x00; // Select internal oscillator as
152 1 // input to clock multiplier
153 1
154 1 CLKMUL |= 0x80; // Enable clock multiplier
155 1 Delay(); // Delay for clock multiplier to begin
156 1 CLKMUL |= 0xC0; // Initialize the clock multiplier
157 1 Delay(); // Delay for clock multiplier to begin
158 1
159 1 while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
160 1 CLKSEL = SYS_INT_OSC; // Select system clock
161 1 CLKSEL |= USB_4X_CLOCK; // Select USB clock
162 1 #endif /* _USB_LOW_SPEED_ */
163 1 }
164
165 //-----------------------------------------------------------------------------
166 // PORT_Init
167 //-----------------------------------------------------------------------------
168 //
169 // Return Value : None
170 // Parameters : None
171 //
172 // This function configures the crossbar and GPIO ports.
173 //
174 // P1.7 analog Potentiometer
175 // P2.2 digital push-pull LED
176 // P2.3 digital push-pull LED
177 //-----------------------------------------------------------------------------
178 void Port_Init(void)
179 {
C51 COMPILER V7.50 F32X_USB_MAIN 08/23/2006 15:13:08 PAGE 4
180 1 P1MDIN = 0x7F; // Port 1 pin 7 set as analog input
181 1 P0MDOUT |= 0x0F; // Port 0 pins 0-3 set push-pull
182 1 P1MDOUT |= 0x0F; // Port 1 pins 0-3 set push-pull
183 1 P2MDOUT |= 0x60; // P2.2 and P2.3 set to push-pull
184 1 P1SKIP = 0x80; // Port 1 pin 7 skipped by crossbar
185 1 XBR0 = 0x00;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -