|
|
View previous topic :: View next topic |
Author |
Message |
huma
Joined: 23 Jun 2006 Posts: 12
|
Interrupt problem |
Posted: Wed Jul 12, 2006 6:15 am |
|
|
hello,
I m trying to toggle the LED's connected to PORTD of PIC 16F877 based on interrupt from RB0/INT pin when a push button is pressed.
I am simulating this program in Proteus VSM,but i m getting no result.Nothing happens when i push the button and it is also not showing the normal sequence i.e in While loop.
Is there any problem with my code?
I have checked the other topics related to RB0/INT interupt,but everything seems to me ok,i might have missed something and i m not getting whats that.
Please tell me i shall be very thankful to you.
Code: | /*
The program toggles the LED's on/off connected on PORTD when push button is pressed,
causing interrupt on RB0/INT pin
*/
#include "16f877.h"
#fuses XT,NOWDT
#use delay(clock = 4000000)
//---------function prototypes
#int_ext
void external_int_isr(void);
//----------------------------
//---------global variables---
char value = 0xbb;
//----------------------------
void main()
{
set_tris_d(0x00); //LED's connected to portD ,make it output port
set_tris_b(0x01); //set RB0 = 1
port_b_pullups(TRUE);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(true)
{
output_d(value); //output a sequnce on PORTD
}
}
void external_int_isr(void)
{
value = ~value; //complement the sequence
clear_interrupt(int_ext); //clear the INTF flag bit
}
|
|
|
|
Ttelmah Guest
|
Re: Interrupt problem |
Posted: Wed Jul 12, 2006 7:03 am |
|
|
Comments in the code.
Code: | /*
The program toggles the LED's on/off connected on PORTD when push
button is pressed, causing interrupt on RB0/INT pin
*/
#include "16f877.h"
#fuses XT,NOWDT
#use delay(clock = 4000000)
//---------function prototypes
//#int_ext
void external_int_isr(void);
//--- Do _not_ prototype with the interrupt definition - this _must_ be
//--- on the real routine.
//----------------------------
//---------global variables---
char value = 0xbb;
//----------------------------
void main()
{
//set_tris_d(0x00); //LED's connected to portD ,make it
// output port
//set_tris_b(0x01); //set RB0 = 1
//--- The two TRIS statements, actually do nothing. Since you are in
//--- 'standard_io' mode, the compiler will override the TRIS, as soon
//--- as you perform IO. Does not matter, but if you want manual control
//--- of TRIS, select 'fast_io' mode for the ports.
port_b_pullups(TRUE);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(true)
{
output_d(value); //output a sequnce on PORTD
}
}
#int_ext
//You _must_ have the interrupt defintion line here
void external_int_isr(void)
{
value = ~value; //complement the sequence
//clear_interrupt(int_ext); //clear the INTF flag bit
//Do not do this. The compiler already does it for you
}
|
The problem that is stopping it working, is that there isn't a real interrupt handler, because of the wrong placement of the #int definition.
Best Wishes |
|
|
huma
Joined: 23 Jun 2006 Posts: 12
|
Thanks |
Posted: Wed Jul 12, 2006 12:36 pm |
|
|
thanks a lot Ttelmah.it worked i just did as u said.
and i also come to know whts this Standard and fast io are.Thanks. |
|
|
|
|
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
|