CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Converting serial to parallel
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Elie777



Joined: 30 Dec 2010
Posts: 16

View user's profile Send private message MSN Messenger

Converting serial to parallel
PostPosted: Tue Jan 04, 2011 3:33 am     Reply with quote

I am going to use a usb to serial cable. I need my pic 16f84 to give an output of 5 bits which will be the input for an encoder.

Can some help me know what components I need and how to write the code to convert from serial to parallel.

10x for any help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 5:34 am     Reply with quote

Read the manual on GETC.
If the PIC is to do anything 'more' than just read serial, and output it on a port, you would be much better off with a different chip, with a UART.
Minimum needed:

Reliable 5v supply.
Crystal or ceramic resonator, giving a stable frequency.
Pull up resistor on MCLR.
Resistor and trap diode from the TXD line on the USD module, feeding to a pin on the PIC.
A #use RS232 line, specifying this pin, the baud rate you want to use, and the 'INVERT' option (must be used, unless you add a proper RS232 buffer).
Getc the character, and write the value to a port.

However if the PIC has to do anything 'more' (reply to the PC for example), then you really need to find a PIC with a UART, and add a RS232 level translator (MAX232 for example).

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 6:27 am     Reply with quote

I guess, using an USB-to-parallel adapter (FT245 or FT2232) with respective FTDI software driver would be an easier way. Or an USB PIC to interface to USB directly.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 6:39 am     Reply with quote

Ttelmah has most of the details for you,though your project description is a bit vague. Will the PIC read the encoder and transmit the data to the PC, or does the PIC get data from the PC and do 'something with it?
I built several serial to parallel 'boxes' using the PIC 16F84 to allow parallel printers to be used on serial ports, since serial ported printers can't be found anymore.
Ttelmah, is right, that if you choose a newer PIC, it'll be easier and nicer! One with a built in clock and UART (16F628,648 ?? I think) works very well and easy on the wallet.
The hardest part will be the USB-Serial 'box', be sure to test it using a loopback connector very well. Some do NOT always work correctly!.
Elie777



Joined: 30 Dec 2010
Posts: 16

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 05, 2011 4:36 am     Reply with quote

10x for your replies. I just need to take data from the pc and use it.

FvM I searched a lot for a usb to parallel adapter but I couldn't find one.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Jan 05, 2011 4:48 am     Reply with quote

The units FVM mentions, are USB to serial adapters, _with a parallel output option as well_. Designed for 'embedded' applications. Hence will not be found if you search for 'USB to parallel', but sound as if they would do what you want.

Best Wishes
Elie777



Joined: 30 Dec 2010
Posts: 16

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 05, 2011 5:16 am     Reply with quote

Ttelmah can u help me to write my code because I'm trying to learn programming on my own and I don't have enough time because I have to present the project after 2 days. I'm finding a lot of difficulty writing this code.

10x for any help.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 05, 2011 7:27 am     Reply with quote

As a general rule, everyone here will help you IF you show effort in 'cutting your own code' and ask why this or that doesn't work right.
To expect anyone to do your homework is not appropriate. Your 'project' is NOT a 2 day event! First you have to design and develop a PC based solution to talk to the PIC. Depending on the PC platform that could be a simple 'terminal' program, either canned or homemade. Then there's that USB interface. Another HUGE task unless you're lucky to have code that works for your USB device.Wiring to the PIC can be fun...as all USB devices don't work like others..oh yeah don't forget about the RS-232 chips!
The PIC program could be the easiest part of your task. After spending a week or so to get the 'Hello World' working, you can progress to the 'serial to parallel' program. It's quite easy to do ONCE you've read and re-read the CCS C manual a few times and cut maybe 20-30 versions of the program. Be sure to use resistors for the LEDS or you'll burnout the PIC !
You are very fortunate to have tools available that make this homework easy. One is called the Internet, the other Google.There are thousands of examples of your homework already out 'there' so it's really easy to copy someone else's efforts.
None of those 'tools' existed 40 years ago when I taught myself PDP-11 asm, Z-80 asm, BASIC, COBOL, FORTRAN, 68HC11 asm, 1802 asm the list goes on and on. I've spent 10s of thousands of hours soldering, wirewrapping, keying in programs, flowcharting, reading, reading, reading.....
You learn best by doing and that will take TIME but you'll be smarter and enjoy YOUR accomplishments.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Jan 05, 2011 11:03 pm     Reply with quote

