Need 18f4550 usb I/O codes please (I'm going crazy)

Discussion in 'Embedded Systems and Microcontrollers' started by aykutcanturk, Jul 22, 2011.

  1. aykutcanturk

    Thread Starter New Member

    Jul 22, 2011
    Dear friends,
    I need pic application to communicate with pic18f4550 over usb and on/off all output ports and another one for reading all input ports. I can write pc application if I can understand howto set output pins and howto read input pins. I'm software developer but I'm not pic nor C export. I'll use that for my hobby cnc machine, start/stop relays, engines. It should be very simple but I'm lost in documentations and samples almost for one month.

    Every sample is piece by piece and it looks like everyone knows that pic stuff very well.what I need it is: "upload that file to pic and communicate like this". anyone have sample code for setting and reading 4550's 32 pins from old times ? I have ql200 development board but its obvious now that I wont learn that pic stuff without "complete working sample".

    please my friend, help me. Maybe I learned so many thing about pics but I cannot put them together without a working sample.

  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Now wouldn't it be nice if Microchip provided a nice general purpose demo program of how to talk to a PIC18f4550 over the USB, to be able to send it information and receive it back. It would be even better if this demo did not need any special drivers in Windows.

    Oh wait, they do. It is located in the latest Microchip Application Library (MAL) down at: C:\Microchip Solutions v2011-06-02\USB\Device - CDC - Serial Emulator\Firmware\USB Device - CDC - Serial Emulator - C18 - PICDEM FSUSB.mcw

    (Wow, no wonder you couldn't find it!)

    This demo program is basically a USB to RS232 converter. Data stream in over the USB and is send out on the RS2323 Tx. Anything the 232 sees on the Rx gets sent back to the PC on the USB. It is quite useful since you can cut out the RS232 stuff and use it to get data to and from your app, which here is just banging the port pins.

    While there is a HUGE amount of code in that project believe it or not (OK, you better believe it or I will hunt you down) you can ignore the vast majority of this code. All you are concerned with is 4 routines:

    int main(void) which is where most of these live

    InitializeSystem() which calls void UserInit(void)

    ProcessIO(); This does most of the work in the app, getting data from the USB and sending it to the RS232, and vice versa. Here you can redirect that to direct data in to the ports.

    void UserInit(void) will be doing a bunch of things you don't want so you'll replace most of this too.

    On the windows side the driver is already there for this, as it is a communications device class (CDC) device. MC provides the ini file for the first time install. To talk to it you address it as you would any serial port, meaning Hyperterminal is all you need. VB, VC, Delphi, and most any windows programming language have the widget to access serial ports.

    Offhand I don't know of a prebuilt tested board that has this chip, but that is they are quite simple to build (and I've built several of these). You just need the PIC, a couple of caps, a resonator, a USB B type connector (or hack the end off a cable), and a breadboard. I actually just use the $3 Radio Shack breadboards. I also add a 6 pin strip for a programmer.

    Right, programmer! Any will do, PicKit 2 or 3 are cheapest and will let you do in circuit debugging. ICD3 is nice for more $$$ but you need a different (harder to hand wire too) connector (not a pin strip).
  3. be80be

    Distinguished Member

    Jul 5, 2008
    There even better ones if you dig in that 500m byte download

    the beast place to start is here

    PICDEM Full Speed USB

    $59 and some change here


    Don't need a programmer with this it's built in

    Last edited: Jul 22, 2011