17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Functional Overview<br />

USB<br />

Universal Serial Bus, or USB, is used as a method for peripheral devices to connect to and talk<br />

to a personal computer. <strong>CCS</strong> provides libraries for interfacing a PIC to PC using USB by using<br />

a PIC with an internal USB peripheral (like the PIC16C765 or the PIC18F4550 family) or by<br />

using any PIC with an external USB peripheral (the National USBN9603 family).<br />

Relevant Functions:<br />

usb_init()<br />

usb_init_cs()<br />

usb_task()<br />

Initializes the USB hardware. Will then wait in an infinite loop for the<br />

USB peripheral to be connected to bus (but that doesn't mean it has<br />

been enumerated by the PC). Will enable and use the USB interrupt.<br />

The same as usb_init(), but does not wait for the device to be<br />

connected to the bus. This is useful if your device is not bus powered<br />

and can operate without a USB connection.<br />

If you use connection sense, and the usb_init_cs() for initialization, then<br />

you must periodically call this function to keep an eye on the connection<br />

sense pin. When the PIC is connected to the BUS, this function will then<br />

perpare the USB peripheral. When the PIC is disconnected from the<br />

BUS, it will reset the USB stack and peripheral. Will enable and use the<br />

USB interrupt.<br />

Note: In your application you must define USB_CON_SENSE_PIN to the connection sense pin.<br />

usb_detach()<br />

usb_attach()<br />

usb_attached()<br />

usb_enumerated()<br />

Removes the PIC from the bus. Will be called automatically by<br />

usb_task() if connection is lost, but can be called manually by the user.<br />

Attaches the PIC to the bus. Will be called automatically by usb_task()<br />

if connection is made, but can be called manually by the user.<br />

If using connection sense pin (USB_CON_SENSE_PIN), returns TRUE<br />

if that pin is high. Else will always return TRUE.<br />

Returns TRUE if the device has been enumerated by the PC. If the<br />

device has been enumerated by the PC, that means it is in normal<br />

operation mode and you can send/receive packets.<br />

usb_put_packet Places the packet of data into the specified endpoint buffer. Returns<br />

(endpoint, data, len, tgl) TRUE if success, FALSE if the buffer is still full with the last packet.<br />

usb_puts<br />

(endpoint, data, len,<br />

timeout)<br />

Sends the following data to the specified endpoint. usb_puts() differs<br />

from usb_put_packet() in that it will send multi packet messages if the<br />

data will not fit into one packet.<br />

75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!