CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

[How To] Create a own USB HID device

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

[How To] Create a own USB HID device
PostPosted: Sun Dec 30, 2012 8:12 am     Reply with quote

Hello Community,

A few days ago I started to create my own USB device.
I also saw that much guys tried that also, maybe they got it working or not and because of this I want to release my C# and my PIC Project.

The C# program is not fully made by me, but I edited it and even got it working for my device.

The most important things in the PIC firmware:
Commands:
Code:
//Commands
#define CMD_LED2_ON 0x80
#define CMD_STATE_LED2_ON 0x81


Check the incoming data for the Commands:
Code:
//Get the Data
usb_get_packet(1,in_data,16);
//Write to the LCD that Data has been received
printf(lcd_putc,"\fReceived Data:\n");

//Check if the incoming byte equals the Command
if(in_data[0] == CMD_STATE_LED2_ON)
{
  //Write to the LCD that command 0x81 has been executed
  printf(lcd_putc,"LED2 is: %d", input(LED2));

  //Check if LED is high
  if(input(LED2))
  { 
     //Set the output byte to 0x01 == true
     out_data[0] = 0x01;
     //Send data
     usb_put_packet(1,out_data,16 USB_DTS_TOGGLE);
     output_high(LED2);
  }
  else
  {
     //set the output byte to 0x00 == false
     out_data[0] = 0x00;
     //Send data
     usb_put_packet(1,out_data,16 USB_DTS_TOGGLE);
  }
}
else if(in_data[0] == CMD_LED2_ON)
{
  //Toggle LED State
  printf(lcd_putc,"Turn LED2 ON");
  output_toggle(LED2);
}


The most important things in the C# Project
Execute a command:
Code:
public void RunCommand(Byte be)


PID and VID:
Code:
Int32 myProductID = Convert.ToInt32(0x0042);
Int32 myVendorID = Convert.ToInt32(0x04D8);


Get data from the PIC for example: Read the LED state:
Code:
if (!hidHandle.IsInvalid)
{
    ReadCommand(0x81);
    //Read the LED state
    bool ledState = Convert.ToBoolean(m_Result);
   
    if (ledState == true) this.ledStateLabel.Text = "LED is on";
    else this.ledStateLabel.Text = "LED is off";
}


Here are the Downloads, hosted on my server:
Firmware:
Firmware

C# Program
C# Program

Schematic (The LCD is just for Debugging, the Schematic does not contain a schematic how to wire it.
Easy Schematic

Example Picture (You see there much more than it's needed. I use this Board also for an ADC Reader)
Example Picture

I hope it helps to understand it and getting it working for you too and I hope that someone moderator will make it sticky.

Leave a comment please Smile

Regards Benni


Last edited by benni on Thu Oct 03, 2013 6:10 am; edited 1 time in total
rakkoc



Joined: 05 Apr 2012
Posts: 1

View user's profile Send private message

PostPosted: Mon Aug 12, 2013 9:31 am     Reply with quote

Links are broken, can you upload again ?
benni



Joined: 28 Jun 2012
Posts: 28

View user's profile Send private message

PostPosted: Thu Oct 03, 2013 6:12 am     Reply with quote

Hey,

Links are updated.

Regards Benni
ze.vana



Joined: 11 Jun 2011
Posts: 15

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 08, 2014 5:22 am     Reply with quote

benni wrote:
Hey,

Links are updated.

Regards Benni

you are right I'm the one who is having a lot of difficulty starting on usb hid devices
I have started in visual c# 2008 last year, and now c# 2010. I've already made many C# projects
communication with PIC4550,2550 usb->PC, but using C# serial Port, I wanna do it using HID.
But As the guy said "THE LINKS ARE BROKEN". Could you please send me it by email:
ze.vana@hotmail.com , I have an account in www.4shared.com, if you have too, you can put the your links there.
pieter



Joined: 16 Jan 2011
Posts: 27

View user's profile Send private message

information
PostPosted: Fri Mar 14, 2014 12:12 am     Reply with quote

Hi Benni, can you please post your downloads on the forum?
Thanks!
sohar



Joined: 14 Aug 2014
Posts: 1

View user's profile Send private message

PostPosted: Thu Aug 14, 2014 11:44 pm     Reply with quote

Note: CCS defaults to software i2c, unless you use the
hardware i2c pins and add the FORCE_HW parameter to the #use i2c()
statement.
_________________
####### Abdul Rehman ########
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group