Saturday, January 24, 2015

Usb Communication With PIC Microcontroller [step by step tutorial]



usb connection with pic microcontroller
mikroc usb tutorial

USB communication is better than serial communication. Hardware interfacing is very easier than Rs 232 . In USB 1.0 communication  Low Speed is-1.5Mbit/second  & High Speed is -12Mbit/second . The upgrade version provides more speed than older version. USB-3.0  has higher speed, 5Gbit/second and it's called super speed. For more information you can visit this page >>  Wikipedia Usb.

In this tutorial I will use pic18f2550 microcontroller & it is very popular for usb. Now you can ask a question, how do we get our MCU to work with high speed or low seed ?
At 6MHz clock we will get low speed and at 48MHz Clock we will get High speed. In this tutorial we will try to make higher speed connection. We are not going to use 48MHz clock, because it is very noisy. We will try another technique instead of it. Microchip company provides internal PLL( Phase Locked Loop ) circuit  in some of specific  products and  pic18f2550 has internal PLL Circuit. Now look at the picture :

Phase Locked Loop Cuit
PLL Circuit
The PLL circuit  converts 4MHz clock to 48MHz clock. So, we need 4MHz clock. We have to divide the clock in such way so that we can get  result 4MHz. Look at here, If we use 20MHz divide it by 5 and we get 4. Example : (20/5)=4 ,(12/3)=4. We have to define this in the  source code.

Now let's create a project in Proteus 8.

Proteus 8 Circuit :

Step 1:
How to Create Project in Proteus 8
How to Create Project in Proteus _1
Step 2:
How to Create Project in Proteus 8
How to Create Project in Proteus 8_2

Step3 :
How to Create Project in Proteus 8_3
How to Create Project in Proteus 8_3

 Step 4:
Usb Communication With PIC Microcontroller [step by step tutorial]


Step 5:
How to find parts in Proteus 8
How to find parts in Proteus 8
 Step 6:
How to find parts in Proteus 8_3
How to find parts in Proteus 8
Step 7:

usb interfacing with pic microcontroller Circuit
Usb  Interfacing With PIC Microcontroller Circuit

Now let's create a project in MikroC.

MikroC Code :

Step 1:
Create New Project in MikroC_1
Create New Project in MikroC_1
Step 2:
Create New Project in MikroC_2
Create New Project in MikroC_2
Step 3:
Create New Project in MikroC_3
Create New Project in MikroC_3
Step 4:
 Include All Library in mikroc
Include All Library
Step 5:
Editing MikroC project
Editing MikroC project settings_1
Step 6:
USB Communication With PIC Microcontroller
USB Communication With PIC Microcontroller


1. As we know PLL circuit takes input 4MHz clock. So we have to divide 12MHz by 3 so that we can get 4MHz clock. If we use 4MHz we have no need  this part .
2 & 3 . We are using USB 1.0 and it's High Speed clock 48MHz. So we have to devide it by 2.

4 . Here we are using 12MHz Crystal clock and the oscillator selection should be HS Oscillator.          

5 . We have to enable voltage regulator. Basically it is an internal  3.3 voltage regulator of pic18f2550. If we enable this, it is required to connect vusb pin with a 220 nf capacitor.

#Source Code :

 

unsigned char receivedata[64] absolute 0x500;  //  <--Variable Declaration  
 unsigned char senddata[64] absolute 0x580;  
 int i=0;  
 void Interrupt(){  
 USB_Interrupt_Proc();    //<--Interrupt function  
 }  
 void main()   //<--The Main Function  
 {  
 HID_Enable(&receivedata,&senddata);  //<--To Enable HID  
 while(1){             //<-- Infinity LOOP  
 while(!HID_Read());   //<--for reading  
 for(i=0;i<64;i++){  
 senddata[i]=receivedata[i];   //<--Sending received data to senddata[i] variable  
 }  
 while(!HID_Write(&senddata,64)); //<--for writting  
 }  
 }  
 

1. unsigned char receivedata[64] absolute 0x500;

    unsigned char senddata[64] absolute 0x580;


Here we have created character type two array variable senddata & receivedata. During USB Communication we must have to keep all data in USB RAM. PIC 18F2550 microcontroller's USB RAM memory address begins with 0x500 and ends with 0x7F. That's why, we kept the receivedata[64]  in 0x500 location and senddata[64] in 0x580.
2. 

void Interrupt(){


USB_Interrupt_Proc();}