Elie777 wrote:
10x for your replies. I just need to take data from the pc and use it.

FvM I searched a lot for a usb to parallel adapter but I couldn't find one.


you're joking, right?

I type "usb to parallel" on google and get a zillion results. (Well, more like 2,290,000!! -- but it's close!)

any of those would work just fine and you could DUMP stuff right out LPTx: !!!

how awesome is that? Just latch and go!

You know, they used to make parallel port based mass storage devices/adapters! (ZIP Drives from IOMega)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jan 06, 2011 1:58 am     Reply with quote

Quote:
I searched a lot for a usb to parallel adapter but I couldn't find one

You may want to try usb-to-parallel FT245 at google.com

I mentioned the chips (FT245 is a dedicated parallel interface and FT2232 a multi-purpose serial and parallel interface), because I've used them for similar applications, and they are actually present in a huge number of products. As already mentioned in my post, FTDI has software drivers, that allow an easy access to individual pins from Windows and Linux OS. You can get ready-to-use modules that expose the pins and an USB connector.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Jan 06, 2011 3:35 am     Reply with quote

The problem with usb to parallel units in general, is that they emulate a centronics printer port, so many require an 'ack' from the printer (easy to bodge this though....). Also though potentially you could just 'print' a bit pattern to appear on the port, some software won't sent a 'line' till the EOL character is seen. Again easy to avoid provided you sent the data yourself, but a serial-parallel approach, is possibly a fraction 'easier' for the inexperienced. The FT2232, is particularly easy to use, doing exactly what was originally described, allowing you to send a character on the PC, to what it 'sees' as a serial port, and then presenting this data in parallel.
There are so many solutions to this, that it is almost 'infinite'. Could do it in hardware without a processor (shift register on a serial connection), software (18F2550), dedicated chip (FT2232), PGA, etc. etc.. It'd possibly be quite 'fun' to work out how many possible solutions there are. I'd suspect several hundred, all with fundamental differences...

Best Wishes
Elie777



Joined: 30 Dec 2010
Posts: 16

View user's profile Send private message MSN Messenger

PostPosted: Thu Jan 06, 2011 7:22 am     Reply with quote

Can I find in the market a usb to parallel adapter that will be recognized by the pc( lab view) as a parallel port where I can control each pin?

I asked in many computer stores and they told me I can't find usb to parallel. I can only find usb to serial.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jan 06, 2011 8:08 am     Reply with quote

Elie777 wrote:
Can I find in the market a usb to parallel adapter that will be recognized by the pc( lab view) as a parallel port where I can control each pin?

I asked in many computer stores and they told me I can't find usb to parallel. I can only find usb to serial.


I think your problem is going to be how "lab view" accesses the paralell port. Lab View directly accesses the port via the port addresses for LPT1 (0x3BC to 0x3BF) and IRQ 2. i don't know exactly how it does this but in order to do what you want you will need a virtual driver for the PC which emulates a paralell port at this address and controls the relevant hardware.

We have run in to a similar problem with trying to use a PCIE and PCI paralell port on a PC using Lab View. If you read the Lab View info it specifically says the paralell port has to be at LPT1 addresses.

Unless they have changed Lab View or you can find a virtual driver then this is not normally possible without a built in paralell port or ISA card. And as most PC motherboards appear not to come with paralell ports or ISA slots you have this problem.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 06, 2011 8:25 am     Reply with quote

Accessing the parallel port is dependent on the OS. Any PC using Win98SE or older allows direct(register) access to ports..

XP pro can have direct access if your program gets into Ring0(needed for true realtime stuff)

Don't know about other versions as I only use those two OS.

I'm still unclear as to the OP statement 'I need my pic 16f84 to give an
output of 5 bits which will be the input for an encoder', as no reference to what encoder he's using or what the overall picture is.It's gotten 'muddied' through the replies...
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jan 06, 2011 8:40 am     Reply with quote

temtronic wrote:
Accessing the parallel port is dependent on the OS. Any PC using Win98SE or older allows direct(register) access to ports..


Only true if you use a driver for the OS you are running. if you access the hardware directly using the hardware addresses then you are bypassing the OS. I believe this is what Lab View does. Considering Lab view was probably around in the days of Dos/Windows 3.1 etc. I expect this method has never changed.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group