View previous topic :: View next topic |
Author |
Message |
corgenius
Joined: 27 May 2015 Posts: 18
|
PIC12F675 input question |
Posted: Sat Jun 13, 2015 1:18 pm |
|
|
Dear colleagues,
Recently I've developed a code for making a small delay project using a PIC12F675.
The program makes an output high for a specific amount of time and it works perfectly but just for ONE input.
I've tried to add 2 inputs to have different delay time for the same output, but it seems whatever I try, the only input that works is the one that is written first in the code.
My code is : Code: | #include <12F675.h>
#FUSES INTRC_IO
#use delay(clock=4MHz)
#define LAMP_BUTTON PIN_A0
#define LAMP_BUTTON2 PIN_A2
#define LAMP PIN_A5
#define LAMP2 PIN_A4
#define LAMP3 PIN_A1
#define SWITCH_PRESSED 0 // 5V
#define SWITCH_NOT_PRESSED 1 // 0V
//============================================================================================
void main()
{
int8 previous, current, previous2, current2;
delay_us(100); // delay for pullups
output_high(LAMP3); //STATUS MICROCONTROLLER - LED ON = MICROCONTROLER ON
//===========================================================================================
//first input
previous2 = !input(LAMP_BUTTON2); // read buton
While (true) // FOREVER LOOP
{
current2 = !input(LAMP_BUTTON2);
if((current2 == SWITCH_PRESSED) && (previous2 == SWITCH_NOT_PRESSED))
{
output_high(LAMP);
delay_ms(5000);
output_low(LAMP);}
previous2 = current2;
}
//===========================================================================================
//secund input
previous = !input(LAMP_BUTTON); // read buton
While (true) // FOREVER LOOP
{
current = !input(LAMP_BUTTON);
if((current == SWITCH_PRESSED) && (previous == SWITCH_NOT_PRESSED))
{
delay_ms(200); // DELAY
output_high(LAMP); // Open PIN_A5
// light game - just for fun - start
output_high(LAMP2);
delay_ms(3000);
output_low(LAMP2);
delay_ms(300);
output_high(LAMP2);
delay_ms(1000);
output_low(LAMP2);
delay_ms(200);
output_high(LAMP2);
delay_ms(900);
output_low(LAMP2);
delay_ms(180);
output_high(LAMP2);
// light game - just for fun - end
output_low(LAMP); // close pin_a5
output_low(LAMP2); //close light game LED
delay_ms(30);
}
previous = current;
delay_ms(30);
}
}
|
I'm guessing its from
I've tried to search the datasheet but with no results.:( Also tried modifying it in order to add I2 as INTRC but with no result
Does anyone have an idea why the code doesn't accept 2 inputs?
Warm regards,
Eugeniu |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat Jun 13, 2015 3:13 pm |
|
|
Hi,
It's working exactly as you coded it! Hint: how does your code ever get beyond the 1st While loop? You need to investigate what While (true) means!
John |
|
|
corgenius
Joined: 27 May 2015 Posts: 18
|
|
Posted: Sun Jun 14, 2015 10:47 am |
|
|
Dear colleagues,
I've tried modifying the code in order to have just one , but I didn't had any luck:(.
Code:
Code: | #include <12F675.h>
#FUSES INTRC_IO
#use delay(clock=4MHz)
#define LAMP_BUTTON PIN_A0
#define LAMP_BUTTON2 PIN_A2
#define LAMP PIN_A5
#define LAMP2 PIN_A4
#define LAMP3 PIN_A1
#define SWITCH_PRESSED 0 // 5V
#define SWITCH_NOT_PRESSED 1 // 0V
//============================================================================================
void main()
{
int8 previous, current, previous2, current2;
delay_us(100); // delay for pullups
output_high(LAMP3); //STATUS MICROCONTROLLER - LED ON = MICROCONTROLER ON
//===========================================================================================
//first input
previous2 = !input(LAMP_BUTTON2); // read buton
While (true) // FOREVER LOOP
{
current2 = !input(LAMP_BUTTON2);
if((current2 == SWITCH_PRESSED) && (previous2 == SWITCH_NOT_PRESSED))
{
output_high(LAMP);
delay_ms(5000);
output_low(LAMP);}
previous2 = current2;
}
//===========================================================================================
//secund input
previous = !input(LAMP_BUTTON); // read buton
current = !input(LAMP_BUTTON);
if((current == SWITCH_PRESSED) && (previous == SWITCH_NOT_PRESSED))
{
delay_ms(200); // DELAY
output_high(LAMP); // Open PIN_A5
// light game - just for fun - start
output_high(LAMP2);
delay_ms(3000);
output_low(LAMP2);
delay_ms(300);
output_high(LAMP2);
delay_ms(1000);
output_low(LAMP2);
delay_ms(200);
output_high(LAMP2);
delay_ms(900);
output_low(LAMP2);
delay_ms(180);
output_high(LAMP2);
// light game - just for fun - end
output_low(LAMP); // close pin_a5
output_low(LAMP2); //close light game LED
delay_ms(30);
}
previous = current;
delay_ms(30);
} |
Does anyone else have any ideas?
Regards,
Eugeniu |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 14, 2015 11:25 am |
|
|
Look up the 'break' statement in a C manual.
Edit:
He solved it per my answer to his question in a PM, that he combine the
two while() loops into one while() loop. |
|
|
|