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

int_ext3

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



Joined: 16 Apr 2015
Posts: 8

View user's profile Send private message

int_ext3
PostPosted: Fri Apr 17, 2015 9:44 am     Reply with quote

I am using port b to switch on motor for a period of time using timer. I chose port b as it has internal pull up resistors and are equipped with timer function. I have written a code that has two push buttons, pin_b0 and pin_b1 using int_ext, int_ext1. The problem is i want to use 6 push buttons. I tried int_ext3 but i don't know which pin it enables. Please help me for the rest of 4 inputs.

Here is my code which works fine for 2 inputs:
Code:

#include <18F8722.h> //select proper pic header file
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)

int i=0;
int j=0;
int k=0;

#INT_TIMER0
void interrupt_tim0() // program automatically jump on ISR when overflow occurred
{
i++;
if(i==3 & j==1) // check for about 5 sec
  {
   output_high(PIN_J6);  // Off the motor again after 5 sec
   output_high(PIN_J4);
   i=0;
   j=0;
   disable_interrupts(INT_RTCC);//disable timer0
  } //end of ISR

if(i==5 & k==1) // check for about 5 sec
  {
   output_high(PIN_J6);  // Off the motor again after 5 sec
   output_high(PIN_J4);
   i=0;
   k=0;
   disable_interrupts(INT_RTCC);//disable timer0
  }
} //end of ISR

#int_ext     //Set external interrupt on pin RB0-INT0
void ext_isr() // program automatically jump on ISR when overflow occured
{
j=1;
enable_interrupts(INT_RTCC);//enable timer0
output_high(PIN_J6);  // ON the motor for 5 seconds, wait for Timer 0 interrupt
output_low(PIN_J4);
}//end of ISR for ext interrupt

#int_ext2     //Set external interrupt on pin RB0-INT0
void ext2_isr() // program automatically jump on ISR when overflow occured
{
k=1;
enable_interrupts(INT_RTCC);//enable timer0
output_low(PIN_J6);  // ON the motor for 5 seconds, wait for Timer 0 interrupt
output_high(PIN_J4);
}//end of ISR for ext interrupt

main()
{
// PWM Configurations
setup_timer_2(T2_DIV_BY_1,255,1); // Set PWM frequency
setup_ccp1(CCP_PWM); // Configure CCP1 to PWM mode
set_pwm1_duty(1023L); // default duty cycle = 100% (Half Speed)

set_tris_b(0xFF);    // Set RB0 to input, RB1-7 output
PORT_B_PULLUPS(1);   //disable internal pull-ups

ext_int_edge(H_TO_L);   // init interrupt triggering for button press
enable_interrupts(INT_EXT); //enable external interrupt
ext_int_edge(1,H_TO_L);   // init interrupt triggering for button press
enable_interrupts(INT_EXT1); //enable external interrupt

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);//Timer 0 setup
enable_interrupts(GLOBAL);

output_high(PIN_J6);  // First Off the motor
output_high(PIN_J4);
while(1); // Wait for the interrupt
}// end of program
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 12:45 pm     Reply with quote

According to the datasheet, INT0-INT3 are on pins B0-B3. So INT3 would be on B3
kishen



Joined: 16 Apr 2015
Posts: 8

View user's profile Send private message

RE:
PostPosted: Sat Apr 18, 2015 6:14 am     Reply with quote

but there is no pin b3 for external connection in pic18f8722 and where should i connect the rest of the push buttons so i can use my interrupt feature.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat Apr 18, 2015 6:44 am     Reply with quote

Quote:

no pin b3 for external connection


what does YOUR datasheet say is connected to pin # 55 ??
Ttelmah



Joined: 11 Mar 2010
Posts: 19381

View user's profile Send private message

PostPosted: Sat Apr 18, 2015 1:06 pm     Reply with quote

I'd also have to say, consider another approach.

Using interrupts for buttons, means you need to have external circuitry to debounce the signals. Buttons in the real world, do not make nice on/off connections. Even if they work when kit is new, after a while buttons will start giving make/break/make/break/make connections, making interrupt responses unreliable. Also having loads of separate interrupt handlers is bulky code.

If you look at things handling lots of buttons they don't do this, Instead they use a timer tick to scan/read as many buttons as needed. They then have software debounce in the handler, so that the key has to remain made for perhaps two successive interrupts before being 'seen'.
Using a timer interrupt, you can have as many buttons as you have pins, just a single interrupt, and reliable handling of debounce, and even have things like key repeat if you want.
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