📄 f340_usb0_mouse.lst
字号:
C51 COMPILER V7.06 F340_USB0_MOUSE 09/12/2006 16:12:59 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE F340_USB0_MOUSE
OBJECT MODULE PLACED IN F340_USB0_Mouse.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F340_USB0_Mouse.c DB OE
stmt level source
1 //-----------------------------------------------------------------------------
2 // F340_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: 3XX000043
16 // Target: C8051F340
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
28 #include "c8051f3xx.h"
29 #include "F3xx_USB0_Mouse.h"
30 #include "F3xx_USB0_InterruptServiceRoutine.h"
31 #include "F3xx_USB0_Register.h"
32
33 //-----------------------------------------------------------------------------
34 // Definitions
35 //-----------------------------------------------------------------------------
36
37 #define SYSCLK 12000000 // SYSCLK frequency in Hz
38
39 // USB clock selections (SFR CLKSEL)
40 #define USB_4X_CLOCK 0x00 // Select 4x clock multiplier, for USB
41 #define USB_INT_OSC_DIV_2 0x10 // Full Speed
42 #define USB_EXT_OSC 0x20
43 #define USB_EXT_OSC_DIV_2 0x30
44 #define USB_EXT_OSC_DIV_3 0x40
45 #define USB_EXT_OSC_DIV_4 0x50
46
47 // System clock selections (SFR CLKSEL)
48 #define SYS_INT_OSC 0x00 // Select to use internal oscillator
49 #define SYS_EXT_OSC 0x01 // Select to use an external oscillator
50 #define SYS_4X_DIV_2 0x02
51
52 //-----------------------------------------------------------------------------
53 // 16-bit SFR Definitions for 'F32x
54 //-----------------------------------------------------------------------------
55
C51 COMPILER V7.06 F340_USB0_MOUSE 09/12/2006 16:12:59 PAGE 2
56 sfr16 TMR2RL = 0xca; // Timer2 reload value
57 sfr16 TMR2 = 0xcc; // Timer2 counter
58
59
60 //-----------------------------------------------------------------------------
61 // Local Definitions
62 //-----------------------------------------------------------------------------
63
64 #define Sw1 0x01 // These are the port2 bits for Sw1
65 #define Sw2 0x02 // and Sw2 on the development board
66
67 //-----------------------------------------------------------------------------
68 // Global Variable Declarations
69 //-----------------------------------------------------------------------------
70 signed char MOUSE_VECTOR;
71 unsigned char MOUSE_AXIS;
72 unsigned char MOUSE_BUTTON;
73
74 unsigned char IN_PACKET[4];
75
76 //-----------------------------------------------------------------------------
77 // Local Variable Declarations
78 //-----------------------------------------------------------------------------
79
80 unsigned char SWITCH_1_STATE = 0; // Indicate status of switch
81 unsigned char SWITCH_2_STATE = 0; // starting at 0 == off
82
83 unsigned char TOGGLE1 = 0; // Variable to make sure each button
84 unsigned char TOGGLE2 = 0; // press and release toggles switch
85
86
87 //-----------------------------------------------------------------------------
88 // Local Function Prototypes
89 //-----------------------------------------------------------------------------
90
91 void Sysclk_Init (void);
92 void Port_Init (void);
93 void USB0_Init (void);
94 void Timer_Init (void);
95 void ADC0_Init (void);
96 void Delay (void);
97
98 //-----------------------------------------------------------------------------
99 // Interrupt Service Routines
100 //-----------------------------------------------------------------------------
101
102 //-----------------------------------------------------------------------------
103 // Timer2_ISR
104 //-----------------------------------------------------------------------------
105 //
106 // Called when Timer 2 overflows, check to see if switch is pressed,
107 // then watch for release.
108 //
109 //-----------------------------------------------------------------------------
110
111 void Timer2_ISR (void) interrupt 5
112 {
113 1 if (!(P2 & Sw1)) // Check for switch #1 pressed
114 1 {
115 2 if (TOGGLE1 == 0) // Toggle is used to debounce switch
116 2 { // so that one press and release will
117 3 // toggle the state of the switch sent
C51 COMPILER V7.06 F340_USB0_MOUSE 09/12/2006 16:12:59 PAGE 3
118 3 SWITCH_1_STATE = ~SWITCH_1_STATE;
119 3 TOGGLE1 = 1; // to the host
120 3 }
121 2 }
122 1 else TOGGLE1 = 0; // Reset toggle variable
123 1
124 1 SWITCH_2_STATE = (P2 & Sw2);
125 1
126 1 TF2H = 0; // Clear Timer2 interrupt flag
127 1 }
128
129 //-----------------------------------------------------------------------------
130 // Adc_ConvComplete_ISR
131 //-----------------------------------------------------------------------------
132 // Called after a conversion of the ADC has finished
133 // - Updates the appropriate variable for either potentiometer or temperature
134 // sensor
135 // - Switches the Adc multiplexor value to switch between the potentiometer and
136 // temp sensor
137 //
138 //-----------------------------------------------------------------------------
139 void Adc_ConvComplete_ISR (void) interrupt 10
140 {
141 1
142 1 AD0INT = 0; // acknowledge interrupt
143 1
144 1 MOUSE_VECTOR = ADC0H - 128; // save potentiometer value, and add
145 1 // offset
146 1
147 1 MOUSE_VECTOR = MOUSE_VECTOR / 16; // reduce magnitude of value
148 1
149 1 // Switch 1 functions to toggle between movement along the
150 1 // x axis and movement along the y axis
151 1 if (SWITCH_1_STATE)
152 1 {
153 2 MOUSE_AXIS = Y_Axis;
154 2 }
155 1 else
156 1 {
157 2 MOUSE_AXIS = X_Axis;
158 2 }
159 1
160 1 // Switch 2 operates as the left mouse button
161 1 if(SWITCH_2_STATE)
162 1 {
163 2 // button not pressed
164 2 MOUSE_BUTTON = 0;
165 2 }
166 1 else
167 1 {
168 2 // button pressed
169 2 MOUSE_BUTTON = 0x01;
170 2 }
171 1
172 1 }
173
174
175 //-----------------------------------------------------------------------------
176 // Initialization Routines
177 //-----------------------------------------------------------------------------
178
179 //-----------------------------------------------------------------------------
C51 COMPILER V7.06 F340_USB0_MOUSE 09/12/2006 16:12:59 PAGE 4
180 // System_Init (void)
181 //-----------------------------------------------------------------------------
182 //
183 // Return Value - None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -