Hi all,
I've been trying to get my program working and for some reason it doesn't. It builds successfully and i've check it all but perhaps a fresh pair of eyes will do the trick.
Posted below is the question and written program.
Question
Using two switches and 8 LEDs, write a program such that when switch 1 is pressed ON, LED 0 comes ON permanently, and LEDs 1 and 2 come ON for 2 seconds. When switch 2 is pressed on, LEDs 1 and 2 come ON for 1 second followed by the turn off of all LEDs.
My program
#include <htc.h>
__CONFIG(UNPROTECT & BORDIS & PWRTEN & WDTDIS & INTIO & MCLREN & FCMDIS & IESODIS);
#define _XTAL_FREQ 8000000
void init(void)
{
// port directions: 1=input, 0=output
TRISD = 0x00;
TRISA = 0xFF;
// 8Mhz Internal Clock
OSCCON = 0b01110000;
// Clear PortD
PORTD = 0x00;
// Turn off comparators
CMCON0 = 0x07;
//Turn off ADC
ANSEL = 0x00;
}
char counter;
void main(void)
{
init();
while (1){ while(RA0) //Wait while switch off
{ __delay_ms(1); } //Debounce switch while(!RA0) //Wait while switch on
{ __delay_ms(1); } //Debounce switch
counter = 0;
// Switch ON PORTD
PORTD = 0b11100000; // XOR (Flip) PORTD
//2 second delay rotuine
while (counter < 20){
__delay_ms(98);
counter = counter + 1;
__delay_ms(40);
}
PORTD = 0b10000000;
while (1){ while(RA1) //Wait while switch off
{ __delay_ms(1); } //Debounce switch while(!RA0) //Wait while switch on
{ __delay_ms(1); } //Debounce switch
PORTD = 0b11100000;
//1 second delay rotuine
while (counter < 10) {
__delay_ms(98);
counter = counter + 1;
}
__delay_ms(20);
// Clear PortD
// Switch OFF PORTD
PORTD = 0x00;
}
}
}
I've been trying to get my program working and for some reason it doesn't. It builds successfully and i've check it all but perhaps a fresh pair of eyes will do the trick.
Posted below is the question and written program.
Question
Using two switches and 8 LEDs, write a program such that when switch 1 is pressed ON, LED 0 comes ON permanently, and LEDs 1 and 2 come ON for 2 seconds. When switch 2 is pressed on, LEDs 1 and 2 come ON for 1 second followed by the turn off of all LEDs.
My program
#include <htc.h>
__CONFIG(UNPROTECT & BORDIS & PWRTEN & WDTDIS & INTIO & MCLREN & FCMDIS & IESODIS);
#define _XTAL_FREQ 8000000
void init(void)
{
// port directions: 1=input, 0=output
TRISD = 0x00;
TRISA = 0xFF;
// 8Mhz Internal Clock
OSCCON = 0b01110000;
// Clear PortD
PORTD = 0x00;
// Turn off comparators
CMCON0 = 0x07;
//Turn off ADC
ANSEL = 0x00;
}
char counter;
void main(void)
{
init();
while (1){ while(RA0) //Wait while switch off
{ __delay_ms(1); } //Debounce switch while(!RA0) //Wait while switch on
{ __delay_ms(1); } //Debounce switch
counter = 0;
// Switch ON PORTD
PORTD = 0b11100000; // XOR (Flip) PORTD
//2 second delay rotuine
while (counter < 20){
__delay_ms(98);
counter = counter + 1;
__delay_ms(40);
}
PORTD = 0b10000000;
while (1){ while(RA1) //Wait while switch off
{ __delay_ms(1); } //Debounce switch while(!RA0) //Wait while switch on
{ __delay_ms(1); } //Debounce switch
PORTD = 0b11100000;
//1 second delay rotuine
while (counter < 10) {
__delay_ms(98);
counter = counter + 1;
}
__delay_ms(20);
// Clear PortD
// Switch OFF PORTD
PORTD = 0x00;
}
}
}