SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » PIC18F USB development




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Expanding on the PIC18F4550 USB HID Device Project
 Post Posted: Fri Feb 18, 2011 4:31 am 
Offline

Joined: Fri Feb 18, 2011 4:13 am
Posts: 1
Hello Simon and fellow USB device creators,

Simon first of all thanks for all of your hard work and getting your stuff on here for us all to benefit. Simon, I am working on a project whereby I want to have five inputs control five outputs using the PIC18F4550. So if there is a 1 on RA0, I want the output at RB0 to be a 1. I am familiar with C and I think I have my code correct here: I just inserted my piece of code in place of everything you had in the 'process input & output' section like so:
Code:
   
// Process input and output
void ProcessIO(void)
{   
    // If we are not in the configured state just return
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
   
   // We support the following commands:
   //
   // 0x80 Toggle the LED
   // 0x81 Read the push-switch status
   // 0x82 Read the LED status

   //Check if data was received from the host.

if(!HIDRxHandleBusy(USBOutHandle))
    {   
       
                        if (RA0 == 1)
                          RB0 = 1;

        // Re-arm the OUT endpoint for the next packet
        USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
    } 
}
#endif

And so I just have a switch at RA0 and when I push it I want RB0 to go "high". Well I am not getting a high on RB0 with just the USB device plugged in, and by the way, the device is recognized by my computer. My question is, do I need to run a program like your WFF HID demo application in order to get a 1 on RB0 when a push RA0 swtich? Or could I just plug it in and push the button to get my output, assuming the code is correct?
Thanks in advance for your time. And thanks to anyone else who may assist me with this.

-Joe


Top 
 Profile  
 
 Post subject: Re: Expanding on the PIC18F4550 USB HID Device Project
 Post Posted: Fri Feb 18, 2011 6:59 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 893
Hi

The statement:

if(!HIDRxHandleBusy(USBOutHandle))

is only true if there is USB data waiting to be sent back to the host (in response to a command generated by the host). So unless you have processed a USB command your code will not be called (and therefore you will never see a 1 on RB0).

Since your function of checking RA0 and setting RB0 has nothing to do with a USB action it should really be in the main polling loop rather than in the function which processes USB actions. That way it will be run every poll.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 2 posts ] 

Board index » Electronics Projects » PIC18F USB development


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Translated by MaĆ«l Soucaze © 2009 phpBB.fr