This is a simple problem I recently ran into in programming a PIC18F45K20.
The simple problem, if I set one of the outputs (read, one bit in PORTA), at least some of the other bits are cleared. Here is some test code I wrote to show the problem:
If I switch this code to use pins RB0 and RB1, the pins toggle simultaneously as they should.
I have not used the PIC18F series extensively, but haven't found a reason in the datasheet or errata.
Ideas?
Thanks
The simple problem, if I set one of the outputs (read, one bit in PORTA), at least some of the other bits are cleared. Here is some test code I wrote to show the problem:
If I run this code, only pin RA1 toggles high and low. RA0 stays low (except for the 1 execution step it is high before RA1).#include <htc.h>
#include <stdio.h>
__CONFIG(1, FCMEN_OFF & FOSC_INTIO7);
__CONFIG(2, PWRT_ON & BOREN_OFF & WDTEN_OFF);
__CONFIG(3, PBADEN_OFF & MCLRE_OFF);
__CONFIG(4, LVP_OFF);
void init(void);
void main(void)
{
init();
int i;
RA0=1;
RA1=1;
for(i=1; i<=1000; i++) //Delay for visual
{
_delay(1000);
}
RA0=0;
RA1=0;
for(i=1; i<=1000; i++) //Delay for visual
{
_delay(1000);
}
}
void init(void)
{
// port directions: 1=input, 0=output
TRISA = 0b00000000;
TRISB = 0b00000000;
TRISC = 0b11111111;
TRISD = 0b00000000;
//Set Oscillator to 16MHz
IRCF0=1;
IRCF1=1;
IRCF2=1;
}
If I switch this code to use pins RB0 and RB1, the pins toggle simultaneously as they should.
I have not used the PIC18F series extensively, but haven't found a reason in the datasheet or errata.
Ideas?
Thanks