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

Long press the key on remote PIC

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



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

Long press the key on remote PIC
PostPosted: Sun Sep 05, 2021 4:41 am     Reply with quote

This is a code that works well.

Is there a way to define a function by long pressing the remote key? But I need a way to long press key on ir remote ?
For example after 3 second pressing in case 16.

Code:

nec_remote_read(){
  unsigned int16 count = 0x00;
  unsigned int8 i;
for(h=0;h<2;h++){
  SET_TIMER1(0); //9
  while(!input(IR_Sensor) && (count < 0x251C))
    count = GET_TIMER1();
  if( (count > 0x251B) || (count < 0x2134))
     return FALSE;
  SET_TIMER1(0x00); //4.5
  count = 0x00;
  while((input(IR_Sensor)) && (count < 0x1388))
    count = GET_TIMER1();
  if( (count > 0x1387) || (count < 0xFA0))
    return FALSE;
  for(i = 0; i < 32; i++){  //32READY
    SET_TIMER1(0x00);
    count=0x00;
    while(!input(IR_Sensor) && (count < 0x28A))
    count=GET_TIMER1();
  if( (count > 0x289) || (count < 0x1F4))
      return FALSE;
    count = 0x00;
    SET_TIMER1(0x00);
  while((input(IR_Sensor)) && (count < 0X708))
      count = GET_TIMER1();
  if( (count > 0X707) || (count < 0X190))
      return FALSE;
  if( count > 0X3E8)                                 
      bit_set(ir_code, (0X1F - i));                     
  else                                             
      bit_clear(ir_code, (0X1F - i));                 
  }
  return TRUE;
}
 }
//---------------------------NEC_Remote----------------------------//
//-----------------------------Set_timer---------------------------//
void set_timer()
{
h_timer=0;
m_timer=0;
int8 timer_counter=0;
while( command !=64){

if(nec_remote_read())
 {
address = ir_code >> 16;
command = ir_code >> 8;
new_command=1;
 }
  if((command==96)&&( new_command==1)) //up key
   {
    if(timer_counter<=7)
    {
    timer_counter++;
    new_command=0;
    }
  }
  if(command==32) //dwn key
  {
  if(timer_counter>=1&( new_command==1))
    {
     timer_counter=timer_counter-1;
     new_command=0;
    }
  }

      switch ( timer_counter){
       Case 0 :
                  h_timer=0;
                  m_timer=0;
            break;
             
       Case 1:
                  h_timer=5;
                  m_timer=0;
            break;
       Case 2 :
                  h_timer=10;
                  m_timer=0;
            break;
       Case 3 :
                  h_timer=15;
                  m_timer=0;
            break;
       Case 4 :
                  h_timer=20;
                  m_timer=0;
            break;     
       Case 5 :
                  h_timer=30;
                  m_timer=0;
            break;
       Case 6 :
                  h_timer=45;
                  m_timer=0;
            break;
       Case 7 :
                  h_timer=60;
                  m_timer=0;
            break;
                              }
//----------------------------IR_receive---------------------------//
void ir_receive(void)
{
   if(nec_remote_read()){
      address = ir_code >> 16;
      command = ir_code >> 8;
     
 switch ( command){
 
            Case 64 :                //circule
                       break;
                     
            Case 72:                 //0n 0ff
                       break;
                     
              Case 120:                //light
                       break;
                 
              Case 16:                 //timer
              set_timer();
                       break;
                 
              Case 96:                 //up
                       break;
             
              Case 32:                 //down
                       break;
             
             
       }

 
if(command!=0)
{

 
}
 //display();
  }
 
}
//----------------------------IR_receive---------------------------//

void main(){
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);            // Set internal oscillator to 32MHz (8MHz and PLL)
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);

while (1)
{
ir_receive();
}
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 05, 2021 4:49 am     Reply with quote

In the manual, in the FAQ sections, there's a 'timed keypress' chunk of code.
it 'looks' for a pin status AND < certain timout value. Pretty sure you can modify to make it work as you need.

Jay
edit: fromt the 'common questions and answers sectio od the CCS C manual....
...

How do I wait only a specified time for a button press?
The following is an example of how to wait only a specific time for a button press.



#define PUSH_BUTTON PIN_A4

int1 timeout_error;

int1 timed_get_button_press(void){

int16 timeout;



timeout_error=FALSE;

timeout=0;

while(input(PUSH_BUTTON) && (++timeout<50000)) // 1/2 second

delay_us(10);

if(!input(PUSH_BUTTON))

return(TRUE); //button pressed

else{

timeout_error=TRUE;

return(FALSE); //button not pressed timeout occurred

}

}
....
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