📄 f326_usb0_mouse.lst
字号:
C51 COMPILER V7.50 F326_USB0_MOUSE 06/22/2006 17:45:53 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 LARGE
line level source
1 //-----------------------------------------------------------------------------
2 // F326_USB0_Mouse.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2005 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // Source file for routines that mouse data.
10 //
11 //
12 // How To Test: See Readme.txt
13 //
14 //
15 // FID: 3XX000042
16 // Target: C8051F326
17 // Tool chain: Keil C51 7.50 / Keil EVAL C51
18 // Silicon Laboratories IDE version 2.6
19 // Command Line: See Readme.txt
20 // Project Name: F3xx_MouseExample
21 //
22 // Release 1.0
23 // -Initial Revision (PD)
24 // -07 DEC 2005
25 //
26
27 #include "F3xx_USB0_Mouse.h"
28 #include "c8051f3xx.h"
*** WARNING C318 IN LINE 30 OF c8051f3xx.h: can't open file 'c8051f326.h'
29 #include "F3xx_USB0_InterruptServiceRoutine.h"
30 #include "F3xx_USB0_Register.h"
31
32 //-----------------------------------------------------------------------------
33 // Definitions
34 //-----------------------------------------------------------------------------
35
36 #define SYSCLK 12000000 // SYSCLK frequency in Hz
37
38 // USB clock selections (SFR CLKSEL)
39 #define USB_4X_CLOCK 0x00 // Select 4x clock multiplier, for USB
40 #define USB_INT_OSC_DIV_2 0x10 // Full Speed
41 #define USB_EXT_OSC 0x20
42 #define USB_EXT_OSC_DIV_2 0x30
43 #define USB_EXT_OSC_DIV_3 0x40
44 #define USB_EXT_OSC_DIV_4 0x50
45
46 // System clock selections (SFR CLKSEL)
47 #define SYS_INT_OSC 0x00 // Select to use internal oscillator
48 #define SYS_EXT_OSC 0x01 // Select to use an external oscillator
49 #define SYS_4X_DIV_2 0x02
50
51 //-----------------------------------------------------------------------------
52 // 16-bit SFR Definitions for 'F326
53 //-----------------------------------------------------------------------------
54
C51 COMPILER V7.50 F326_USB0_MOUSE 06/22/2006 17:45:53 PAGE 2
55 sfr16 TMR2RL = 0xca; // Timer2 reload value
56 sfr16 TMR2 = 0xcc; // Timer2 counter
57
58
59 //-----------------------------------------------------------------------------
60 // Local Definitions
61 //-----------------------------------------------------------------------------
62
63 #define Sw1 0x01 // These are the port2 bits for Sw1
64 #define Sw2 0x02 // and Sw2 on the development board
65
66 //-----------------------------------------------------------------------------
67 // Global Variable Declarations
68 //-----------------------------------------------------------------------------
69 signed char MOUSE_VECTOR;
70 unsigned char MOUSE_AXIS;
71 unsigned char MOUSE_BUTTON;
72 unsigned char IN_PACKET[4];
73
74 //-----------------------------------------------------------------------------
75 // Local Variable Declarations
76 //-----------------------------------------------------------------------------
77
78 unsigned char SWITCH_1_STATE = 0; // Indicate status of switch
79 unsigned char SWITCH_2_STATE = 0; // starting at 0 == off
80
81 unsigned char TOGGLE1 = 0; // Variable to make sure each button
82 unsigned char TOGGLE2 = 0; // press and release toggles switch
83
84
85 //-----------------------------------------------------------------------------
86 // Local Function Prototypes
87 //-----------------------------------------------------------------------------
88
89 void Sysclk_Init(void);
90 void Port_Init(void);
91 void USB0_Init(void);
92 void Timer_Init(void);
93 void Delay(void);
94
95 //-----------------------------------------------------------------------------
96 // Interrupt Service Routines
97 //-----------------------------------------------------------------------------
98
99 //-----------------------------------------------------------------------------
100 // Timer1_ISR
101 //-----------------------------------------------------------------------------
102 // Called when timer 1 overflows, check to see if switch is pressed,
103 // then watch for release.
104 // This routine sets the Mouse_... variables for the report handler.
105 //
106 //-----------------------------------------------------------------------------
107 void Timer1_ISR(void) interrupt 3
108 {
109 1 static unsigned char Mouse_Count = 0;
110 1 static unsigned char Mouse_MovementMultiplier = 0;
111 1 static signed char Mouse_Direction = 1;
112 1 static unsigned char Mouse_StateMachine = 0;
113 1
114 1 if (!(P2 & Sw1)) // Check for switch #1 pressed
*** ERROR C202 IN LINE 114 OF F326_USB0_MOUSE.C: 'P2': undefined identifier
115 1 {
C51 COMPILER V7.50 F326_USB0_MOUSE 06/22/2006 17:45:53 PAGE 3
116 2 // if switch 1 is pressed, increase the magnitude of the mouse
117 2 // movement vector
118 2 if(Mouse_MovementMultiplier <= 255)
119 2 {
120 3 Mouse_MovementMultiplier += 1;
121 3 }
122 2
123 2 if (TOGGLE1 == 0) // Toggle is used to debounce switch
124 2 { // so that one press and release will
125 3 SWITCH_1_STATE = ~SWITCH_1_STATE; // toggle the state of the switch sent
126 3 TOGGLE1 = 1; // to the host
127 3 }
128 2 }
129 1 else
130 1 {
131 2 TOGGLE1 = 0; // Reset toggle variable
132 2
133 2 // if switch 1 is not pressed, reduce the magnitude of the mouse
134 2 // movement vector
135 2 if(Mouse_MovementMultiplier > 0)
136 2 {
137 3 Mouse_MovementMultiplier -= 1;
138 3 }
139 2 }
140 1
141 1
142 1 SWITCH_2_STATE = (P2 & Sw2);
*** ERROR C202 IN LINE 142 OF F326_USB0_MOUSE.C: 'P2': undefined identifier
143 1
144 1 // Mouse_Count sets the number of timer interrupts serviced before
145 1 // the mouse changes direction
146 1 if(Mouse_Count++ == 50)
147 1 {
148 2 // the mouse state machine cycles through states 0-3
149 2 if(++Mouse_StateMachine == 4) Mouse_StateMachine = 0;
150 2
151 2 // each state sets the mouse to turn 90 degrees clockwise
152 2 switch (Mouse_StateMachine)
153 2 {
154 3 case(0):
155 3 // positive X direction
156 3 Mouse_Direction = 1;
157 3 MOUSE_AXIS = X_Axis;
158 3 break;
159 3 case(1):
160 3 // negative Y direction
161 3 Mouse_Direction = -1;
162 3 MOUSE_AXIS = Y_Axis;
163 3 break;
164 3 case(2):
165 3 // negative X direction
166 3 Mouse_Direction = -1;
167 3 MOUSE_AXIS = X_Axis;
168 3 break;
169 3 case(3):
170 3 // positive Y direction
171 3 Mouse_Direction = 1;
172 3 MOUSE_AXIS = Y_Axis;
173 3 break;
174 3 }
175 2
176 2 Mouse_Count = 0;
C51 COMPILER V7.50 F326_USB0_MOUSE 06/22/2006 17:45:53 PAGE 4
177 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -