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

button block and unblock

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







button block and unblock
PostPosted: Thu May 12, 2005 9:22 am     Reply with quote

I have to block user actions within 5 hours.
User enters some number on keypad and after last hitting on the "enter"
block no_press should be active.
After 5 hours you can enter the new number.
Main problem is that all other buttons ( alarm, cooler ) and so on, must be
active all the time ( and within 5 hours ). Just the enter is blocked.

How to make this ?
Timer for counting is timer0.
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

PostPosted: Thu May 12, 2005 11:05 am     Reply with quote

set a flag and use an if statment everywhere the button is to be used to execute a function. Use a timer to keep track of time for 5 hours. Reset the timer when after "enter" is pressed and when time is up clear the flag to allow presses again.

Code:
if(block_init)
 nopress = 1;

if(count == hrs)
  nopress = 0;

if(nopress == 0)
  do_function();
else
  block_function();  //in case you want to send message "blocked" to the LCD display or something.


You can still pick up the button press and just ignore the function it is supposed to execute. Or you could use the flag to ignore the selected button press detection. You fill in the blank.
_________________
-Matt
Jurgens
Guest







PostPosted: Fri May 13, 2005 6:21 am     Reply with quote

Thank you for your explanation.
A have some problems whit this one....

Code:


//Timer0
if (hour < 5)
{
  blockEnterTime=1;
}

// button
if(blockEnterTime == 1)
{
  printf(lcd_putc,"Block");
  delay_ms(1000);
  blockEnterButton=1;
}

if (blockEnterButton == 1)
{
    printf(lcd_putc,"\f NO PRESS");         
else
    printf(lcd_putc,"\f FREE PRESS");
    // do something         
}            
   
break;


//-----------
It is ok but wenn i hit next time on the enter button, program goes thru same stuff but he should block the next enter button press...
Time is still under 5 hours and block should be activated...


I get this on the second pass : enter press / "block" / "FREE PRESS"... instead "NO PRESS"

Why is this so ?
Jurgens
Guest







PostPosted: Fri May 13, 2005 6:22 am     Reply with quote

Thank you for your explanation.
A have some problems whit this one....

Code:


//Timer0
if (hour < 5)
{
  blockEnterTime=1;
}

// button
if(blockEnterTime == 1)
{
  printf(lcd_putc,"Block");
  delay_ms(1000);
  blockEnterButton=1;
}

if (blockEnterButton == 1)
{
    printf(lcd_putc,"\f NO PRESS");         
else
    printf(lcd_putc,"\f FREE PRESS");
    // do something         
}            
   
break;


//-----------
It is ok but wenn i hit next time on the enter button, program goes thru same stuff but he should block the next enter button press...
Time is still under 5 hours and block should be activated...


I get this on the second pass : enter press / "block" / "FREE PRESS"... instead "NO PRESS"

Why is this so ?
bfemmel



Joined: 18 Jul 2004
Posts: 40
Location: San Carlos, CA.

View user's profile Send private message Visit poster's website

PostPosted: Fri May 13, 2005 9:20 am     Reply with quote

Jurgen,

Somewhere in your program you have a spot where you get new key states, at least it would be nice if there was only one place. If so then you can control which keys get reported from there. Set up a timer and set it when the enter key is pressed and don't return the ENTER key value until the timer hits zero again. See the code fragments I put together below.
Code:

#int_TIMER2
void TIMER2_isr( void ) {

   if (lastEnterTime)            // decrements the counter to keep Enter key from being seen
      --lastEnterTime;           // stop decrementing at 0, don't allow underflow
}


/*    get physical key press information from hardware    */
unsigned int8 GetNewKeyState(void)    {

   // .. do some sort of hardware decode to get the physical keypress
}

/* process key press */
unsigned int8 KeyPress(void)   {
   int8 keyReturn;         // key that was pressed
     
   if( !(keyReturn = GetNewKeyState()) )  {    // As long as a key was pressed process the information
      switch  (keyReturn) {      // allows different processing for each switch case.
         case  ONE:
         case  TWO:
         case  THREE:
         case  FOUR:
         case  FIVE:
         case  SIX:
         case  SEVEN:
         case  EIGHT:
         case  NINE:
         case  ZERO:
            break;
         case ENTER:
            if (lastEnterTime)               // As long as it has not been five minutes since the last time.
               keyReturn = 0;                // then return a NULL key press
            else                             // if the five minute timer is zero, then ...
               lastEnterTime = FIVE_MINUTES; // set the timer to five minutes again and return the enter key
            break;
         default:
            keyReturn = 0;
            break;
      }  /* end of switch */
   }  /* end of keyReturn not blank */
}  /* end of KeyPress() */


Good Luck;

- Bruce
Guest








