Microchip Technology DV164139 Data Sheet

Page of 54
© 2009 Microchip Technology Inc.
DS41356B-page 19
2.5.2
Overview of the HID Mouse Firmware
As with most of the Framework applications, the user defined source code is called 
from the ProcessIO() function in the <application>.c file. The user defined firm-
ware will manipulate the Host PC mouse pointer to move in a single direction for 14 
times through the main loop. After 14 times, the mouse pointer changes direction ulti-
mately moving in a complete circle. A bit flag is initialized named emulate_mode that 
will toggle HIGH/LOW whenever the push button on the Low Pin Count USB Develop-
ment Board is pressed. The status of this flag will start or stop pointer movement on the 
screen by not calling the user defined function, emulate_mouse(), which handles the 
mouse movement routines.
The flowchart for the user defined function is shown in Figure 2-4.
FIGURE 2-4:
FLOWCHART FOR THE EMULATE_MOUSE()
In the flowchart of Figure 2-4, it can be seen that if the emulate_mode flag is ‘0’, the 
directional data transmitted along the USB is cleared. Note that data is transmitted from 
the PIC18F14K50 whether or not the flag is set. Data is transmitted only when the SIE 
is capable of transmitting it. This check is implemented in code by using the 
if(HIDTxHandleBusy(lastTransmission) == 0)
 conditional statement. The 
lastTransmission
 is loaded at the time of transmission and processed by the 
HIDTxHandleBusy 
macro in the conditional ‘if’ statement.
If the emulate_mode flag is set, the function enters into the mouse pointer movement 
algorithm. This is accomplished by keeping track of a counter variable, 
movement_length
. When this variable exceeds 14, a buffer array is loaded with new 
directional data as supplied by the dir_table array defined at the top of the mouse.c 
file. Each element of the array is accessed by incrementing the vector variable counter. 
The buffer array is then loaded into a hid_report_in[] buffer array that is used by 
the HIDTxPacket macro to transmit the data along the USB to the Host PC.
Emulate_Mouse ()
emulate_mode 
= TRUE
YES
YES
movement_length 
> 14?
Change directional 
data to next vector
Clear directional data
Keep directional 
data as before
NO
NO
NO
PIC18F14K50 
own the SIE
YES
Transmit directional 
data along USB
return
return
TRUE = 1
FALSE = 0