go_away

Author Topic: 16F877A interrupt help  (Read 6664 times)

0 Members and 1 Guest are viewing this topic.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
16F877A interrupt help
« on: October 12, 2008, 10:37:03 AM »
I have little question :- how to give an interrupt through any input pin?

lets say i want to turn on a led connected to Pin A0 every time i press a push button(with pull up resistor connected) which is connected to pin A1?

i searched internet and found a code.in that code push button is connected Pin B0.i modified it to do what i want(turning on leds) except changing the pin which push button is connected(which is B0).

so what i want to know is how to connect push button to a pin other than B0 and execute relevent programme.?

and is it possible to connect more than one push buttons and do different task using more than one external interrupt?

i use CCS C 4.057thanks :)

here is my code

Code: [Select]
#include "D:\PIC C codes\16F877A\intrrupt 1\interrupt1.h"
int x=0;
#int_EXT
void button_isr()
{
delay_ms(20);
if(x==3)
{
x=0;
}
else
{
x++;
}

}



void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   ext_int_edge( H_TO_L );

   // TODO: USER CODE!!
   do{
   if(x==0)
   {
   output_high(PIN_A1);
   output_low(PIN_A2);
   output_low(PIN_A3);
   }
   
   if(x==1)
   {
   output_high(PIN_A2);
   output_low(PIN_A1);
   output_low(PIN_A3);
   }
   
   if(x==2)
   {
   output_high(PIN_A3);
   output_low(PIN_A2);
   output_low(PIN_A1);
   }
   }while(1);

}

I'm Me

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: 16F877A interrupt help
« Reply #1 on: October 12, 2008, 11:40:46 AM »
You can't. If that pin is not an interrupt pin, you can't make it generate an interrupt.
You can fake it however - use a timer to scan the button n times per second, and if it's on (or off, or just transitioned, you decide) you can write some code. And since the timer only triggers in an interrupt, the code will be executed in an interrupt. You can use this method to add "interrupts" to more pins, but it will add more processing overhead.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: 16F877A interrupt help
« Reply #2 on: October 12, 2008, 05:42:23 PM »
You can't. If that pin is not an interrupt pin, you can't make it generate an interrupt.
You can fake it however - use a timer to scan the button n times per second, and if it's on (or off, or just transitioned, you decide) you can write some code. And since the timer only triggers in an interrupt, the code will be executed in an interrupt. You can use this method to add "interrupts" to more pins, but it will add more processing overhead.
well ow to do this timer thing.i'm new to this and dont know how to use timers.any tutorial would be great
thanks
I'm Me

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: 16F877A interrupt help
« Reply #3 on: October 14, 2008, 03:15:08 AM »
You'll find an example of interrupt code for the 16F877 in my sourcecode here:
http://www.societyofrobots.com/robot_sumo.shtml

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: 16F877A interrupt help
« Reply #4 on: October 14, 2008, 03:20:26 AM »
You'll find an example of interrupt code for the 16F877 in my sourcecode here:
http://www.societyofrobots.com/robot_sumo.shtml

thanks I'll check
I'm Me

 


Get Your Ad Here