Hello everyone,
I wrote the program shown below to be utilized with the PICkit 2 demo board. The intent of the written code is to light up the LEDs connected to RC0 and RC1 when the switch connected to RA3 is not pressed. However, when RA3 is pressed, RC0 and RC1 should go off. Once the switch is pressed twice then RC2 should turn on. Unfortunately, what I have described is not happening. All of the leds are on at all time. Please help!!!
/*
PIC16F690 Configuration
*/
__CONFIG (INTIO & WDTDIS & PWRTEN & MCLRDIS & BORDIS & UNPROTECT & IESODIS & FCMDIS ); //Internal clock, Watchdog off, MCLR off, Code Unprotected
main()
{
ANSEL = 0; // Intialize A/D ports off
CM1CON0 = 0; // Initialize Comparator 1 off
CM2CON0 = 0; // Initialize Comparator 2 off
PORTC = 0x00; //Clear PortC port
TRISC = 0x00; //All PortC I/O outputs
TRISA = 0xFF; //All PortA I/O inputs
unsigned char count = 0; // Initialize count equal to zero
while(1==1) //loop forever
{
if (RA3 == 1) // Test RA3 port
{
RC0 = 1; // If SW1 not pressed, turn on RC0 LED
RC1 = 1; //If SW1 not pressed, turn on RC01 LED
}
else if (count == 2 ) //Check count to be equal to two
{
RC2= 1; //Turn on RC2 when SW1 is pressed twice
}
else
{
count = count + 1; //Increment count by one
RC0 = 0; // If SW1 pressed, turn off RC1/DS2 LED
RC1 = 0;
}
} //End while
} //end main
I wrote the program shown below to be utilized with the PICkit 2 demo board. The intent of the written code is to light up the LEDs connected to RC0 and RC1 when the switch connected to RA3 is not pressed. However, when RA3 is pressed, RC0 and RC1 should go off. Once the switch is pressed twice then RC2 should turn on. Unfortunately, what I have described is not happening. All of the leds are on at all time. Please help!!!
/*
PIC16F690 Configuration
*/
__CONFIG (INTIO & WDTDIS & PWRTEN & MCLRDIS & BORDIS & UNPROTECT & IESODIS & FCMDIS ); //Internal clock, Watchdog off, MCLR off, Code Unprotected
main()
{
ANSEL = 0; // Intialize A/D ports off
CM1CON0 = 0; // Initialize Comparator 1 off
CM2CON0 = 0; // Initialize Comparator 2 off
PORTC = 0x00; //Clear PortC port
TRISC = 0x00; //All PortC I/O outputs
TRISA = 0xFF; //All PortA I/O inputs
unsigned char count = 0; // Initialize count equal to zero
while(1==1) //loop forever
{
if (RA3 == 1) // Test RA3 port
{
RC0 = 1; // If SW1 not pressed, turn on RC0 LED
RC1 = 1; //If SW1 not pressed, turn on RC01 LED
}
else if (count == 2 ) //Check count to be equal to two
{
RC2= 1; //Turn on RC2 when SW1 is pressed twice
}
else
{
count = count + 1; //Increment count by one
RC0 = 0; // If SW1 pressed, turn off RC1/DS2 LED
RC1 = 0;
}
} //End while
} //end main