PDA

View Full Version : PIC16F684 GPIO puzzles me



rrupad
- 22nd December 2015, 06:11
The PIC GPIO puzzles me.

My requirement is to light up LEDs one after another with a slight delay and at the end of it all the LEDs need to glow.

Below is the code that I wrote.

void initPorts()
{
PORTA = 0X00;
TRISA = 0X00;

PORTC = 0x00;
CMCON0 = 0X07;
TRISC = 0x00;
}

void main()
{
initPorts();

while(1)
{
RC5 = HI; __delay_ms(50);
RC4 = HI; __delay_ms(50);
RC3 = HI; __delay_ms(50);
RC2 = HI; __delay_ms(50);
RC1 = HI; __delay_ms(50);
RC0 = HI; __delay_ms(50);
}
}

When I execute this code on the target - LEDs on Port RC4 and RC5 glow continuously and the LEDs connected to the remaining ports sequentially switch on and off creating a running light effect.

What am I doing wrong??

Thanks for any response.

Ravi Upadhyaya

Heckler
- 23rd December 2015, 04:15
This forum is for the PICBASIC compiler.

Your code appears to be a variant of "C" rather than BASIC

You may need to look elsewhere.

sorry:o

HenrikOlsson
- 23rd December 2015, 06:17
"Wrong" language ;-)
But try enabling digital I/O on PortC, look at the ANSEL register.

/Henrik.