On Sun, Apr 06, 2014 at 02:55:22PM -0400, Josh Koffman wrote: > Thank you everyone for the fantastic comments! I am starting by > translating some of my existing, working projects over to C, as a > challenge to illustrate the differences. And boy, are there ever a > lot! For the record, I work pretty much exclusively with the 18f chips > at the moment, but I am seriously considering moving up, given that > I'd like to continue writing in C. The bummer is that currently when > starting a new project, I'll often grab an existing board, bodge on > some wires, and give things a go before spinning a new PCB. I guess I > will have to take the plunge at some point and get something designed > using a 16 or 32 bit chip! I have also been looking at a few general > dev boards. We'll see. For a specific PIC24 chip take a look at the PIC24FVKM202. 16K of program memory, 2K of general purpose ram, 5V operation, in a 28 pin DIP package. Takes 5 minutes to wire up on a breadboard. > Thank you for the comments on the goto keyword. I agree, and I am > going to try to avoid using it. We'll see how I do. I realize why it's > unsavoury for many, and I hope to be able to figure things out enough > that I don't need it. At the very least, it should be a good challenge > to rethink the way most of my routines work. The rethinking is in the understanding that you've been doing the compiling for yourself in assembly. Consider a simple "if" statement: if (j =3D=3D 5) { // a few lines of code } Now in assembly you did the comparison of j and 5, followed by a skip/branch combo where the skip jumped into the few lines of code and the branch jumped around it to the end. That's exactly what the compiler does for you now. But you do not have to do the comparison code, or the skip/branch, or generating a label to branch to. It takes care of all that for you. > As for variables, I am going to try to be very conscious about how I > declare them. One thing I'm not entirely sure on, is what if my > project consists of multiple source files? As an example, suppose I > have a function in a different file (say, function.c). If I call that > function from my main loop, how would I have to define the variable? Declare the function in the main source file? As a prototype. That would be the header of the function without the body (which is in the {} that follow the function header. The linker will find it for you and link the proper addresses together. > Do I do it in the main loop, or as a global? I know that technically I > could craft all my functions to take every single variable as an > argument, but that seems a bit unwieldy. Generally I keep a few > registers that I will set bits in for flags on how the program is > running, or what state it's in. I don't think I've fully grasped what > it means to declare something volatile, static, or just regular > global. Now for a variable, you would declare it in one file or the other and then make a declaration of the variable using an 'extern' statement in the other: function.c ---------- unsigned long var_that_you_need; main.c ------ extern unsigned long var_that_you_need; the space is allocated in function.c. main.c simply informs the linker that the variable is located in another file. Again the linker takes care of all of it. Typically what is done is to put all these types of definitions in a header file. So for example: function.h ---------- extern unsigned long var_that_you_need; function.c ---------- #include "function.h" unsigned long var_that_you_need; main.c ------ #include "function.h" main() { var_that_you_need =3D 2L; } The compiler doesn't get confused by both the extern definition and the real definition in function.c. The real definition superceeds. >=20 > Thank you again! Hope this helps, BAJ >=20 > Josh > --=20 > A common mistake that people make when trying to design something > completely foolproof is to underestimate the ingenuity of complete > fools. > -Douglas Adams > --=20 > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 Byron A. Jeff Chair: Department of Computer Science and Information Technology College of Information and Mathematical Sciences Clayton State University http://faculty.clayton.edu/bjeff --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .