Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with interrupt pic16f877a

Status
Not open for further replies.

32bits

Newbie level 3
Joined
Jan 11, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
Hi, I am new to the forum, nice to meet you everyone!

I am working on a project that needs to do an interrupt from external source (RB0/INT) every time that there is a falling edge (TTL), at the moment I am just testing it with a push button, but the final idea is to use a quadrature signal as a input, similar to an encoder signal (I do not know if that can be done yet), but I want to go step by step. Below is my code, basically every time that I push the button it should go to the interrupt but it won't go when I am debugging, I do not know if I am doing something wrong, i would appreciate your help.

By the way I am using boostc compiler and pic16f877a. Many thanks.

Code:
#include <system.h>
 
#ifdef _PIC16F877A
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
#endif
 
#pragma CLOCK_FREQ 16000000
void inter_set();
 
void main()
 
{      
            
        inter_set();
       
        while(1);
        {
                                porte.0 = 0;
        }
       
}
 
void inter_set()
{
 
                 
 
        trisb = 0b11111111;            //PortB as input
        trise = 0b00000000;            //PortE as output
        option_reg = 0b10000000;    // Interrupt on falling edge of RB0/INT pin
        intcon = 0b00000000;          // Clear interrupt
        intcon = 0b10010000;          // Enables the RB0/INT external interrupt                                                                          
 
       
}
 
void interrupt()
{
 
porte.0 = 1; 
clear_bit( intcon, RBIF );  // Clear flag bit
        
}

My configuration:
rb0_int.png
 

Please can anyone give me a hand. cheers.
 

Try enabling the RBIE first, then enabling GIE.

I suspect your code is actually working though. When the interrupt is called it sets PORTE bit 1 but as soon as you return to the main() it gets cleared again. You may only be setting the bit for a few uS before resetting it again, is this what you intended?

Brian.
 

betwixt thanks for you help,
I tried what you said but still does not work.
I tried the code below, but still the same, anyone has any example of external interrupt using boostc compiler. thanks in adavance.

Code:
#include <system.h>

#ifdef _PIC16F877A
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
#endif

#pragma CLOCK_FREQ 20000000 
void Test(void);
void inter_set();


void main()

{    
            
    inter_set();
	
	while(1) { } 
         
     
} 


void inter_set()
{
	portb = 0x00;
	trisb = 0x01;
	set_bit( option_reg, INTEDG );  	// Set for rising edge
	set_bit( intcon, INTE );		    // Enable external interrupt
	set_bit( intcon, RBIE );			// RB change interrupt
    set_bit( intcon, GIE );				// Set global interrupt			       
}


void interrupt(void)
{
   if(INTF)  // External interrupt, button RB0 has been pressed 
   {                  
   Test(); 
   clear_bit( intcon, INTF );      // clear the interrupt 
   } 

}

    
void Test(void){

porte.0 = 1;
delay_10us;

}
 

If I read the code correctly, it should set PORTE bit 0 after the interrupt and do nothing else. Have you set PORTE to be an output and is the bit cleared before you start ?

Brian.
 

You should read the port value next instruction after check interrupt flag. Everyone had the same problem.
 

Solved. The interrupt was happening really fast and I could not see it. Using breakpoints I managed to see it. many thanks again.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top