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