I have an LED connected to pin RA1 of PIC18F25K20 (powered by 3.3V supply) in the following way:
5V rail -> Resistor (200 Ohm) -> LED Anode -> LED Cathode -> RA1
RA1 : Input -> LED is off
RA1 : Output Low -> LED is ON.
Is this the correct way to connect the LED, as the PIC is powered by 3.3V and LED is connected to 5V?
I initialized RA1 to be an input as shown in the DEVICE_Init
routine. Code is written in C language - Microchip C18 compiler.
void main()
{
DEVICE_Init();
//wait one second
while (1)
{
TRISA = 0; //led is on
//wait 2 seconds
TRISA = 0x06; //led is off
//wait 4 seconds
}
}
void DEVICE_Init (void)
{
OSCCON = 0x73; //PRIMARY INTERNAL OSCILLATOR
PORTA = 0;
LATA = 0;
TRISA = 0x06; //RA1, RA2 INPUT
....
}
When I first power up the chip, the LED turns ON for a fraction of a second and then turn off. My understanding is that the IO pins are input on reset. So why would the LED turn on for a brief moment at power up?