Understanding Programming

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
TerryV
Posts: 33
Joined: Tue Feb 21, 2006 10:06 am
Contact:

Understanding Programming

Post by TerryV »

As a beginner I have written a small C program which simply turns on the LEDs on the V3 development board.

The program compiles and down loads successfully but functions differently to what I expected:

My understanding was that an o/p will stay hi unless it is turned off, this does not appear to be the case, also having reached the end, the program appears to randomly restart with out my resetting.

Can some one explain?

Many thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Understanding Programming

Post by Benj »

Hello
My understanding was that an o/p will stay hi unless it is turned off
PICs work in 8-bit therefore if you modify one bit on a port then you are actually modifying an entire port. To get around this you could use something like this.

portb = portb | 0x01; //sets bit 1 of port b
portb = portb & 0xFE; //clears bit 1 of port b
having reached the end, the program appears to randomly restart with out my resetting.
The program counter on the device that fetches instructions will keep going even if your program does not. Therefore at the end of your program you must have a infinite loop to stop the program memory wrapping around back to the start or worse.

while (1) ;

Post Reply