CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC12F675 input question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
corgenius



Joined: 27 May 2015
Posts: 18

View user's profile Send private message

PIC12F675 input question
PostPosted: Sat Jun 13, 2015 1:18 pm     Reply with quote

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

Code:
#FUSES INTRC_IO


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

View user's profile Send private message

PostPosted: Sat Jun 13, 2015 3:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 14, 2015 10:47 am     Reply with quote

Dear colleagues,

I've tried modifying the code in order to have just one
Code:
while(true)
, 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

View user's profile Send private message

PostPosted: Sun Jun 14, 2015 11:25 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group