📄 f34x_usb_main.lst
字号:
C51 COMPILER V8.02 F34X_USB_MAIN 04/28/2008 13:24:09 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE F34X_USB_MAIN
OBJECT MODULE PLACED IN F34x_USB_Main.OBJ
COMPILER INVOKED BY: D:\Program Files\keil 3\C51\BIN\C51.EXE F34x_USB_Main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // F34x_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: 34X000019
20 // Target: C8051F34x
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: F34x_USB_Interrupt
25 //
26 //
27 // Release 1.0
28 // -Initial Revision (GP)
29 // -22 NOV 2005
30 // -Ported from 'F320_USB_Bulk
31 //
32
33 //-----------------------------------------------------------------------------
34 // Includes
35 //-----------------------------------------------------------------------------
36
37 #include <c8051f340.h>
38 #include "F34x_USB_Register.h"
39 #include "F34x_USB_Main.h"
40 #include "F34x_USB_Descriptor.h"
41
42 //-----------------------------------------------------------------------------
43 // 16-bit SFR Definitions for 'F32x
44 //-----------------------------------------------------------------------------
45
46 sfr16 TMR2RL = 0xca; // Timer2 reload value
47 sfr16 TMR2 = 0xcc; // Timer2 counter
48
49 //-----------------------------------------------------------------------------
50 // Globals
51 //-----------------------------------------------------------------------------
52
53 sbit Led1 = P2^4; // LED='1' means ON
54 sbit Led2 = P2^6;
55
C51 COMPILER V8.02 F34X_USB_MAIN 04/28/2008 13:24:09 PAGE 2
56 #define Sw1 0x01 // These are the port2 bits for Sw1
57 #define Sw2 0x02 // and Sw2 on the development board
58 BYTE Switch1State = 0; // Indicate status of switch
59 BYTE Switch2State = 0; // starting at 0 == off
60
61 BYTE Toggle1 = 0; // Variable to make sure each button
62 BYTE Toggle2 = 0; // press and release toggles switch
63
64 BYTE Potentiometer = 0x00; // Last read potentiometer value
65 BYTE Temperature = 0x00; // Last read temperature sensor value
66
67 idata BYTE Out_Packet[64]; // Last packet received from host
68 idata BYTE In_Packet[64]; // Next packet to sent to host
69
70 code const BYTE TEMP_ADD = 112; // This constant is added to Temperature
71
72
73 //-----------------------------------------------------------------------------
74 // Main Routine
75 //-----------------------------------------------------------------------------
76 void main(void)
77 {
78 1 PCA0MD &= ~0x40; // Disable Watchdog timer
79 1
80 1 OSCILLATOR_Init(); // Initialize oscillator
81 1 PORT_Init(); // Initialize crossbar and GPIO
82 1 USB0_Init(); // Initialize USB0
83 1 Timer2_Init(); // Initialize Timer2
84 1 ADC0_Init(); // Initialize ADC0
85 1
86 1 while (1)
87 1 {
88 2 // It is possible that the contents of the following packets can change
89 2 // while being updated. This doesn't cause a problem in the sample
90 2 // application because the bytes are all independent. If data is NOT
91 2 // independent, packet update routines should be moved to an interrupt
92 2 // service routine, or interrupts should be disabled during data updates.
93 2 // Led1=1;
94 2 // if (Out_Packet[0] == 1) Led1 = 1; // Update status of LED #1
95 2 // else Led1 = 0;
96 2 // if (Out_Packet[1] == 1) Led2 = 1; // Update status of LED #2
97 2 // else Led2 = 0;
98 2 // P1 = (Out_Packet[2] & 0x0F); // Set Port 1 pins
99 2
100 2
101 2 // In_Packet[0] = Switch1State; // Send status of switch 1
102 2 In_Packet[1] = 'D'; // and switch 2 to host
103 2
104 2 In_Packet[4]++;
105 2 if(In_Packet[4]>99)
106 2 {
107 3 In_Packet[4]=0;
108 3 In_Packet[3]++;
109 3 }
110 2 if(In_Packet[3]>99)
111 2 {
112 3 In_Packet[3]=0;
113 3 In_Packet[2]++;
114 3 }
115 2 if(In_Packet[2]>255) In_Packet[2]=0;
116 2
117 2
C51 COMPILER V8.02 F34X_USB_MAIN 04/28/2008 13:24:09 PAGE 3
118 2 // In_Packet[2] = (P0 & 0x0F); // Port 0 [0-3]
119 2 // In_Packet[3] = Potentiometer; // Potentiometer value
120 2 //In_Packet[4] = Temperature; // Temperature sensor value
121 2 }
122 1 }
123
124 //-----------------------------------------------------------------------------
125 // Initialization Subroutines
126 //-----------------------------------------------------------------------------
127
128 //-----------------------------------------------------------------------------
129 // OSCILLATOR_Init
130 //-----------------------------------------------------------------------------
131 //
132 // Return Value : None
133 // Parameters : None
134 //
135 // Initialize the system clock and USB clock
136 //
137 //-----------------------------------------------------------------------------
138 void OSCILLATOR_Init(void)
139 {
140 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
149 1 OSCICN |= 0x03; // Configure internal oscillator for
150 1 // its maximum frequency and enable
151 1 // missing clock detector
152 1
153 1 CLKMUL = 0x00; // Select internal oscillator as
154 1 // input to clock multiplier
155 1
156 1 CLKMUL |= 0x80; // Enable clock multiplier
157 1 Delay(); // Delay for clock multiplier to begin
158 1 CLKMUL |= 0xC0; // Initialize the clock multiplier
159 1 Delay(); // Delay for clock multiplier to begin
160 1
161 1 while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
162 1 CLKSEL = SYS_INT_OSC; // Select system clock
163 1 CLKSEL |= USB_4X_CLOCK; // Select USB clock
164 1 #endif /* _USB_LOW_SPEED_ */
165 1 }
166
167 //-----------------------------------------------------------------------------
168 // PORT_Init
169 //-----------------------------------------------------------------------------
170 //
171 // Return Value : None
172 // Parameters : None
173 //
174 // This function configures the crossbar and GPIO ports.
175 //
176 // P2.2 digital push-pull LED
177 // P2.3 digital push-pull LED
178 // P2.5 analog Potentiometer
179 //-----------------------------------------------------------------------------
C51 COMPILER V8.02 F34X_USB_MAIN 04/28/2008 13:24:09 PAGE 4
180 void PORT_Init(void)
181 {
182 1 P2MDIN = 0xDF; // P2.5 set as analog input
183 1
184 1 P0MDOUT |= 0x0F; // P0 pins 0-3 set high impedance
185 1 P1MDOUT |= 0x0F; // P1 pins 0-3 set high impedance
186 1 P2MDOUT |= 0xff; // P2 pins 0,1 set high impedance
187 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -