Solved

C code to read TTL levels

Posted on 2004-04-06
8
227 Views
Last Modified: 2010-04-01
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?
0
Comment
Question by:Stupot
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 16

Expert Comment

by:George Tokas
Comment Utility
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.

Regards,
gtokas.
0
 

Author Comment

by:Stupot
Comment Utility
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.
0
 
LVL 44

Assisted Solution

by:Karl Heinz Kremer
Karl Heinz Kremer earned 75 total points
Comment Utility
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?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Stupot
Comment Utility
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'.
0
 

Accepted Solution

by:
Jay_Harbath earned 150 total points
Comment Utility
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.  
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 
LVL 16

Assisted Solution

by:George Tokas
George Tokas earned 75 total points
Comment Utility
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.
Regards,
gtokas.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now