Berkeman is right, to learn anything you need to produce the final code and even if I wanted to I couldn't produce much C code in my present condition & circumstances. (Today I have been awake less than 4 useful hours.) I have already done a similar project, so I can tell you in my sleep a few things -- but new ideas aren't going to be quickly assimilated. (After a Murphy Sunday to Tuesday -- I wouldn't even want to try) All of my hardware routines were done in assembly, and only the high level interface program was done in C for convenience; esp. for my other teammates who weren't assembly level programmers... There wasn't enough memory in the chip to do everything in C code anyhow -- and I mentored my other team mates on how to write code in C to replace the libraries that came with the compiler which were too big. It was a great learning experience, but a bit of work which is *specific* to optimizations of our project.
I don't see the attachment to know your general idea, still... as I am able ... which isn't predictable/consistent -- I am willing to give you some pointers as you get stuck -- though I don't want and am not able to do your project for you.
A PIC16F877 is in the 16 series of microcontrollers; most people don't program them with a C compiler -- I happened to have a C compiler for (other) 16F controllers from CCSC, If you are thinking the IDE from Microchip comes with C for free, look carefully, for as a year ago when I loaded the latest IDE the C compiler *hitches* were available, but the actual software was separate.
If that is still the case, there is an open source project for 16 series mnemonics, but it isn't GCC and it is alpha software which if you are asking me for code now, isn't going to be a viable solution for you.
Do you have a full C compiler, then, that you haven't spoken of; if so, which company makes it? -- for that affects how you code your program. Microcontroller C compilers generally need special consideration to operate 8 bit MCUs. C is really a 32 bit language which gets shoehorned into 8 bits using various hacks and routines written by the compiler company. It feels like C, but the code efficiency is horrible for such a small memory device.
Your accelerometer datasheet already has a wiring diagram for a pic12F chip which will be nearly identical to your own (change pin numbers based on data-sheet). A couple of things to notice -- the PIC is powered from the accelerometer; this may or not be a convenience issue. The A/D converters on the PICS are ratiometric. If you change the power supply to the A/D converter -- you get different numbers. #1 -- To make the system stable -- design so that at least your A/D and accelerometer share in some way -- the same voltage reference. #2 -- be careful that the reference power supply isn't being heavily loaded because the pic microcontroller is switching large power swings (for itself, not absolute...) on its logic pins -- especially at high speed. #3 -- your solution isn't mine; I used an external A/D chip with a digital interface, so my program software had different requirements than yours does and my code won't help you much anyway.
What I have told you is nothing more than what is on the datasheet -- and what you can find in "Design notes" from various companies for different accelerometers, etc.
Here is a sample of the kinds of things a design note closer to your project ought to talk about -- that I can produce off the top of my head. You have a 3.33mV swing, so questions you need to think about are -- what is my operating point in terms of G. eg: how much will gravity bias the chip axes such that 'I' will not have +-3G on at least one axis, but more like =-1G+2G or whatever your design really has. How am 'I' going to deal with the zero point floating at some vaguely defined value, which might even change with temperature (Datasheet for composite surf board doesn't say...what does AnalogDev datasheet tell 'me' about zero point accuracy of the ACTUAL chip). Can a simple number coded as zero offset for all time be accurate enough for 'my' project? How many mV/uV/step can 'I' actually measure with the microcontroller ADC given the number of bits, and that full scale is __ volts, and that the accelerometer only outputs a two volt swing which is 2V/__ Volts. Is it fine enough to detect a 50% smaller signal than the smallest one I am expecting is significant?
Without knowing the idea, I can't suggest anything about software design pitfalls; nor can I point you toward specific design notes easily available on the web... Big hint; don't blatantly copy without checking the copyrights, understanding the code fully, and being sure you aren't wasting your time.
There are general questions one needs to answer at every step of a project -- and the one you must watch out for the most, is that you have limited program space. 14K of 8 bit instructions, is like 7K of 16 bit instructions, is like 3.5K of 32 bit instructions. 4096 commands (lines of C code or often less) is what you most likely have if you are not careful.
A text message like "Hello world, press A key to continue." Requires 38, PIC 16F instructions *just to store*, not to mention every time it is "printed", the call print routine takes several instructions to set things up, eg: 5-10 instructions would not be unusual. A real good time saver *in the future* is to waste a little time now writing dummy routines and compiling them to find out how much space typical operations cost.
For example: try this program.
int dummy( int a, int b ) {
int c,d;
c=a; b=d;
return c+d;
}
main() {
int a,b,c;
a=1;
b=3;
c=dummy(a,b);
}
how much space does this *Simple* progam take. How much more (and I guarantee it will be more) would the code take if c+d is replaced with c*d. How about (gasp) c/d.
If it doesn't surprise you, you know more than you need to do the project -- and are going to have an easy time of it and are just being lazy asking for help. If it does surprise you, you are normal and need to do more thinking perhaps guided a little.
Best wishes.
--Andrew.