void Interrupt() is one user defined function which contains USB_Interrupt_Proc()  function inside . Interrupt means restriction for something. When  interrupt is enabled, microcontrller doesn't perform main function. It will perform only interrupt function or ISR(interrupt service routine). After clearing the flag main method works.

3. HID_Enable(&receivedata,&senddata); 

This function will initialize USB. It locates receivedata variable and  send data variable.

Note : HID means "Human Interface Device"

4. char HID_Read();

This function receives data. If receiving is failed, it returns 0. Otherwise it returns character .

while(!HID_Read());

It means, this function tries to receive data until  data are being received .

char HID_Write();


This function receive data. If receiving is failed, it returns 0. Otherwise it returns the numbers of data .while(!HID_Write());


 It means, this function tries to send data until  data are being sent. 

5.for(i=0;i<64;i++>

senddata[i]=receivedata[i];    

}

This loop will run from 0 to 63 and will keeps the received data to senddata variable from receivedata variable.  

  #Descriptor File Addition

Descriptor File : This file will make your pc understand about device's informations. Like
Manufacture Name, Product ID, Vendor ID  etc.
Now i will show you. How to create a Descriptor file .



Step 7:
Create Descriptor FIle_1
Create Descriptor File_1
Step 8:
Create Descriptor FIle_2
Create Descriptor FIle_2
Step 9:
Adding descriptor file with MikroC Project .
Adding Descriptor File
Adding Descriptor File
Step 10:
Step 11:

Usb Communication With PIC Microcontroller [step by step tutorial]
Step 12:
usb interfacing with pic microcontroller
How to upload hex file in proteus_1
Step 13:
How to upload hex file in proteus
How to upload hex file in proteus_2
Step 14:
How to upload hex file in proteus
How to upload hex file in proteus_3
Step 15:
In proteus Simulation we need to install virtual usb .
How to install Virtual USB in proteus
Install Virtual USB in proteus
Step 16:
Run Proteus Project
Run Project

Now go to the Proteus Circuit and Just Run the project .

Output:

Now go to the Tool >>HID Terminal >> click on Terminal .
HID Terminal of MikroC
HID Terminal of MikroC
HID Terminal of MikroC
HID Terminal Output




                                          Thank You!                                                           

31 comments:

  1. Thanks Man I Found This Post Really Useful...

    ReplyDelete
  2. Your download links are dead... Please advise ...

    ReplyDelete
    Replies
    1. I'm sorry. Just follow the tutorial and the video also. Code is given there. That's all I could say.

      Delete
  3. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! phone accessories

    ReplyDelete
  4. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again. best office chair for software developers

    ReplyDelete
  5. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. etcher

    ReplyDelete
  6. Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. etcher.download

    ReplyDelete
  7. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. agentie de comunicare

    ReplyDelete
  8. Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also usb cable

    ReplyDelete
  9. This is a good post. This post gives truly quality information. I’m definitely going to look into it.. communication with customers

    ReplyDelete
  10. This blog is so stunningly outstanding. Left its readers in the awe.
    to_pydatetime

    ReplyDelete
  11. I think this is an informative post and it is very useful and knowledgeable. Really its Great Article. Keep it up. Here is a complete of web and mobile app development services Read here and know all the famous Software Development services.

    Hire woocommerce Developer

    ReplyDelete
  12. There are not many preferable sentiments over when somebody sees you utilizing a program you lashed together to make your life more straightforward and says that it looks truly valuable. https://hostinglelo.in/

    ReplyDelete
  13. San Diego State University is intently attached to its local area inside as a program director and asset producing power just as remotely being a steward for expansive local area improvement and interest in the neighborhood climate.https://onohosting.com/

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. For instance, the code 99213 is utilized to address a commonplace office visit. At the point when the coder incorporates the code 99213 on the case, it tells the insurance agency that the clinical supplier played out a mid-range office visit. https://sites.google.com/view/seoservicesindelhiindia

    ReplyDelete
  16. I remember my school days back in 1995 when the peoples were using flopy disc and dvd use for data storage purpsoe but now we have universal serial bus (USB) I we can storga very large amount of data in it. As i work for the online Thesis help services I alos used USB for the writing work and it contain more then 100 Gaga bytes(GB) data

    ReplyDelete
  17. Many around the world admire Russian women for different reasons. Their supermodel-like beauty alone is enough to get people’s attention.

    ReplyDelete
  18. Hosting built to Boost WordPress websites. With Managed WordPress hosting you get powerful tools and a smart-design Website Builder for easy, quick website creation

    ReplyDelete
  19. Fully managed Cheapest WordPress Hosting india with no restrictions. Free Migration, CDN, Staging Sites.

    ReplyDelete
  20. I have been impressed after reading this because of some quality work and informative thoughts. I just want to say thanks to the writer and wish you all the best for coming! Update your old version of the NBA 2K21 game to NBA 2K22 by unlocking the East or West Season Tip pack, 500 MTP, or 1 Token these packs by using NBA 2k locker code .

    ReplyDelete
  21. Thank you for the good work. Have you been aware for the Ryzen 7 3700X, If yes then you can read one article Latest motherboard This new-age processor is ideally introduced for the gaming and rendering process and gives neck-to-neck competition to Intel.

    ReplyDelete
  22. Outstanding article! I want people to know just how good this information is in your article. Your views are much like my own concerning this subject. I will visit daily your blog because I know. It may be very beneficial for me. https://movieswood.today

    ReplyDelete
  23. What a sensational blog! This blog is too much amazing in all aspects. Especially, it looks awesome and the content available on it is utmost qualitative. https://afilmywap.world

    ReplyDelete
  24. Penis duration is a touchy trouble, and approximately 30% of men are upset with it. It is able to make you self-conscious and make you experience the need for a few form of penis increase method. Observe records about 성기확대 here, for additonal facts.

    ReplyDelete
  25. Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing...
    net software development

    ReplyDelete
  26. USA communication or pic microcontroller its very useful now days in online service. Thanks for sharing this article. Now it's time to avail 1 litre water bottle for more information.

    ReplyDelete

