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

How selecting a menu with a single input selector

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

How selecting a menu with a single input selector
PostPosted: Fri Jan 22, 2010 10:15 am     Reply with quote

Hi, I have a doubt, I want to select one of three possible option of a menu but using a single selector in this case the RA2 of Pic16f88, someone can tell me how I can do this, I can not use interrupts why that I'm using something else, here is my code but this does not work

Code:
#include <16F88.h>
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOCPD,NOWRT,NODEBUG
#use delay(clock=20000000)

#use fast_io(A)
#use fast_io(B)

#byte PORTA                = 0x05
#byte PORTB                = 0x06
#byte ANSEL                = 0x9B
#byte OPTIONREG            = 0x81

#define PULSADOR         PIN_A2
int Modo;

void Option_0();
void Option_1();
void Option_2();
   


void main()
{
   set_tris_A(0b00011100);
   set_tris_B(0b11001101);

   ANSEL=0;
   OPTIONREG=OPTIONREG & 0x7F;     

   while(1){

   if (!input(PULSADOR)){;
      Modo = 0;
      if (!input(PULSADOR)){;
         Modo = 1;
         if (!input(PULSADOR));
            Modo = 2;
         }
      }
   }
   if (Modo == 0)
      Option_0();
   if (Modo == 1)
      Option_1();
   if (Modo == 2)
      Option_2();
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Jan 22, 2010 1:42 pm     Reply with quote

You're using the same pin to set the different values. What you are doing in your if() statements is if the input goes low the first if() is entered. You assign modo=0. IMMEDIATELY the next if() statement is entered. If the input is still low modo=1. IMMEDIATELY the last if() statement is entered. If the input is still low modo=2. This happens so fast that it will, invariably, end up being 2 every time. You need to change your code to something like:
Code:
  if(!input(PULSADOR) && modo == 0)
  {
    modo = 1;
    option_0();
    while(!input(PULSADOR))// wait until the input goes high again
      ;
  }

  if(!input(PULSADOR) && modo == 1)
  {
    modo = 2;
    option_1();
    while(!input(PULSADOR))// wait until the input goes high again
      ;
  }

  if(!input(PULSADOR) && modo == 2)
  {
    modo = 3;
    option_2();
    while(!input(PULSADOR))// wait until the input goes high again
      ;
  }

Or something like that. It could be simplified a bit but that might be a way to accomplish what you're looking for. You'll need something to set modo back to 0 again or it will never enter any of the if() statements again.

Clear as mud?

Ronald
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