[SOLVED] Unable to set specific bits in PORTs
I'm using a PIC18F4550 and it seems that I can't set any bits higher than RB0 and RB1. If I set all 8 on at the same time it seems to work fine, just not if I want 7 for example.
Here is some test code:
All I see with this code are my LEDs counting in binary 0, 1, 2, 3, 0, 1, 2, 3. What's even more strange is that PORTB (don't know about the others) is actually resetting to 0 after 3.
Could any of your gurus please shed some light on this. I've never come across this project before. My hardware setup is extremely simple and as 0xFF seems to work fine I guess it's not the LEDs themselves that are bust.
Please note that i've tried quite a few diffrent ways of changing PORTB, including setting the value manually.
I'm using a PIC18F4550 and it seems that I can't set any bits higher than RB0 and RB1. If I set all 8 on at the same time it seems to work fine, just not if I want 7 for example.
Here is some test code:
Code:
#include "p18f4550.h"
#include "delays.h"
#include "timers.h"
#pragma config PLLDIV = 5, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = HSPLL_HS, FCMEN = OFF, IESO = OFF, PWRT = ON, BOR = OFF, BORV = 0, VREGEN = OFF, WDT = OFF, CCP2MX = OFF, PBADEN = OFF, LPT1OSC = ON, MCLRE = ON, STVREN = ON, LVP = OFF, ICPRT = OFF, XINST = OFF, DEBUG = OFF
#define delay() Delay10KTCYx(150)
void main()
{
unsigned int delay = 1;
volatile unsigned char x = 4;
ADCON0 = 0;
INTCON = 0;
SPPCON = 0;
UCON = 0;
TRISB = 0;
PORTB = 0xFF;
TRISD = 0;
PORTD = 0;
while(1)
{
PORTB = PORTB + 1;
PORTD = PORTD + 1;
delay();
}
}
All I see with this code are my LEDs counting in binary 0, 1, 2, 3, 0, 1, 2, 3. What's even more strange is that PORTB (don't know about the others) is actually resetting to 0 after 3.
Could any of your gurus please shed some light on this. I've never come across this project before. My hardware setup is extremely simple and as 0xFF seems to work fine I guess it's not the LEDs themselves that are bust.
Please note that i've tried quite a few diffrent ways of changing PORTB, including setting the value manually.
Last edited: