Help Needed in Connecting PIC to PC via USB
Currently i am doing my bachelor project.
the idea of the project is to control several devices and systems using PC, i will connect the PC to PIC using USB interface
i already found the circuit and connected it and also the pc (windows xp sp2) identified my circuit as Human Interface device(HID).
● The problem now how can i test this connection(how do i send and receive data between both terminals)?
● Which program language or platform can i use to have access to usb port in the PC?
--here is code that i downloaded to the PIC microcontroller
1-The interrupt part for keeping the connection alive by sending message every 3.3ms
2-When pic receives (P=??) it is expected to send to PC data on PORTC
When it receives (P=nT) it is expected to output n in PORTB
the idea of the project is to control several devices and systems using PC, i will connect the PC to PIC using USB interface
i already found the circuit and connected it and also the pc (windows xp sp2) identified my circuit as Human Interface device(HID).
● The problem now how can i test this connection(how do i send and receive data between both terminals)?
● Which program language or platform can i use to have access to usb port in the PC?
--here is code that i downloaded to the PIC microcontroller
1-The interrupt part for keeping the connection alive by sending message every 3.3ms
2-When pic receives (P=??) it is expected to send to PC data on PORTC
When it receives (P=nT) it is expected to output n in PORTB
#include "C:\Program Files\Mikroelektronika\mikroC\Examples\EasyPic4\extra_examples\HID-library\USBdsc.c" unsigned char Read_buffer[64]; unsigned char Write_buffer[64]; unsigned char num,x; // // Timer interrupt service routine // void interrupt() { HID_InterruptProc(); // Keep alive TMR0L = 100 ; // Re-load TMR0L INTCON.TMR0IF = 0 ; // Reload TMR0 } void main() { ADCON1 = 0xFF; // Set PORTB to digital I/O TRISB=0; // Set PORTB to outputs TRISD=0; TRISC=1; PORTD=0; PORTB = 0; // Clear all outputs INTCON=0; INTCON2=0xF5; INTCON3=0xC0; RCON.IPEN=0; PIE1=0; PIE2=0; PIR1=0; PIR2=0; // // Configure TIMER 0 for 3.3ms interrupts. Set prescaler to 256 // and load TMR0L to 100 so that the time interval for timer // interrupts at 48MHz is 256.(256-100).0.083 = 3.3ms // // The timer is in 8-bit mode by default // T0CON = 0x47; // Prescaler = 256 TMR0L = 100; // Timer count is 256-156 = 100 INTCON.TMR0IE = 1; // Enable T0IE T0CON.TMR0ON = 1; // Turn Timer 0 ON INTCON = 0xE0; // Enable interrupts // Enable USB port Hid_Enable(&Read_buffer, &Write_buffer); Delay_ms(2000); // Read from the USB port. Number of bytes read is in num for(;;) // do forever { if(Read_buffer[0]=='P' && Read_buffer[1]=='=' && Read_buffer[2]=='?' && Read_Buffer[3]=='?' ){ while(!Hid_Write(PORTC, 1)){ x = Hid_Write(PORTC, 1); } } // Read from the USB port. Number of bytes read is in num if(Read_buffer[0] == 'P' && Read_buffer[1] == '=' && Read_buffer[3] == 'T') { if(Read_buffer[2]=='1'){ PORTD=1; // opens gate } PORTB = Read_buffer[2]; } } Hid_Disable(); }
Replies
-
Harshad ItaliyaI think C language is good platform for this project
-
Harshad ItaliyaTake a look here for interfacing Circuit.
#-Link-Snipped-# -
mohit30goelmosh11Currently i am doing my bachelor project.
the idea of the project is to control several devices and systems using PC, i will connect the PC to PIC using USB interface
i already found the circuit and connected it and also the pc (windows xp sp2) identified my circuit as Human Interface device(HID).
● The problem now how can i test this connection(how do i send and receive data between both terminals)?
● Which program language or platform can i use to have access to usb port in the PC?
--here is code that i downloaded to the PIC microcontroller
1-The interrupt part for keeping the connection alive by sending message every 3.3ms
2-When pic receives (P=??) it is expected to send to PC data on PORTC
When it receives (P=nT) it is expected to output n in PORTB
#include "C:\Program Files\Mikroelektronika\mikroC\Examples\EasyPic4\extra_examples\HID-library\USBdsc.c" unsigned char Read_buffer[64]; unsigned char Write_buffer[64]; unsigned char num,x; // // Timer interrupt service routine // void interrupt() { HID_InterruptProc(); // Keep alive TMR0L = 100 ; // Re-load TMR0L INTCON.TMR0IF = 0 ; // Reload TMR0 } void main() { ADCON1 = 0xFF; // Set PORTB to digital I/O TRISB=0; // Set PORTB to outputs TRISD=0; TRISC=1; PORTD=0; PORTB = 0; // Clear all outputs INTCON=0; INTCON2=0xF5; INTCON3=0xC0; RCON.IPEN=0; PIE1=0; PIE2=0; PIR1=0; PIR2=0; // // Configure TIMER 0 for 3.3ms interrupts. Set prescaler to 256 // and load TMR0L to 100 so that the time interval for timer // interrupts at 48MHz is 256.(256-100).0.083 = 3.3ms // // The timer is in 8-bit mode by default // T0CON = 0x47; // Prescaler = 256 TMR0L = 100; // Timer count is 256-156 = 100 INTCON.TMR0IE = 1; // Enable T0IE T0CON.TMR0ON = 1; // Turn Timer 0 ON INTCON = 0xE0; // Enable interrupts // Enable USB port Hid_Enable(&Read_buffer, &Write_buffer); Delay_ms(2000); // Read from the USB port. Number of bytes read is in num for(;;) // do forever { if(Read_buffer[0]=='P' && Read_buffer[1]=='=' && Read_buffer[2]=='?' && Read_Buffer[3]=='?' ){ while(!Hid_Write(PORTC, 1)){ x = Hid_Write(PORTC, 1); } } // Read from the USB port. Number of bytes read is in num if(Read_buffer[0] == 'P' && Read_buffer[1] == '=' && Read_buffer[3] == 'T') { if(Read_buffer[2]=='1'){ PORTD=1; // opens gate } PORTB = Read_buffer[2]; } } Hid_Disable(); }
Its not a much bigger problem man....? u can test ur connections over making a locan lan panel b/w no. of computers u have..u can also try for the php server method .....that can also be beneficial 4 u??? -
debu@mosh11: Debu's Innovations: USB-101 should help you. It explains how to write both PC side and Device side USB code, meant for beginners.
Hope this helps,
Regards,
Debu 😀
You are reading an archived discussion.
Related Posts
Now a days there is good market of PIC(Microchip) controller as Student Projects..
(In Industry NXP and Freescale are Good!)
I was trying to learn PIC a long time ago...
Wishing our CEan - The Y Not a very happy and prosperous birthday
😁😁😁😁😁
May your dreams come true 😁
Please can some send me the code of this program:
A Bus company charges $1 for distance upto 10km. For any additional Km, a passenger is charged $0.2. These are...
If you're keeping track of Snow Leopard's progress, you'll be pleased to know that a new build (10A335) has been released into the hands of devs (and consequently, the world)....
Here i am going to Share Tutorials for the PIC
IntroductionWelcome to the start of the PIC Tutorial. These pages will take you form the basic structure of the device,...