0% found this document useful (0 votes)
252 views24 pages

EasyHID: USB Communication Guide

EasyHID is a software program that allows PIC microcontrollers with a USB module to communicate with computers over USB. The document provides instructions on installing EasyHID and using it to generate code templates for a PIC microcontroller and PC application to enable two-way USB communication between the two. It describes using the EasyHID wizard to configure details of the project like buffer sizes and location before generating code for the microcontroller in PicBasic Pro and PC in Visual Basic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
252 views24 pages

EasyHID: USB Communication Guide

EasyHID is a software program that allows PIC microcontrollers with a USB module to communicate with computers over USB. The document provides instructions on installing EasyHID and using it to generate code templates for a PIC microcontroller and PC application to enable two-way USB communication between the two. It describes using the EasyHID wizard to configure details of the project like buffer sizes and location before generating code for the microcontroller in PicBasic Pro and PC in Visual Basic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Using the EasyHID program

EasyHID is a software program created to support the use of PIC


microcontrollers that has a USB (Universal Serial Bus) module such
as PIC18F2550, PIC18F4550, etc. by the capabilities of the software
This is able to create HID of USB devices. You can create basic
programs for both BASIC language of microcontrollers
Microcontroller (PicBasic Pro) and create basic programs for
programs on computers, namely Visual Basic, Visual C++ and Delphi
which can be studied and learned from the following examples.

Installing the EasyHID program

Open the EasyHID file and click the 2 icons to SETUP the picture.

A Welcome window will appear, click Next>.


Click Yes to accept the License.

Select the installation destination, then click Next > The program will
begin the installation process until it completes.
Click Finish to complete the program installation.

Example steps for using EasyHID

The following example will design an application. It is


divided into two main parts: the microcontroller uses the
number PIC18F4550 (hardware referenced with the board
ET-PICUSB/4550) and computer which will be developed
with Visual Basic program. The working of the program is
It sends messages from the computer program via the USB
bus system to the PIC18F4550 microcontroller and displays
the messages on the LCD screen, which can be studied and
experimented with the following steps

■ Open the EasyHID program by clicking Start > Programs


> EasyHID > EasyHID as shown in the following figure.

The EasyHID Wizard window will appear for us to enter Company


Name, Product Name and Serial Number as we want As in the
example in the picture, then click Next >

Introduction
EasyHID is designed to provide a simple solution to
the problems normally associated with implementing
USB communications between a PIC microcontroller
and Personal Computer (PC),

EasyHID is used to create two program templates;


ready for compiling. One program is targetted for
your PIC microcontroller (the USB device); the other
is used on your PC (the USB host).

Device Information
Please enter your company and product name, The
company and product name strings are mandatory
fields. The device serial number is an optional string
value and can be omitted.
Company Name

Product Name

Serial Number

Enter the required Vendor ID and Product ID numbers as in the


example, then click Next>.

Wizard

Vendor and Product ID


Please enter a valid Vendor ID (VID) and Product ID (PID),
9999
Vendor ID
0001
Product ID
If you intend to ship a USB device you need an official USB Vendor IDj which is unique throughout
the world. Vendor ID ' S are assigned by the USB implementers forum at www.usb.org . Use the
default values above FOR TESTING ONLY.

Alternatively, Mecanique own a USB Vendor ID and can provide an individual or a company
with a set of product ID ' S at very low cost. This means that your product can be shipped
world wide with a guaranteed unique and unambiguous VID and PID combination.

□ Purchase a unique set of Products IDs so that I can distribute mv product...


□ Tell me more about using Vendor and Product IP's...

Set the desired properties You can choose the size of Buffer (Input) and Buffer (Output) as
desired. The maximum is 64 bytes, as in the following example.

Set 16 bytes. When finished, click Next >.

EasyHID Wizard

Configuration Details
The input polling interval is used by the host to request data from a USB device. The
output polling interval is used by the host to send data to a USB device, Bus power is the
maximum power consumption (x2) of the USB device on the bus.
10
Polling (Input) ms - host requests data from a USB device (max latency) ms -
10
Polling (Output) 50 host sends data to a USB device (max latency) x2 rnA

Bus Power
The input buffer (report) is sent by a USB device when requested to do so by the host,
The output buffer (report) is sent by the host to a USB device.
16
Buffer (Input) bytes - USB device to host (64 bytes max)
16
Buffer bytes - host to USB device (64 bytes max)

(Output)
If you are unsure about the correct values to enter, use the recommended
defaults.
Defaults

■ Specify details. as we want to design As in the following example


o Project Name = The name of the project that we want in the example is
USB4550 LCD o Location = The location where you want to store the folder that
will be created o USB Device

