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 CCS Technical Support

[SOLVED] Input loop?

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



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

[SOLVED] Input loop?
PostPosted: Sun Oct 19, 2014 2:10 pm     Reply with quote

Dear CCS fanatics Smile

Take a look at this code...

This is in the main loop

Code:

   if (waitforbuttoninput)
   {
      if (!input(PIN_C2))
      {
      putc('.');
      waitforbuttoninput=0;
      }
   }


Why when I set the waitforbuttoninput to true it read correctly and putchar . character over serial BUT never stop listening for input??

If I keep pressing the switch I still get dot characters but it should not since I've set the flag to 0...


Any idea??

Would a break statement inserted after waitforbuttoninput=0; help?

I know this is for exiting a while,switch and for loop...





EDIT (For clarifying):

Code to enable reading of the switch which works great (to receive from serial)

Code:

      case 'Y' : waitforbuttoninput = 1; // read start button and flash 
      break;
      case 'y' : waitforbuttoninput = 0;
      break;


Using pcwhd 5.027 on a PIC18F4685
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!


Last edited by ELCouz on Sun Oct 19, 2014 5:37 pm; edited 1 time in total
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Oct 19, 2014 3:00 pm     Reply with quote

Post SHORT but complete, compilable code which shows us exactly what your problem is.
(Save us from having to second guess.)

Mike
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Oct 19, 2014 3:06 pm     Reply with quote

I don't know what more you can see but here it is...


Code:
#include <18F4685.h>
#FUSES HS,NOMCLR,NOLVP,NOPBADEN,BROWNOUT,BORV46,PUT

#use delay(clock=12M)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,errors)


int8 dummy;
int1 waitforbuttoninput;


#int_rda
void serial_isr()
{
dummy=getc();
}




void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

   while(1)
   {
 
      switch (dummy)
      {
      case 'Y' : waitforbuttoninput = 1; // read start button
      break;
      case 'y' : waitforbuttoninput = 0;
      break;
      }

   
   if (waitforbuttoninput)
   {
      if (!input(PIN_C2))
      {
      putc('.');
      waitforbuttoninput=0;
      }
   }
   
   }
}

_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Oct 19, 2014 4:22 pm     Reply with quote

Code:

   if (waitforbuttoninput)
   {
      if ((!input(PIN_C2))&&(waitforbuttoninput))
      {
      waitforbuttoninput=0;
      putc('.');
      }
   }


Even this doesn't work the int1 waitforbuttoninput isn't set to 0 or the IF statement ignore the 0 value...

Shouldn't the pic check if waitforbuttoninput is set to 1 before reading the input?
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2014 5:01 pm     Reply with quote

Quote:
Shouldn't the pic check if waitforbuttoninput is set to 1 before reading the input?

You press a key and 'dummy' gets set to 'Y'. Once it's set, it stays that
way forever (unless you press a different key). You never clear 'dummy'.
You crank through your while() loop, it sees the 'Y', it sets
'waitforbuttoninput' to 1. It's because you never clear 'dummy'.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Oct 19, 2014 5:28 pm     Reply with quote

PCM programmer wrote:
Quote:
Shouldn't the pic check if waitforbuttoninput is set to 1 before reading the input?

You press a key and 'dummy' gets set to 'Y'. Once it's set, it stays that
way forever (unless you press a different key). You never clear 'dummy'.
You crank through your while() loop, it sees the 'Y', it sets
'waitforbuttoninput' to 1. It's because you never clear 'dummy'.


You are right!

I've modified my working code too fast. Clearly skipped that...

Code:


.....

      case 'x' :output_low(pin_a0);
      dummy = 0;
      break;
      case '?' :printf("$!*"); //keep alive
      savedcount = count;
      dummy = 0;
      break;
      case '@' :printf("$%s*",version); // version info
      dummy = 0;
      break;
      case 'Y' : waitforbuttoninput = 1; // read start button and flash 
      break;
      case 'y' : waitforbuttoninput = 0;
      break;
      }


You could see its been there before but managed to forget to add this...

Thanks for pointing me out PCM Programmer!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Mon Oct 20, 2014 12:40 am     Reply with quote

You can also see 'why' PCM_programmer asked for complete code. The problem was actually 'outside' the bit you were looking at.... Smile
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