C code to read TTL levels

Without going into too much unnecessary information here is my problem.  I have a circuit on a helicopter that i am trying hack into for an electronics project.  Specifically one PIC that i am interested in deals with the command signals to the motors, and i need to read this data to evaluate and decode.  A good way of doing this, or so i'm told, is to simply connect the PIC to a serial input and read the TTL levels, (which are 0V - 5V).  I need a program that will read these levels and convert them to a useable format (1's and 0's) and have been trying to find something on the web, can anyone help?
Who is Participating?
Jay_HarbathConnect With a Mentor Commented:
The hardware way to do this is to use a logic analyzer that clips onto the PIC package and monitors and records all the PIC I/O   Unfortunately that will result in a huge data log of square waves.  You then have to figure out enough of the schematic to understand which control outputs from the PIC are going to the motor control circuitry and which inputs to the PIC come from motor feedback circuitry.  Once you know which pin does what, then you get the exhaustive and exhausting process of trying to determine what algorithm the PIC programmer used to read the inputs and control the outputs.  A nasty, dirty, mind numbing job to say the least.  

The software way would be to remove the PIC from the board, put it into a PIC programmer and attempt to read out the hexadecimal machine code.  This assumes that that particular chip does not have some sort of program security feature that prevents someone (like you) from reading out the program after the chip has been programmed.  Many microcontroller manufacturers have hardware program protection features that can be set after a chip has been programmed and verified.  I use them all the time.  Now, given that the company programming the PIC did not use any sort of program protection, all you will get is a hex file of the contents of the program memory.  You then need a disassembler that can convert the machine code into very, very raw assembly language.  You still need to understand the schematic with this approach, because you will have to understand which control outputs from the PIC are going to the motor control circuitry and which inputs to the PIC come from motor feedback circuitry.  With this information, you can start trying to understand the raw assembly language program and start guessing at variable names for memory locations and I/O pin assignments.  After extremely long hours (days, months) of effort, you might come up with some semblance of a commented assembly language program with a glimmering of the algorithm the original engineer used.  Mind you, this will only be an assembly language equivalent.  It is very likely that the engineer programmed most if not all of the application in C, but no disassembler in the world can go from machine code to C.  Considering how C compilers optimize, you won’t even find one that can convert assembly language back into C.  

To do what it sounds like you want to do will take thousands of dollars of equipment (logic analyzers or PIC programmers) and months of very hard work and lots of knowledge of electronics.  Reverse engineering embedded control applications takes courage, perseverance, and stupidity to make the attempt, strong motivation and very, very deep pockets.  
George TokasCommented:
PIC is a microcontroler.
That means there is a software inside it to perform some actions.
If you take my advice as electronic engineer also, don't try to hack it.
If it is not protected (I mean at programming phase) then you can get the code from inside the PIC and with dissasembly you can see the program and modify it yourself.

StupotAuthor Commented:
That would be ideal, but unfortunately the helicopter is fairly revolutionary in its design and the manufacturers have gone to some lengths to ensure that it cannot be reverse engineered that easily (Like scratching off part numbers e.t.c).  Also it's quite expensive (and not mine), so i can't really take the PIC off the circuit to access the code inside.  Also it's probably been protected, though i haven't checked, but the company are reluctant to give any information regarding the circuitry.
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Karl Heinz KremerConnect With a Mentor Commented:
The serial port does not use 0/5V signal levels, so you would not be able to use it directly. A better choice is the parallel port, it uses the same signal level as your device.
What operating system are we talking about?
StupotAuthor Commented:
I will probably use windows, but have the option to use linux if preferrable.
Also, the person who mentioned the idea suggested using the C functions 'inport' and 'outport'.
Karl Heinz KremerCommented:
If you are willing to use Linux, take a look at this project: http://vodka.tky.hut.fi/~jap/Programming/Slogan/
This is a simple logic analyzer that reads eight input channels (the eight data lines of the parallel port). You don't need any special hardware, just the software and the connector.
George TokasConnect With a Mentor Commented:
Jay_Harbath put it the right way.
Even if you read the PIC using a programmer if it is protected then the data you will have will be garbage.
For me i.e. if I needed to I will take a look at the circuitry to have an idea of how it is implemented and then I will make a new one of my own.
Anyway the control data from remote controls have a standard protocol.
Jay_Harbath you must be on the same field with me.
Check out my details and contact me if you like.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.