Книга: Advanced PIC Microcontroller Projects in C
8.6 mikroC Language USB Bus Library Functions
8.6 mikroC Language USB Bus Library Functions
The mikroC language supports a number of functions for USB HID-type communications. Each project based on the USB library should include a descriptor source file which contains vendor ID and name, product ID and name, report length, and other relevant information. To create a descriptor source file we can use mikroC’s integrated USB HID terminal tool (see Tools?HID Terminal). The default name for descriptor file is USBdsc.c, but it can be renamed if required. The USBdsc.c file must be included in USB-based projects either via the mikroC IDE tool, or as an #include option in the program source file.
The mikroC language supports the following USB bus library functions when a PIC microcontroller with built-in USB is used (e.g., PIC18F4550), and port pins RC4 and RC5 are connected to the D+ and D– pins of the USB connector respectively:
Hid_Enable: This function enables USB communication and requires two arguments: the read-buffer address and the write-buffer address. It must be called before any other functions of the USB library, and it returns no data.
Hid_Read: This function receives data from the USB bus and stores it in the receive-buffer. It has no arguments but returns the number of characters received.
Hid_Write: This function sends data from the write-buffer to the USB bus. The name of the buffer (the same buffer used in the initialization) and the length of the data to be sent must be specified as arguments to the function. The function does not return any data.
Hid_Disable: This function disables the USB data transfer. It has no arguments and returns no data.
The USB interface of a PIC18F4550 microcontroller is shown in Figure 8.9. As the figure shows, the interface is very simple. In addition to the power supply and ground pins, it requires just two pins to be connected to the USB connector. The microcontroller receives power from the USB port.
Figure 8.9: PIC18F4550 USB interface
- 8.1 Speed Identification on the Bus
- 8.2 USB States
- 8.3 USB Bus Communication
- 8.4 Descriptors
- 8.5 PIC18 Microcontroller USB Bus Interface
- 8.6 mikroC Language USB Bus Library Functions
- PROJECT 8.1 — USB-Based Microcontroller Output Port
- PROJECT 8.2 — USB-Based Microcontroller Input/Output
- PROJECT 8.3 — USB-Based Ambient Pressure Display on the PC
- Как переносить данные через USB-брелок («флэшку»)?
- Наносится ли какой-нибудь вред USB-брелоку, когда его извлекают из разъема без использования функции безопасного отключе...
- CHAPTER 4 Functions and Libraries in mikroC
- 4.3.7 Miscellaneous Library
- 4.3.6 ANSI C Library
- 6.1 Program Description Language (PDL)
- 11.1.3. Шина SMBus
- Установка устройств с интерфейсом USB
- Procedural Languages and Triggers
- Assembly language, the second generation language
- Using USB and Legacy Printers
- USB 3.0