Техническая Спецификация для Microchip Technology DV164139

Скачать
Страница из 54
© 2009 Microchip Technology Inc.
DS41356B-page 21
EXAMPLE 2-7: 
USER DEFINED FUNCTIONAL CODE FOR 
EMULATE_MOUSE()
Note that the HID mouse transmits in 3-byte packets. The format of this packet is as 
follows:
• This byte is typically used to identify mouse buttons. Since this application does 
not require any mouse clicks, this byte is always zero.
• The second and third bytes represent horizontal (X) and Vertical (Y) 
displacements.
Compile the project. There should be no errors.
Testing the Application
9.
Ensure that the Low Pin Count USB Development Board is configured as in Lab 1.
10. Connect the PICkit 2 Programmer and open the PICkit 2 programming software.
11. Navigate to the .hex file located in the C:\LPCUSBDK_Labs\Lab2_files for 
this lab and download to the PIC18F14K50.
if (emulate_mode == TRUE)
    {
      //go 14 times in the same direction before changing 
      if (movement_length > 14)
      {
        buffer[0] = 0;
        buffer[1] = dir_table[vector & 0x07];
        //X-Vector
        buffer[2] = dir_table [(vector+2) & 0x07];
        //Y-Vector
        // go to the next direction in the table 
vector++;
        //reset the counter for when to change again 
movement_length = 0;
      }//end if (movement_length > 14)
    }
else
    {
        //don't move the mouse
        buffer[0] = buffer[1] = buffer[2] = 0;
    }
    if(HIDTxHandleBusy(lastTransmission) == 0)
    {
        //copy over the data to the HID buffer
        hid_report_in[0] = buffer[0];
        hid_report_in[1] = buffer[1];
        hid_report_in[2] = buffer[2];
  
//Send the 3 byte packet over USB to the host.
    
lastTransmission = HIDTxPacket(HID_EP, (BYTE*)hid_report_in, 
0x03);
        //increment the counter to change the data sent
        movement_length++;
    }
Note:
The device created in the Device Manager from the previous lab will need 
to be removed so that the new device, created in this lab, can enumerate 
properly. In the Device Manager window, right-click on the device and 
select Uninstall.