Compiler
-Compiler is a language translator used.
- Microcontroller = Number of the microcontroller that we will design o
Application Compiler
- Compiler = Program language used for writing programs on PC.

When specifying various details as desired or as in the example in the picture


below. When finished, click next > to proceed to the next step.

The program will start various processes. Until the process is finished, click
Finish.
Then let us go look at the location that we defined. You will see the folder. It
happens as we named it, which in this example is USB4550 LCD, which contains
two more folders: PicBasicPRO and VisualBASIC, as shown in the following
picture.

-13-
การใช้งาน EasyHID

Inside is a program code that provides basic functions related to USB. The
following figure is the basic PicBasic Pro program that EasyHID created.

The following picture is the Visual Basic program that EasyHID created.

-14-
We can take this code and develop it further according to our needs.
การใช้งาน EasyHID

■ The PicBasic Pro program code that has been created includes the DoUSBIn
function for receiving data from USB into the USBBuffer variable and the
DoUSBOut function for sending data out to the USB bus.

Code Explorer

Ij^j Includes

&■(£) Defines
[รู้] osc
[นิ] LOADERJJSED El
(ร) Constants
[รู้] USBBufferSizeMa [รู้]
USBBufferSizeTX [รู้]
USBBufferSizeRX El (ร) Variables
(ฏ USBBuffer (v|
USBBufferCount fp=ฯ Alias and
Modifiers Ir3! Symbols ^) Labels
[jj] ProgramStart UJ
DoUSBIn บ]
DoUSBOut

SI U5B455CLLCD
DEFINE OSC 48 DEFINE
LOADER_USED 1

maximum buffer size U S B B u f f eirSizeMax CON 16


USBBufferSizeTX CON 16 F
Input
USBBufferSizeRX CON 16 r
output

F
the USB buffer. . .
USBBuffer VAR BYTE[USBBuffersizeMax]
USBBufferCount VAR BYTE

- ฟ - ฟ่ - ฟ่ - ฟ่ - H - H - ฟ - ฟ่ - ฟ่ H - H ■ ฟ - ฟ - ฟ - ฟ่ - ฟ่ - - ฟ - ฟ่ - ฟ่ - ฟ่ - H - H - ฟ - ฟ่ - ฟ่ - ?

* main program loop - remember, r you must keep the USB *


* connection alive with a call to USB Service every couple *
* of milliseconds or so. . . *
- ฟ - ฟ่ - ฟ่ - ฟ่ - H - H - ฟ - ฟ่ - ฟ่ H - H ■ ฟ - ฟ - ฟ - ฟ่ - ฟ่ - - ฟ - ฟ่ - ฟ่ - ฟ่ - H - H - ฟ - ฟ่ - ฟ่ - ?
USBINIT r
Initialise USB. . .
ProgramStart:
GOSUB DoUSBIn GOSUB
DoUSBOut GOTO
ProgramStart

' -ฟ - ฟ่ - ฟ่ - ฟ่ -H-H-ฟ - ฟ่ - ฟ่ H-H■ฟ -ฟ -ฟ - ฟ่ - ฟ่ --ฟ - ฟ่ - ฟ่ - ฟ่ -H-H-ฟ - ฟ่ - ฟ่ H-H■ฟ -ฟ -ฟ -?!-?!-

' * receive data from the USB bus *


'
A*****#******##*****###*****##******##*****###****
*##*****#*
DoUSBIn:
USBBufferCount = USBBufferSizeRX ' RX buffer size

-15-
USB SERVICE ' keep connection alive
การใช้งานUEasyHID
SBIN 1, USBBuffer, USBBufferCount, DoUSBIn read data, If available
r

RETURN

'
A*****#******##*****###*****##******##*****###****
*##*****#*
r
* wait for USB Interface to attach *
I
******************************************************
******
DoUSBOut:
USBBufferCount = USBBufferSizeTX r
TX buffer size
USB SERVICE r
Aeep connection alive
USBOUT 1 , U S B B u f f e r , U S B B u f f e r C o u n t , D o U S B O u t ' If bus a v a i i a M e , t j c a n s r RETURN ริ
<]||| ■ a) >๒
(^) Ready

In this example, we will receive values from USB and display them on the LCD
screen. The complete program developed from the basic program that EasyHID
designed will be as follows.

Using EasyHID, example code for PicBasic Pro

DEFINE osc 48 DEFINE LOADERUSED 1 Define LCDDREG PORTD Define

LCD DBIT 4 Define LCD RSREG PORTD Define LCD RSBIT 2 Define LCD

EREG PORTD Define LCD EBIT 3 Define LCD BITS 4

USBBufferSizeMax con 16 ' maximum buffer size USBBufferSizeTX con

16 ' input USBBufferSizeRX con 16 ' output

' the USB buffer...

