Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
Thread Tools Display Modes
Old 13th March 2008, 08:34 PM   (permalink)
Experienced Member
 
SeanHatch is on a distinguished road
Send a message via AIM to SeanHatch
Default PIC18F interrupt

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
SeanHatch is offline   Reply With Quote
Old 13th March 2008, 10:54 PM   (permalink)
Experienced Member
 
SeanHatch is on a distinguished road
Send a message via AIM to SeanHatch
Default

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 is offline   Reply With Quote
Old 13th March 2008, 11:52 PM   (permalink)
Experienced Member
aussiepoof has a spectacular aura about
Default

Quote:
Originally Posted by SeanHatch
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 is offline   Reply With Quote
Old 13th March 2008, 11:54 PM   (permalink)
Experienced Member
 
SeanHatch is on a distinguished road
Send a message via AIM to SeanHatch
Default

Quote:
Originally Posted by aussiepoof
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.
SeanHatch is offline   Reply With Quote
Old 14th March 2008, 12:08 AM   (permalink)
Experienced Member
aussiepoof has a spectacular aura about
Default

Cool... just checking before I jumped in :-)

Try:

LATDbits.RD0 = !LATDbits.RD0;

P.
aussiepoof is offline   Reply With Quote
Old 14th March 2008, 12:22 AM   (permalink)
Experienced Member
aussiepoof has a spectacular aura about
Default

Oh, and TRISD = 0b11111110

P.
aussiepoof is offline   Reply With Quote
Old 14th March 2008, 12:29 AM   (permalink)
Experienced Member
 
SeanHatch is on a distinguished road
Send a message via AIM to SeanHatch
Default

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.
SeanHatch is offline   Reply With Quote
Old 14th March 2008, 12:47 AM   (permalink)
Experienced Member
aussiepoof has a spectacular aura about
Default

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.
aussiepoof is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
PIC16F628a Problem generating a RCIE interrupt Norlin Micro Controllers 3 16th January 2008 01:43 AM
Priority Interrupt Controller Stellarcore Datasheet/Parts Requests 14 13th September 2007 04:13 PM
16F877 Timer0 Interrupt Affecting ADC sebana Micro Controllers 13 12th September 2007 09:42 AM
Question about Interrupt tinhnho Micro Controllers 3 11th February 2007 07:07 PM
HANDLING THE INTERRUPT. alamy Micro Controllers 6 26th March 2005 03:37 PM



All times are GMT. The time now is 03:50 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.