Ain't getting any visitors!
Please Share and Bookmark posts.

Tags

: (1) 18F2550 (1) 36KHz (3) and (1) arduino (1) Based (1) battery (1) Bipolar (1) Blinking (1) blinks (1) Bluetooth (1) bluetooth device interfacing (1) bluetooth module (1) button (1) circuit (1) clock (1) control (1) crystal oscillator (3) Db9 (1) DC Motor (2) digital (2) Digital Voting Machine (1) digital voting machine using pic (1) display (2) DS1307 (1) electronic (1) embedded c programming tutorial (11) embedded c tutorial (11) experiment kit (4) external interrupt (4) flash (1) flashing (1) Gas Leakage detector (1) HC-06 (1) home (1) how (1) How to (10) i2c tutorial (1) in (1) indicator (1) infrared Connection (3) interface (8) interfacing (3) Interrupt (3) Introduction (1) IR Connection (3) IR Receiver (4) IR Transmitter (4) key pad (1) keyboard (1) keypad (1) lavel (1) Lcd 16x2 (2) lcd 2x16 (2) led (1) lm35 (2) LPG (1) machine (1) make (1) Make bootloader (1) making (1) matrix (1) max232 (1) membrane keyboard (2) meter (2) Micocontroller (1) microchip (4) microchip pic (2) microchips (3) microcontroller (9) microcontroller based (3) microcontroller programming (3) Microcontroller Project (4) Microcontroller Projects (1) microcontroller_project (2) microcontrollers (4) Microprocessor (2) mikroC (5) mikroc code to start and stopstart and stop dc motor (1) mikroc pro for pic (2) Motion detector (1) MQ-9 Gas Sensor (1) musical (1) NEC Protocol (4) pcb (5) PIC (3) pic controller (11) pic microcontroller (11) pic microcontroller tutorial (11) pic programming (1) pic programming in c (12) pic proteus (1) Pic Tutorial (12) pic18 (2) pic18f2550 (11) picmicrocontroller (4) picRFモジュール (1) PIR Motion Sensor (1) printed circuit board (1) proteus (6) pulse width modulation (1) push (1) push button (1) PWM (1) real (1) rf transmitter (3) Rs 232 (1) Rs232 (1) scroll (1) scrolling (1) Serial communication (1) Serial Connection (1) Serial Port (1) serial port rs232 (1) Servo Motembedded c programming tutorial (1) simulation (2) Soil Moisture Meter (1) speed control (1) step by step (7) step bystep (1) Stepper Motor (2) text (2) Thief Detector (1) time (1) timer (4) timer0 (4) tone (1) TSOP38236 Receiver (4) tutorial (2) Unipolar (1) USART Connection (1) USB (1) usb 1.0 (1) USB bootloadere (1) USB HID (1) using (9) voltmeter (1) voting (1) water level indicator (3) with (2) work (1)

Traffic Feed


Live Traffic Feed
Visitor Tracking

Leave Your Message Here

Name

Email *

Message *

Like on Facebook