📄 f326_usb0_mouse.lst
字号:
C51 COMPILER V7.50 F326_USB0_MOUSE 06/25/2007 09:10:03 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE F326_USB0_MOUSE
OBJECT MODULE PLACED IN F326_USB0_Mouse.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F326_USB0_Mouse.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F326_USB0_Touch.c
3 //-----------------------------------------------------------------------------
4 //
5 // Source file for routines that touch data.
6 //
7
8
9 #include "c8051F326.h"
10 #include "F326_USB0_Touch.h"
11 #include "F326_USB0_InterruptServiceRoutine.h"
12 #include "F326_USB0_Register.h"
13
14 //-----------------------------------------------------------------------------
15 // Definitions
16 //-----------------------------------------------------------------------------
17
18 #define SYSCLK 12000000 // SYSCLK frequency in Hz
19
20 // USB clock selections (SFR CLKSEL)
21 #define USB_4X_CLOCK 0x00 // Select 4x clock multiplier, for USB
22 #define USB_INT_OSC_DIV_2 0x10 // Full Speed
23 #define USB_EXT_OSC 0x20
24 #define USB_EXT_OSC_DIV_2 0x30
25 #define USB_EXT_OSC_DIV_3 0x40
26 #define USB_EXT_OSC_DIV_4 0x50
27
28 // System clock selections (SFR CLKSEL)
29 #define SYS_INT_OSC 0x00 // Select to use internal oscillator
30 #define SYS_EXT_OSC 0x01 // Select to use an external oscillator
31 #define SYS_4X_DIV_2 0x02
32
33 //-----------------------------------------------------------------------------
34 // 16-bit SFR Definitions for 'F326
35 //-----------------------------------------------------------------------------
36
37 sfr16 TMR2RL = 0xca; // Timer2 reload value
38 sfr16 TMR2 = 0xcc; // Timer2 counter
39
40
41 //-----------------------------------------------------------------------------
42 // Local Definitions
43 //-----------------------------------------------------------------------------
44
45 #define Sw1 0x01 // These are the port2 bits for Sw1
46 #define Sw2 0x02 // and Sw2 on the development board
47
48 //-----------------------------------------------------------------------------
49 // Global Variable Declarations
50 //-----------------------------------------------------------------------------
51
52
53 // Last packet received from host
54 unsigned char xdata OUT_PACKET[OUT_PACKET_SIZE] = {0,0,0};
55
C51 COMPILER V7.50 F326_USB0_MOUSE 06/25/2007 09:10:03 PAGE 2
56 // Next packet to send to host
57 unsigned char xdata IN_PACKET[IN_PACKET_SIZE] = {0,0,0,0,0};
58 //-----------------------------------------------------------------------------
59 // Local Variable Declarations
60 //-----------------------------------------------------------------------------
61
62 unsigned char SWITCH_1_STATE = 0; // Indicate status of switch
63 unsigned char SWITCH_2_STATE = 0; // starting at 0 == off
64
65 unsigned char TOGGLE1 = 0; // Variable to make sure each button
66 unsigned char TOGGLE2 = 0; // press and release toggles switch
67
68
69 //-----------------------------------------------------------------------------
70 // Local Function Prototypes
71 //-----------------------------------------------------------------------------
72
73 void Sysclk_Init(void);
74 void Port_Init(void);
75 void UART_Init(void);
76 void USB0_Init(void);
77 void Timer_Init(void);
78 void Delay(void);
79
80 //-----------------------------------------------------------------------------
81 // Interrupt Service Routines
82 //-----------------------------------------------------------------------------
83
84 //-----------------------------------------------------------------------------
85 // Timer1_ISR
86 //-----------------------------------------------------------------------------
87 // Called when timer 1 overflows, check to see if switch is pressed,
88 // then watch for release.
89 // This routine sets the Mouse_... variables for the report handler.
90 //
91 //-----------------------------------------------------------------------------
92 void Timer1_ISR(void) interrupt 3
93 {
94 1
95 1 }
96
97
98 //-----------------------------------------------------------------------------
99 // Initialization Routines
100 //-----------------------------------------------------------------------------
101
102 //-----------------------------------------------------------------------------
103 // USB0_Init
104 //-----------------------------------------------------------------------------
105 //
106 // Return Value - None
107 // Parameters - None
108 //
109 // - Initialize USB0
110 // - Enable USB0 interrupts
111 // - Enable USB0 transceiver
112 // - Enable USB0 with suspend detection
113 //
114 // ----------------------------------------------------------------------------
115 void USB0_Init(void)
116 {
117 1
C51 COMPILER V7.50 F326_USB0_MOUSE 06/25/2007 09:10:03 PAGE 3
118 1 POLL_WRITE_BYTE(POWER, 0x08); // Force Asynchronous USB Reset
119 1 POLL_WRITE_BYTE(IN1IE, 0x03); // Enable Endpoint 0-1 in interrupts
120 1 POLL_WRITE_BYTE(OUT1IE, 0x02); // Enable Endpoint 0-1 out interrupts
121 1 POLL_WRITE_BYTE(CMIE, 0x07); // Enable Reset, Resume, and Suspend
122 1 // interrupts
123 1 USB0XCN = 0xE0; // Enable transceiver; select full speed
124 1 POLL_WRITE_BYTE(CLKREC, 0x80); // Enable clock recovery, single-step
125 1 // mode disabled
126 1
127 1 EIE1 |= 0x02; // Enable USB0 Interrupts
128 1 EA = 1; // Global Interrupt enable
129 1 // Enable USB0 by clearing the USB
130 1 POLL_WRITE_BYTE(POWER, 0x01); // Inhibit Bit and enable suspend
131 1 // detection
132 1
133 1 }
134
135 //-----------------------------------------------------------------------------
136 // System_Init(void)
137 //-----------------------------------------------------------------------------
138 //
139 // Return Value - None
140 // Parameters - None
141 //
142 // This top-level initialization routine calls all support routine.
143 //
144 // ----------------------------------------------------------------------------
145 void System_Init(void)
146 {
147 1 Sysclk_Init();
148 1 Port_Init();
149 1 UART_Init();
150 1 Timer_Init();
151 1 }
152
153 //-----------------------------------------------------------------------------
154 // Sysclk_Init
155 //-----------------------------------------------------------------------------
156 //
157 // Return Value - None
158 // Parameters - None
159 //
160 // Initialize system clock to maximum frequency.
161 //
162 // ----------------------------------------------------------------------------
163 void Sysclk_Init(void)
164 {
165 1
166 1 OSCICN |= 0x82;
167 1 CLKMUL = 0x00;
168 1 CLKMUL |= 0x80; // Enable clock multiplier
169 1
170 1 Delay();
171 1
172 1 CLKMUL |= 0xC0; // Initialize the clock multiplier
173 1
174 1 while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
175 1
176 1 CLKSEL = 0x02; // Use Clock Multiplier/2 as system clock
177 1
178 1 }
179
C51 COMPILER V7.50 F326_USB0_MOUSE 06/25/2007 09:10:03 PAGE 4
180 //-----------------------------------------------------------------------------
181 // Port_Init
182 //-----------------------------------------------------------------------------
183 //
184 // Return Value - None
185 // Parameters - None
186 //
187 // - Configure the Crossbar and GPIO ports.
188 //
189 // ----------------------------------------------------------------------------
190 void Port_Init(void)
191 {
192 1
193 1 P2MDOUT |= 0x0C; // enable LEDs as a push-pull outputs
194 1
195 1 }
196
197 //-----------------------------------------------------------------------------
198 // Uart_Init
199 //-----------------------------------------------------------------------------
200 //
201 // Return Value - None
202 // Parameters - None
203 //
204 // - Configure the Uart.
205 //
206 // ----------------------------------------------------------------------------
207
208 void UART_Init()
209 {
210 1 SCON0 = 0x10;
211 1 SBRLL0 = 0x8F;
212 1 SBRLH0 = 0xFD;
213 1 SBCON0 = 0x43;
214 1 IP = 0x10;
215 1 IE = 0x90;
216 1 EA = 1;
217 1 }
218
219 //-----------------------------------------------------------------------------
220 // Timer_Init
221 //-----------------------------------------------------------------------------
222 //
223 // Return Value - None
224 // Parameters - None
225 //
226 // - Timer 2 reload, used to check if switch pressed on overflow and
227 // used for ADC continuous conversion
228 //
229 // ----------------------------------------------------------------------------
230 void Timer_Init(void)
231 {
232 1
233 1 TCON = 0x40;
234 1 TMOD = 0x20;
235 1 CKCON = 0x02;
236 1
237 1 TH1 = 0x00; // set reload value
238 1 IE = 0x08; // enable timer interrupt
239 1
240 1 }
241
C51 COMPILER V7.50 F326_USB0_MOUSE 06/25/2007 09:10:03 PAGE 5
242
243
244 //-----------------------------------------------------------------------------
245 // Delay
246 //-----------------------------------------------------------------------------
247 //
248 // Return Value - None
249 // Parameters - None
250 //
251 // Used for a small pause, approximately 80 us in Full Speed,
252 // and 1 ms when clock is configured for Low Speed
253 //
254 // ----------------------------------------------------------------------------
255 void Delay(void)
256 {
257 1 int x;
258 1 for(x = 0;x < 500;x)
259 1 x++;
260 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 168 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 8 ----
PDATA SIZE = ---- ----
DATA SIZE = 4 ----
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 + -