![]() | ![]() | ![]() |
| | |||||||
| 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? |
| | Thread Tools | Display Modes |
| | (permalink) |
| Experienced 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++);
}
} 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 |
| | |
| | (permalink) |
| Experienced Member | 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! |
| | |
| | (permalink) | |
| Experienced Member | Quote:
Surely the button should be on RB0 and the LED on RD0? P. | |
| | |
| | (permalink) | |
| Experienced Member | Quote:
Yes you are correct. Typo. RB0/INT0 is switching between 5 and 0 volts according to the position of the switch. | |
| | |
| | (permalink) |
| Experienced Member | Cool... just checking before I jumped in :-) Try: LATDbits.RD0 = !LATDbits.RD0; P. |
| | |
| | (permalink) |
| Experienced Member | Oh, and TRISD = 0b11111110 P. |
| | |
| | (permalink) |
| Experienced Member | Ha, I noticed that TRISD thing a few minutes ago 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. |
| | |
| | (permalink) |
| Experienced Member | 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. |
| | |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |