?? gphidapp.lst
字號:
C51 COMPILER V6.10 GPHIDAPP 10/10/2001 19:23:08 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE GPHIDAPP
OBJECT MODULE PLACED IN .\gpHIDapp.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\gpHIDapp.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*-----------------------------------------------------------------------------
2 File: ghHIDapp.c 27-Aug-01 LTH
3 Contents: General Purpose HID device with following characteristics:
4 1. VID=0547h, PID=7450h, DID=0001h
5 2. Input and Output reports are 2 bytes
6 3. HID input reports return:
7 a. The number of output reports received
8 b. EZ-USB Dev board switches
9 6. The background program constantly displays the last output
10 report hex digits received in the 7-seg readout.
11 7. Five strings; manuf(1),prod(2),s/n(3),cfg(4), and iface(5.
12
13 Copyright (c) 2001 Cypress Semiconductor, Inc. All rights reserved
14 ------------------------------------------------------------------------------*/
15 #pragma intvector (0x17FD)
16 #pragma interval(4) // put USB (INT2) interrupt vector table at 1800,1804...
17 #include "ezusb.h"
18 #include "ezregs.h"
19
20 extern BOOL GotSUD; // Received setup data flag
21 extern BOOL Sleep;
22 extern BOOL Rwuen;
23 extern BOOL Selfpwr;
24 //-----------------------------------------------------------------------------
25 // Constants
26 //-----------------------------------------------------------------------------
27 #define ButtonAddr 0x41
28 #define seg7Addr 0x42
29 #define bmF1 0x01
30 #define bmF2 0x02
31 #define bmF3 0x04
32 #define bmF4 0x08
33 #define bmDIP1 0x10
34 #define bmDIP2 0x20
35 //-----------------------------------------------------------------------------
36 // Variables
37 //-----------------------------------------------------------------------------
38 BYTE Configuration; // Current configuration
39 BYTE AlternateSetting; // Alternate settings
40 BYTE buttons,oldbuttons;
41 BYTE leds=0xFF;
42 BYTE dp,old_dp; // decimal point
43 char data Digit[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98,0x88,0x83,0xc6,0xa1,0x86,0x8e};
44 int tick,count,timeconst;
45 #define TCMS 500 // Time constant in milliseconds (incremented in SOF ISR)
46 //-----------------------------------------------------------------------------
47 // Function prototypes
48 //-----------------------------------------------------------------------------
49 BYTE read_buttons(void); // Read the Dev Board buttons thru i2c port
50 void display (BYTE); // Update the 7-seg readout thru i2c port
51 //-----------------------------------------------------------------------------
52 // Task Dispatcher (TD) hooks
53 // The following functions are called by the task dispatcher.
54 //-----------------------------------------------------------------------------
55 void TD_Init(void) // Called once at startup
C51 COMPILER V6.10 GPHIDAPP 10/10/2001 19:23:08 PAGE 2
56 {
57 1 IN07VAL = bmEP1; // Enable our EP's: EP1-IN & EP1-OUT
58 1 OUT07VAL = bmEP1;
59 1 USBIEN = bmSOF; // Enable SOF interrupt
60 1 display(0x7F); // 7-seg readout--decimal point only
61 1 timeconst = TCMS; // initial value
62 1 old_dp = 0; // used to detect change in decimal point value
63 1 IN1BUF[0] = 0;
64 1 IN1BUF[1] = 0;
65 1 IN1BC = 2; // Arm EP1-in in case an IN arrives before an OUT (W2K)
66 1 }
67
68 void TD_Poll(void) // Called repeatedly while not handling SETUP packets
69 {
70 1 EUSB=0; // turn off USB (SOF) interrupt
71 1 if (tick > timeconst) // see if timer has hit max
72 1 {
73 2 tick=0;
74 2 count++;
75 2 count &= 0x0F;
76 2 display(Digit[count]); // look up segments
77 2 IN1BUF[0] = count; // update the display value
78 2 }
79 1 EUSB=1; // USB interrupts back on
80 1 //
81 1 buttons = read_buttons();
82 1 if (buttons == read_buttons()) //Debounce
83 1 {
84 2 if ((oldbuttons - buttons) != 0) //Change in button state
85 2 oldbuttons = buttons;
86 2 }
87 1
88 1 if(!(OUT1CS & bmEPBUSY)) // Is there something available?
89 1 {
90 2 timeconst = OUT1BUF[0]*20; // Output Report Byte 0 is time const (tenths of sec)
91 2 dp = OUT1BUF[1]; // decimal point
92 2 OUT1BC = 0; // Re-arm EP1-OUT
93 2 IN1BUF[0] = count;
94 2 IN1BUF[1] = buttons;
95 2 IN1BC = 2; // arm the EP2-IN transfer
96 2 if (dp != old_dp) // update the display NOW if dp data changed
97 2 {
98 3 old_dp = dp; // update stored value
99 3 display(Digit[count]); // look up segments
100 3 }
101 2 }
102 1 }
103
104 BYTE read_buttons (void) // Read the Dev board buttons
105 { // Make available in 4 lsb's, active TRUE
106 1 BYTE d;
107 1 while (I2CS & 0x40); //Wait for stop complete
108 1 I2CS = 0x80; //Set start condition
109 1 I2DAT = ButtonAddr; //Write button address
110 1 while (!(I2CS & 0x01)); //Wait for done
111 1 I2CS = 0x20; //Set last read
112 1 d = I2DAT; //trigger last read
113 1 while (!(I2CS & 0x01)); //Wait for done
114 1 I2CS = 0x40; //Set stop bit
115 1 d = ~I2DAT; // Active TRUE
116 1 d &= 0x0F; // 4 LSB's only
117 1 return(d); //Return the 4 PB values in active-true form
C51 COMPILER V6.10 GPHIDAPP 10/10/2001 19:23:08 PAGE 3
118 1 }
119
120 void display (BYTE d)
121 {
122 1 d &= 0x7F; // Clear the MSB
123 1 d |= (dp & 0x80); // OR in the decimal point (MSB)
124 1 while (I2CS & 0x40); //Wait for stop to be done
125 1 I2CS = 0x80; //Set start condition
126 1 I2DAT = seg7Addr; //Write led address
127 1 while (!(I2CS & 0x01)); //Wait for done
128 1 I2DAT = d; //Write data
129 1 while (!(I2CS & 0x01)); //Wait for done
130 1 I2CS = 0x40; //Set stop bit
131 1 }
132
133 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
134 {
135 1 return(TRUE);
136 1 }
137
138 BOOL TD_Resume(void) // Called after the device resumes
139 {
140 1 return(TRUE);
141 1 }
142 //-----------------------------------------------------------------------------
143 // Device Request hooks
144 // The following functions are called by the endpoint 0 device request parser.
145 //-----------------------------------------------------------------------------
146 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
147 {
148 1 Configuration = SETUPDAT[2];
149 1 return(TRUE); // Handled by user code
150 1 }
151
152 BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
153 {
154 1 IN0BUF[0] = Configuration;
155 1 EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
156 1 return(TRUE); // Handled by user code
157 1 }
158
159 BOOL DR_SetInterface(void) // Called when a Set Interface command is received
160 {
161 1 AlternateSetting = SETUPDAT[2];
162 1 return(TRUE); // Handled by user code
163 1 }
164
165 BOOL DR_GetInterface(void) // Called when a Set Interface command is received
166 {
167 1 IN0BUF[0] = AlternateSetting;
168 1 EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
169 1 return(TRUE); // Handled by user code
170 1 }
171
172 BOOL DR_GetStatus(void)
173 {
174 1 return(TRUE);
175 1 }
176
177 BOOL DR_ClearFeature(void)
178 {
179 1 return(TRUE);
C51 COMPILER V6.10 GPHIDAPP 10/10/2001 19:23:08 PAGE 4
180 1 }
181
182 BOOL DR_SetFeature(void)
183 {
184 1 return(TRUE);
185 1 }
186
187 //-----------------------------------------------------------------------------
188 // USB Interrupt Handlers
189 // The following functions are called by the USB interrupt jump table.
190 //-----------------------------------------------------------------------------
191 void ISR_Sudav(void) interrupt 0 // Setup Data Available
192 {
193 1 GotSUD = TRUE; // Set flag
194 1 EZUSB_IRQ_CLEAR();
195 1 USBIRQ = bmSUDAV; // Clear SUDAV IRQ
196 1 }
197
198 void ISR_Sutok(void) interrupt 2 // Setup token (not used)
199 {
200 1 }
201
202 void ISR_Sof(void) interrupt 1 // SOF
203 {
204 1 EZUSB_IRQ_CLEAR();
205 1 USBIRQ = bmSOF; // Clear SOF IRQ
206 1 tick++;
207 1 }
208
209 void ISR_Ures(void) interrupt 4
210 {
211 1 EZUSB_IRQ_CLEAR();
212 1 USBIRQ = bmURES; // Clear URES IRQ
213 1 }
214
215 //void ISR_IBN(void) interrupt 5 (Not in AN2131)
216 //{
217 //}
218
219 void ISR_Susp(void) interrupt 3
220 {
221 1 Sleep = TRUE; // Just set a flag for fw2.c to check.
222 1 EZUSB_IRQ_CLEAR();
223 1 USBIRQ = bmSUSP;
224 1 }
225
226 void ISR_Ep0in(void) interrupt 6
227 {
228 1 EZUSB_IRQ_CLEAR(); // clear USB (INT2) request
229 1 IN07IRQ = bmEP0; // clear EP0-IN int request
230 1 }
231
232 void ISR_Ep0out(void) interrupt 7
233 {
234 1 EZUSB_IRQ_CLEAR();
235 1 OUT07IRQ = bmEP0;
236 1 }
237
238 void ISR_Ep1in(void) interrupt 8
239 {
240 1 EZUSB_IRQ_CLEAR();
241 1 IN07IRQ = bmEP1;
C51 COMPILER V6.10 GPHIDAPP 10/10/2001 19:23:08 PAGE 5
242 1
243 1 }
244
245 void ISR_Ep1out(void) interrupt 9
246 {
247 1 EZUSB_IRQ_CLEAR();
248 1 OUT07IRQ = bmEP1;
249 1
250 1 }
251
252 void ISR_Ep2in(void) interrupt 0x0A
253 {
254 1 EZUSB_IRQ_CLEAR();
255 1 IN07IRQ = bmEP2;
256 1 }
257
258 void ISR_Ep2out(void) interrupt 0x0B
259 {
260 1 EZUSB_IRQ_CLEAR();
261 1 OUT07IRQ = bmEP2;
262 1 }
263
264 void ISR_Ep3in(void) interrupt 0x0C
265 {
266 1 EZUSB_IRQ_CLEAR();
267 1 IN07IRQ = bmEP3;
268 1 }
269
270 void ISR_Ep3out(void) interrupt 0x0D
271 {
272 1 EZUSB_IRQ_CLEAR();
273 1 OUT07IRQ = bmEP3;
274 1 }
275
276 void ISR_Ep4in(void) interrupt 0x0E
277 {
278 1 EZUSB_IRQ_CLEAR();
279 1 IN07IRQ = bmEP4;
280 1 }
281
282 void ISR_Ep4out(void) interrupt 0x0F
283 {
284 1 EZUSB_IRQ_CLEAR();
285 1 OUT07IRQ = bmEP4;
286 1 }
287
288 void ISR_Ep5in(void) interrupt 0x10
289 {
290 1 EZUSB_IRQ_CLEAR();
291 1 IN07IRQ = bmEP5;
292 1 }
293
294 void ISR_Ep5out(void) interrupt 0x11
295 {
296 1 EZUSB_IRQ_CLEAR();
297 1 OUT07IRQ = bmEP5;
298 1 }
299
300 void ISR_Ep6in(void) interrupt 0x12
301 {
302 1 EZUSB_IRQ_CLEAR();
303 1 IN07IRQ = bmEP6;
C51 COMPILER V6.10 GPHIDAPP 10/10/2001 19:23:08 PAGE 6
304 1 }
305
306 void ISR_Ep6out(void) interrupt 0x13
307 {
308 1 EZUSB_IRQ_CLEAR();
309 1 OUT07IRQ = bmEP6;
310 1 }
311
312 void ISR_Ep7in(void) interrupt 0x14
313 {
314 1 EZUSB_IRQ_CLEAR();
315 1 IN07IRQ = bmEP7;
316 1 }
317
318 void ISR_Ep7out(void) interrupt 0x15
319 {
320 1 EZUSB_IRQ_CLEAR();
321 1 OUT07IRQ = bmEP7;
322 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 805 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 29 ----
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 + -