📄 usb_main.lst
字号:
143 //-------------------------
144 // Usb0_Init
145 //-------------------------
146 // USB Initialization
147 // - Initialize USB0
148 // - Enable USB0 interrupts
149 // - Enable USB0 transceiver
150 // - Enable USB0 with suspend detection
151 //
152 void Usb0_Init(void)
153 {
154 1 POLL_WRITE_BYTE(POWER, 0x08); // Force Asynchronous USB Reset
155 1 POLL_WRITE_BYTE(IN1IE, 0x07); // Enable Endpoint 0-2 in interrupts
156 1 POLL_WRITE_BYTE(OUT1IE, 0x07); // Enable Endpoint 0-2 out interrupts
157 1 POLL_WRITE_BYTE(CMIE, 0x07); // Enable Reset, Resume, and Suspend interrupts
158 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
163 1 USB0XCN = 0xE0; // Enable transceiver; select full speed
164 1 POLL_WRITE_BYTE(CLKREC, 0x80); // Enable clock recovery, single-step mode
165 1 // disabled
166 1 #endif /* _USB_LOW_SPEED_ */
167 1
168 1 EIE1 |= 0x02; // Enable USB0 Interrupts
169 1 EA = 1; // Global Interrupt enable
170 1 // Enable USB0 by clearing the USB Inhibit bit
171 1 POLL_WRITE_BYTE(POWER, 0x01); // and enable suspend detection
172 1 }
173
174 //-------------------------
175 // Timer_Init
176 //-------------------------
177 // Timer initialization
178 // - 1 mhz timer 2 reload, used to check if switch pressed on overflow and
179 // used for ADC continuous conversion
C51 COMPILER V6.12 USB_MAIN 06/09/2004 15:44:26 PAGE 4
180 //
181 void Timer_Init(void)
182 {
183 1 TMR2CN = 0x00; // Stop Timer2; Clear TF2;
184 1
185 1 CKCON &= ~0xF0; // Timer2 clocked based on T2XCLK;
186 1 TMR2RL = -(SYSCLK / 12); // Initialize reload value
187 1 TMR2 = 0xffff; // Set to reload immediately
188 1
189 1 ET2 = 1; // Enable Timer2 interrupts
190 1 TR2 = 1; // Start Timer2
191 1 }
192
193 //-------------------------
194 // Adc_Init
195 //-------------------------
196 // ADC initialization
197 // - Configures ADC for single ended continuous conversion or Timer2
198 //
199 void Adc_Init(void)
200 {
201 1 REF0CN = 0x0E; // Enable voltage reference VREF
202 1 AMX0P = 0x1E; // Positive input starts as temp sensor
203 1 AMX0N = 0x1F; // Single ended mode(negative input = gnd)
204 1
205 1 ADC0CF = 0xFC; // SAR Period 0x1F, Left adjusted output
206 1
207 1 ADC0CN = 0xC2; // Continuous converion on timer 2 overflow
208 1 // with low power tracking mode on
209 1
210 1 EIE1 |= 0x08; // Enable conversion complete interrupt
211 1 }
212
213 //-------------------------
214 // Timer2_ISR
215 //-------------------------
216 // Called when timer 2 overflows, check to see if switch is pressed,
217 // then watch for release.
218 //
219 void Timer2_ISR(void) interrupt 5
220 {
221 1 if (!(P2 & Sw1)) // Check for switch #1 pressed
222 1 {
223 2 if (Toggle1 == 0) // Toggle is used to debounce switch
224 2 { // so that one press and release will
225 3 Switch1State = ~Switch1State; // toggle the state of the switch sent
226 3 Toggle1 = 1; // to the host
227 3 }
228 2 }
229 1 else Toggle1 = 0; // Reset toggle variable
230 1
231 1 if (!(P2 & Sw2)) // This is the same as above, but for Switch2
232 1 {
233 2 if (Toggle2 == 0)
234 2 {
235 3 Switch2State = ~Switch2State;
236 3 Toggle2 = 1;
237 3 }
238 2 }
239 1 else Toggle2 = 0;
240 1
241 1 TF2H = 0; // Clear Timer2 interrupt flag
C51 COMPILER V6.12 USB_MAIN 06/09/2004 15:44:26 PAGE 5
242 1 }
243
244 //-------------------------
245 // Adc_ConvComplete_ISR
246 //-------------------------
247 // Called after a conversion of the ADC has finished
248 // - Updates the appropriate variable for either potentiometer or temperature sensor
249 // - Switches the Adc multiplexor value to switch between the potentiometer and temp sensor
250 //
251 void Adc_ConvComplete_ISR(void) interrupt 10
252 {
253 1 if (AMX0P == 0x1E) // This switches the AMUX between
254 1 { // the temperature sensor and the
255 2 Temperature = ADC0H; // potentiometer pin after each
256 2 AMX0P = 0x07; // conversion
257 2 }
258 1 else
259 1 {
260 2 Potentiometer = ADC0H;
261 2 AMX0P = 0x1E;
262 2 }
263 1
264 1 AD0INT = 0;
265 1 }
266
267 //-------------------------
268 // Delay
269 //-------------------------
270 // Used for a small pause, approximately 80 us in Full Speed,
271 // and 1 ms when clock is configured for Low Speed
272 //
273 void Delay(void)
274 {
275 1 int x;
276 1 for(x = 0;x < 500;x)
277 1 x++;
278 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 307 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 22 ----
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 + -