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

Interrupt on change.

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







Interrupt on change.
PostPosted: Sun Feb 07, 2010 2:51 pm     Reply with quote

What is the syntax and use of new change on port function.

Regards,
Dan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 07, 2010 6:12 pm     Reply with quote

Here is a test program which shows what the input_change_x() function
does. It's not a finished, useful program. It just displays the "delta"
variable whenever button4 or button5 is pressed or released. Button4
is a pushbutton connected to pin RB4. Button5 is connected to pin RB5.
When a button is pushed, it connects the pin to ground. When it's not
pushed, a pull-up holds the pin at a logic high level.

As a test, I pressed and released button4 four times. Then I pressed
and released button5 three times. It displayed the following output
on the serial terminal. Each pair ("10 10") represents a press and a
release of the button. "10" is the Hex bitmask for pin RB4. "20" is the
hex bitmask for pin RB5.
Quote:

10 10 10 10 10 10 10 10 20 20 20 20 20 20 20 20

I don't want to write a complete "button state detection" program.
I only wanted to make this simple test program:
Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

int8 delta = 0;

#define BUTTON4_MASK 0x10  // Button on pin B4
#define BUTTON5_MASK 0x20  // Button on pin B5

#define ALL_BUTTONS_MASK (BUTTON4_MASK | BUTTON5_MASK)

#int_rb
void rb_isr(void)
{
delta = input_change_b() & ALL_BUTTONS_MASK;
}

//======================================
void main()
{
port_b_pullups(TRUE);
delay_us(10);

input_change_b();    // Init Change_B state
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);

while(1)
  {
   if(delta)
     {
      printf("%X ", delta);
      delta = 0;
     }
  }

}
Guest








PostPosted: Mon Feb 08, 2010 12:05 pm     Reply with quote

Thanks
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