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
Understanding Programming
- 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
Hello
portb = portb | 0x01; //sets bit 1 of port b
portb = portb & 0xFE; //clears bit 1 of port b
while (1) ;
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.My understanding was that an o/p will stay hi unless it is turned off
portb = portb | 0x01; //sets bit 1 of port b
portb = portb & 0xFE; //clears bit 1 of port b
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.having reached the end, the program appears to randomly restart with out my resetting.
while (1) ;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel