The move from Assembly Language to C

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
I have a pretty generic understanding of Assembly at this point, but I'd like to maybe migrate over to C since it seems to be the standard programming language for PIC Micros. I learned assembly with a book called Know it All PIC Microcontrollers from Newnes publishing, which was a great book and helped tremendously; and also from members at AAC.

Now I'm trying to decide on a good book for getting started with C that is for beginners (no prior knowledge of C required). An amazon.com search of "C Programming for PIC Microcontrollers" yeilds a number of results. Anyone have any good suggestions?

Thanks!
 

spinnaker

Joined Oct 29, 2009
7,830
I have a pretty generic understanding of Assembly at this point, but I'd like to maybe migrate over to C since it seems to be the standard programming language for PIC Micros. I learned assembly with a book called Know it All PIC Microcontrollers from Newnes publishing, which was a great book and helped tremendously; and also from members at AAC.

Now I'm trying to decide on a good book for getting started with C that is for beginners (no prior knowledge of C required). An amazon.com search of "C Programming for PIC Microcontrollers" yeilds a number of results. Anyone have any good suggestions?

Thanks!
You should not have too many problems moving over. It is where I got my start. Actually I got my start in machine code and when the PET got an assembler, it was a major improvement to coding.

I like this site. They have some good lessons and it is free.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Rich (BB code):
example code (not really a program)

while (1)
{ this is point A
   program goes here, etc
    {
     branch}
}point B
Can someone help me understand the While (1) loop? Does the loop begin at point A and end at point B, and then return to start again at point A? Am I to understand that the purpose of the (1) is that while the condition is other than "1" the loop will repeat, which is essentially forever since the condition can never be "1"? I'm sorry for such a stupid question but I'm new to C.
 

nerdegutta

Joined Dec 15, 2009
2,684
Hi.

I use the:

Rich (BB code):
while (1)
{
some stuff
}
whenever I need a endless-loop. It repeats inside the brackets until program it terminated by a reset, power off, or a break statement inside the while-loop.

I have this kind of loop in a small LED chaser program. Inside the loop, it checks if a bit is set high. If its high, the program exits the loop, perform a procedure on flashing some LEDs, and returns to the loop. Checking for next bit to be set high.

Read this

It repeats since the condition is true. 1 is equal to 1.
 

myforwik

Joined Feb 15, 2010
11
Rich (BB code):
example code (not really a program)

while (1)
{ this is point A
   program goes here, etc
    {
     branch}
}point B
Can someone help me understand the While (1) loop? Does the loop begin at point A and end at point B, and then return to start again at point A? Am I to understand that the purpose of the (1) is that while the condition is other than "1" the loop will repeat, which is essentially forever since the condition can never be "1"? I'm sorry for such a stupid question but I'm new to C.
The loop begins and ends at the outer { } brackets. while (statement) { } means the program will execute the commands between the { } , then check if the statement is true, then execute them again and so on. So the things inbetween { } get execute while the statement is true.

The only way the loop can exit is by a break; statement, which causes execution to jump to the } bracket.
 

AlexR

Joined Jan 16, 2008
732
You can use in-line assembler in most (all?) PIC C compilers but unless you have some pressing need (such as critical timing requirements) its best to avoid the practice. The whole point of writing in C is to produce code that is easy to read and maintain, the last thing you need is blocks of assembler mixed in with the C code obscuring its meaning and making it hard to understand.
 
Top