Hi i just joined to try and get a little help after getting no further with my project all day.
my project is one push button and one LED.
my goal was to get the push button to swap from 1 mode to another and then off (reset to 0)
i am new to all this so i got bits of code from here and there and broke it down and managed to get were i am now.
when i press the push button it goes from off (0) to mode 3 and stays on mode 3 flashing when i press the button again the led goes off.
why does it not go to mode one and stay there?
here is the code
thank you
my project is one push button and one LED.
my goal was to get the push button to swap from 1 mode to another and then off (reset to 0)
i am new to all this so i got bits of code from here and there and broke it down and managed to get were i am now.
when i press the push button it goes from off (0) to mode 3 and stays on mode 3 flashing when i press the button again the led goes off.
why does it not go to mode one and stay there?
here is the code
C:
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Detect (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#include <xc.h>
#define _XTAL_FREQ 4000000
int main()
{
TRISIO = 0; //RB0 as output PIN
ANSEL = 0; // all outputs digital !!!!!
CMCON0 = 7;
GP1 = 0;
GP0 = 0;
int mode = 1;
while(1)
{
if(GP1 == 1)
{
__delay_ms(100);
if(GP1 == 1)
{
mode++;
GP1 = 0;
}
}
if(mode >= 4)
{
mode = 0;
}
if(mode == 2)
{
GP0 = 1;
__delay_ms(1000);
GP0 = 0;
__delay_ms(1000);
}
if(mode == 3)
{
GP0 = 1;
__delay_ms(500);
GP0 = 0;
__delay_ms(500);
}
}
}