Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F interrupt

Status
Not open for further replies.

SeanHatch

New Member
Hi;

I have been working on this interrupt for a while now, and I can't get it to work. I'm trying to turn on or off an LED with a push button.

I have a PIC18F452

Here is the code:
Code:
#include <p18cxxx.h> 
#pragma config WDT=OFF 
#pragma config LVP=OFF
#include <ADC.h> 
#include<math.h>
#include<portb.h>

void change(void);

#pragma code HIGH_INTERRUPT_VECTOR = 0x8
void high_ISR (void){

	_asm
	goto change
	_endasm
	
}
#pragma code

#pragma interrupt change
void change(void)
{
  
    
        PORTDbits.RD0 = !PORTDbits.RD0;
	INTCONbits.INT0IF = 0;

}
      

void main()
        {
		
		TRISD = 0b11111111;
		//TRISB = 0b00000000;
      
		RCONbits.IPEN = 1;
		INTCONbits.GIEH = 1;
		OpenRB0INT (PORTB_CHANGE_INT_ON &
					PORTB_PULLUPS_ON &
					FALLING_EDGE_INT);

		
		

	   for(count = 1; count < 10000; count++);
	
           while(1)                        // forever
               {
				//PORTDbits.RD0 = !PORTDbits.RD0;

				
			
               	                //INTCONbits.INT0IF = 1;
			
				for(count = 1; count < 5000; count++);

				
		}

}

I know I'm pretty close. If I uncomment the line INTCONbits.INT0IF = 1, the interrupt functions as it should. So I know that the interrupt is properly coded and stuff.

Also, I know that the button works. I have a multimeter on the RD0 pin, and it is changing from 5V to 0V when I push the button.

Basically, the voltage change on the RD0 pin is not setting the INT0 flag, and I don't know why? Am I missing initializing something?

Thanks
 
Hmm, I cannot even get one of Microchip's interrupts to work. I've tried the one found in this document: alumni.ipt.pt/~wilson/PCBDriller/_private/MPLab_get_started.pdf

(example 4)

and it still won't work!
 
SeanHatch said:
Also, I know that the button works. I have a multimeter on the RD0 pin, and it is changing from 5V to 0V when I push the button.

Basically, the voltage change on the RD0 pin is not setting the INT0 flag, and I don't know why? Am I missing initializing something?
I'm a little confused... the RDO pin can't set the INT0 flag as only RB0 can do that...

Surely the button should be on RB0 and the LED on RD0?

P.
 
aussiepoof said:
I'm a little confused... the RDO pin can't set the INT0 flag as only RB0 can do that...

Surely the button should be on RB0 and the LED on RD0?

P.


Yes you are correct. Typo. RB0/INT0 is switching between 5 and 0 volts according to the position of the switch.
 
Ha, I noticed that TRISD thing a few minutes ago :((, still a no go.

Also, I'm not sure LATDbits will do anything (I don't even know what the difference is; will research), because when I set the INT0 flag myself, everything works as supposed.

I'm still pretty sure its just a matter of setting the flag

Thanks for your input though, I'll keep working.
 
Ok... you need to do the following I think.

In the interrupt routine read port B, and set INTCON.RBIF RB0 to zero to clear the external interrupt.

P.
 
Status
Not open for further replies.

Latest threads

Back
Top