How to make USB communication with microcontrollers and its details.

I will try, as much as I know what to share. I hope those newcomers will be able to successfully communicate with microcontrollers via USB communication. I’ll try as much as possible. Please forgive me if I have something wrong.
I think USB serial communication is very good. Because there is no problem with interfacing, as much as RS232 Serial. Speed and much better.USB 1.0 Low Speed-1.5Mbit / second & High Speed -12Mbit / second. This will increase the speed of the USB version, the speed increases. USB5.0 speed 5Gbit / second It’s called SuperSpeed. If you would like more details, please visit Wikipedia’s link.
Anyway, come back to the original words. We support the USB 1.0 that Mikrocontroller will use. Now you can ask questions about when High Speed and when Low Speed When the clock is 6MHz then there will be Low Speed and Clock when 48 MHz will be High Speed .. We will try to communicate at High Speed. But the Clock pulse of 48 MHz is fairly noisy and is more expensive. So we will use the PIC 18f2550 Microcontroller to overcome this problem. Because Microchip companies provide some of their series within the microcontroller, the internal PLL circuit, and PIC 18f2550 microcontroller’s internal internal PLL circuit.
PLL means Phase Locked Loop PLL circuits convert 4MHz clocks to 48MHz clock. So we’ll use that Crystal E to divide it into 4MHz. That means if 12MHz, then 12/3 = 4 MHz. Again if it is 20MHz, then 20/5 = 4 MHz. Because PLL circuits convert 4MHz clocks to 48MHz clock, which is to define during coding.
Phase Locked Loop:
#Creating Source Code by MikroC:
Now open MikroC, click on New Project. You will see the following.
After that, notice the picture below.
1 -> We know PLL circuit only takes 4MHz clock input. So the crystal will divide 12MHz by 3, which will then be converted to 96MHz. If the crystal is 4MHz, then do not take anything.
2 & 3 -> We’re using USB 1.0 and High Speed is at 48MHz. So we have to divide 96 MHz by 2.
4 -> Since using 12MHz Crystal Oscillator, so for the Oscillrtor Selection, select HS Oscillator (HS).
5 -> To make USB communication with PIC microcontrollers, you must enable the Voltage Regulator. This is actually the 3.3 voltage regulator inside the PIC microcontroller. And if it is enabled, the capacitor of 220 nf in the microcontroller vusb pin will be added, you will see the circuit diagram.
Source Code Here:
Unsigned char received [64] absolute 0x500; Unsigned char senddata [64] absolute 0x580;
Int i = 0;
Void Interrupt () {
USB_Interrupt_Proc ();
}
Void main ()
{
HID_Enable (& received, & senddata); While (1) { While (! HID_Read ()); For (i = 0; i <64; i ++) {
Senddata [i] = receivedata [i];
}
While (! HID_Write (& senddata, 64)); 0x7FF]. So the receivedata [64] has been kept in 0x500 of USB RAM, then placed the sendata for the received, and the senddata with the gate 0x580.
2. void Interrupt () {
USB_Interrupt_Proc ();}
Void Interrupt () is a User Define function, which has USB_Interrupt_Proc () inside. Interrupt means to prevent something. The function of this function is to turn the USB connection on or off. When USB_Interrupt_Proc () is enabled, Connection will be OFF and will be on DBBL.
3. HID_Enable (& received, & senddata);
The function of this function is to enable USB 1.0. Which will retrieve the received data on the receivedata and send the senddata data, via USB.
** Note: HID means “Human Interface Device”
4. char HID_Read ();
This function receives the data. Returns 0 if return receives fail, and if not return the character.
While (! HID_Read ());
This means that, continuing to receive the data as long as the data has not been received.
Char HID_Write ();
This function returns data. Returning 0 returns if failing, and if not, returns the number of data that has been sent.
While (! HID_Read ());
This means that continuing the data shedding is as long as the data is not sent.
5. for (i = 0; i <64; i ++) {
Senddata [i] = receivedata [i]; }
This for loop will rotate 0 to 63 times, and the data we receive will send it back to the host, enter the senddata.
Descriptor File Addition Now
Descriptor File: This file will bear the identity of your Microcontroller. The main thing is that this file is your device’s
Manufacture will carry the Product ID, Vendor ID, and introduce the device to the PC.
Let’s show you how to create Descriptor File.