PostPosted: Fri May 13, 2005 12:07 pm     Reply with quote

Jurgens wrote:
Code:


if (blockEnterButton == 1)
{
    printf(lcd_putc,"\f NO PRESS");         
else
    printf(lcd_putc,"\f FREE PRESS");
    // do something         
}            
   
break;


Look closely wt this code. Look at your braces. should be:

Code:
if (blockEnterButton == 1)
    printf(lcd_putc,"\f NO PRESS");         
else
    printf(lcd_putc,"\f FREE PRESS");
    // do something   


or

Code:
if (blockEnterButton == 1)
{
    printf(lcd_putc,"\f NO PRESS");         
}
else
{
    printf(lcd_putc,"\f FREE PRESS");
    // do something   
}


braces are only needed when you have more than 1 line of code inside the statement.
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

PostPosted: Fri May 13, 2005 12:10 pm     Reply with quote

And what is the break for?
_________________
-Matt
Jurgens
Guest







PostPosted: Fri May 13, 2005 12:33 pm     Reply with quote

Yes, there is no need for break... and i have correct my errors,
but i still end in "free press" part ??

Jurgens S.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri May 13, 2005 12:53 pm     Reply with quote

Jurgens wrote:
Quote:

but i still end in "free press" part ??


I donīt see in your code how do you quit a detect condition, you coded:

Code:

if (hour < 5)
{
  blockEnterTime=1;
}
.........................
if(blockEnterTime == 1)
{
  printf(lcd_putc,"Block");
  delay_ms(1000);
  blockEnterButton=1;
}
.......................


But I donīt see how/where you clear that condition

Code:

 blockEnterTime=0;
 blockEnterButton=0;


99.99 of times the testing behaviour is according to the code that we wrote !!! Shocked

Best wishes,

Humberto
Jurgens
Guest







PostPosted: Sat May 14, 2005 6:58 am     Reply with quote

The values are set but i think that something else could be problem.
Wenn i program the chip you get this situation:

First run:
blockButton --> 0 / Free press / do something

Second run:
blockButton --> 0 / No press / Free press / do something

It looks like, like he dose not stop on no press part.
Do i have to make some function for exit (wenn he reach the no press part)? The program should just block the enter press until 5 hours nothing else..

One other thing:
Im timer0 i have 4 if schleifen ( if for sec, min, hours and for 5 hours).
What is wiht timer? Weil i have to count till AND over 5 hours ( till i reach 10 hours ), what happens wenn i set blockTime=0;. Will the timer be reseted or not ?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat May 14, 2005 9:29 am     Reply with quote

Jurgens,

What you told us is out of our scope and understanding.

Quote:

First run:
blockButton --> 0 / Free press / do something

Second run:
blockButton --> 0 / No press / Free press / do something


Without full C code we canīt help you nor know what/how are you trying to do it.

Humberto
Jurgens
Guest







PostPosted: Sat May 14, 2005 11:16 am     Reply with quote

Second run:
blockButton --> 1 / No press / Free press / do something

Everything is OK accept he dont makes stop on NO PRESS.

Code:

...
#define INTS_PER_SECOND 76

int8 sekunden=0, minuten=60, stunden, stunden_sleep=0;
int8 int_count , blockEnterTime, blockEnterButton=0;   


#int_rtcc                       
void clock_isr() {                 
                                   
      if(--int_count==0)
     {         
         ++sekunden;
         int_count = INTS_PER_SECOND;
         
      if(sekunden==60){
          minuten++;
         }
     
         if(minuten==60){
                  stunden_sleep++;
         stunden++;
          }
     
         if(stunden_sleep < 5)             
       {
          blockEnterTime=1;            
       }
      }
}

main()
{
   
      int_count=INTS_PER_SECOND;
     set_rtcc(0);
      setup_counters (RTCC_INTERNAL, RTCC_DIV_256);
      enable_interrupts (INT_RTCC);
      enable_interrupts(GLOBAL);
      lcd_init();

   if (enter_gedruckt == istGedruckt)
   {
       if(blockEnterTime == 1)
      {
           printf(lcd_putc,"Block");
           delay_ms(1000);
          blockEnterButton=1;
      }

blockEnterTime=0;
      if (blockEnterButton == 1)
      {
          printf(lcd_putc,"\f NO PRESS");         
      }
      else
       {
         printf(lcd_putc,"\f FREE PRESS");
         delay_ms(2000);

         // Enter 4 nummer   
         printf(lcd_putc,"\f Bitte geben Sie Ihr Nummer ein!");
         ...
      }   
   }            // Enter Taste gedruckt
}               // main             


Jurgens
Guest








PostPosted: Mon May 16, 2005 1:18 pm     Reply with quote

don't you need a loop in your program somewhere?
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