USBBuffer Var Byte[USBBufferSizeMax]

USBBufferCount Var Byte

i var byte

' * main program loop - remember, you must keep the USB *

' * connection alive with a call to USBService every couple *

' * of milliseconds or so... *

usbinit' initialise USB... pause 1500

LCDOut $fe, 1 ' Clear LCD screen LCDOut "CP-

PICUSB4550" ' Display Hello

-16-
ProgramStart:
การใช้งาน EasyHID gosub DoUSBIn

LCDOUT $FE,$C0," " ' Clear Display Line 2 of LCD

LCDOUT $FE,$C0 ' Point to FristAddress of Line 2 LCD

-17-
การใช้งาน EasyHID

for i = 0 to 15

LCDOUT

usbbuffer[i] next i

gosub

DoUSBO

ut goto

Program

Start

' * receive data from the USB bus *

DoUSBIn:

USBBufferCount = USBBufferSizeRX ' RXbuffersize

USBService 'keep connection alive

USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available

return

' * wait for USB interface to attach *

DoUSBOut:

USBBufferCount = USBBufferSizeTX ' TXbuffersize

USBService 'keep connection alive

USBOut 1, USBBuffer, USBBufferCount, DoUSBOut' if bus available,

transmit data return

■ After writing code, compile and program onto PIC18F4550.

-18-
การใช้งาน EasyHID

The next step is to develop a program in the Visual Basic language, following the basic
program that EasyHID created for you by opening the Visual Basic language code with the
VB6 program and then developing the program code as follows.

The picture shows the basic program code that EasyHID created to create a new form as
shown.

-19-
การใช้งาน EasyHID

■ Write a program (see full example from the example in the USB4550 LCD folder)

^ Projectl - Mai n Form (Code) ( ไ . ] f n ] f x ]

1 ]BT_ร«11(1 1 Click 1

A.
1
vendor and product IDs ““ Private Const VendorlD = 9999 Private Const ProductID =
1

1
read and write buffers
Private Const BufferlnSize = 16
Private Const BufferQutSize = 16
Dim Buffering To BufferlnSize) As Byte
Dim BufferOut[0 To BufferOutSize) As Byte

Private Sub BT Send Click() End Sub

-20-
การใช้งาน EasyHID
1 **************************************************************** 1
when
the form loads, connect to the HID controller - pass 1
the form window handle so that
you can receive notification 1
events...

1 *****************************************************************

Private Sub Form Load!)


1
do not remove!

■ Once the design is complete, try testing the program. You must connect the USB cable to
the ET-PIC USB/4550 board that has been programmed with the code previously.

Click T]

Dim str As String ■ *^


Dim i As Long Dim
DLCD As Byte Dim
lang As Integer

If lang > 0 Then bAnsi = Stri]

-21-
str = Textl.'
การใช้งาน EasyHID
lang = Len(st

BufferOut(0) = 0

hidWriteEx VendorlD, ProductID, BufferOut(0) End If End

For i = 0 To BufferOut

Next i

For i = LBoui DLCD =

bi BufferOut
Next

Sub
I ****************************************************************
1
when the form loads, connect to the HID controller - pass 1
the form window handle so that
you can receive notification 1
events...

Test sending message

.^ EasyHID Template X

Send Data to PICMicro for Display LCD

jWatcharin Kaorop Send

Return DATA from PICMicro to PC


jWatcharin Kaorop

1 ETT CO...LTD

■ When tested, it works. Then create an Exe File as shown in the


picture.

New Project Ctrl+N i |ร์7 Open Project... 1 เท o- F II ■


ctrl+o 1

-22-
การใช้งาน EasyHID
Add Project,,, Remove Project

12] Save Project Save Project As...


irm (Code)

Save FormMain.frm ctrl+s Save


FormMain. frm As...
. product IDs t
Save Selection ' Save Change Script VendorlD = 999 t
ProductID = 1

^ Print,,, ctrl+p 0 Print Setup... 1 ■ rite buffers t


BufferInSize = t
BufferOutSize .(อ To
Make USB4550_LCD. exe... t
Make Project Group., 1 ^ BufferlnSi
1- 1 ก Tn Fl 11-f-f p T- fill
1-

Try testing the created Exe File.

Name EJ FormMain
^mcHIDInterface %|
U5B4550_LCD 0
U5B4550J-CD 0
MSSCCPRJ
Ql

Size Type

10 KB Visual Basic Form File


5 KB Visual Basic Module

1 KB Visual Basic Project


1 KB Visual Basic Project 11

-23-
1 KB Microsoft SourceSaf.

การใช้งาน EasyHID
32 KB Application

.แร EasyHID Template

- Return DATA from PICMicro to PC

-24-

You might also like