I'm trying to get myself started with the PIC 18F4550 using the C, MPLAB X (both IDE and IPE) and using the PICKit 3.I've managed to blink one LED without any problems, but as I try to blink more than one LED at simultaneously, it doesn't work.
I have tried a simple project with LED blink on/off using PIC18F4550. The compilers used are XC8 and CCS. I have used as IDE: MPLABX, CCS and Flowcode 7 (with XC8). When the projects are burned on real device and I check with the oscilloscope the signal at pin RA0, then there is no problem.
Please note that I will post my full code at the end of the question. Until then, I'll be writing pseudocode in hope of making my question a little bit clearer.
Assume I want to blink 4 LEDs, each attached to an output pin of the chip, you'd obviously type something like
You would expect that all of the LEDs would turn on and off simultaneously. However, I noticed that only the LED connected to output4 would blink and the rest would remain turned off.So I tried flipping the order of the output pins as such
As a result, only the LED attached to output 3 would blink, and the rest would remain turned off.
So I figured, somehow, the code is not executing sequentially as I'd expected it to do so.Can anyone please provide me with an explanation and a possible solution for this?
Thanks a lot!
Here's the full code
ChrisChris
2 Answers
This could be a LATCH issue. I have had this problem a few times when I started up. Try writing to the LATB (output latch) register instead of the PORTB register. I always use the LATx for output and the PORTx for input.
Mathieu L.Mathieu L.
Always write to the output latches (in your case LATB) and read inputs from PORTx. Writing to PORTx has unpredictable behaviour.
EBlakeEBlake