friendshipz
New Member
hi,
i am currently doing my FYP which requires me to create interrupts for the button on the megapic, the use of the button would be for executing command for (Start, Stop and reset). I have learnt interrupts from my module using chip 18f4520 with the green board but not the megapic. I have been trying to get it working using the megapic but so far i only managed to light up the led light and the interrupt is not working.
my project consist of both hardware and software, i am almost done with the hardware part and doing troubleshooting for the software.
The following code are the one i am currently working with, i simply want to create interrupt for the button so that i can switch on and off for the led light, i hope that you guys can offer me some help and advice so that i can create interrupt for the (start, stop and reset).
for megapic the led light is PORTD and set it to 'low'
#include <p18f4520.h>
void main (void)
{
PORTB = 0; // clear PORTB
TRISBbits.TRISB7 = 1; // assign Interrupt pin
LATD = 0; // Set PORTD output pins state first
TRISDbits.TRISD0 = 0; // PORTD.0 (LED1) is an output
TRISDbits.TRISD1 = 0; // PORTD.1 (LED2) is an output
TRISDbits.TRISD2 = 0; // PORTD.2 (LED3) is an output
TRISDbits.TRISD3 = 0; // PORTD.3 (LED4) is an output
TRISDbits.TRISD4 = 0; // PORTD.4 (LED5) is an output
TRISDbits.TRISD5 = 0; // PORTD.5 (LED6) is an output
TRISDbits.TRISD6 = 0; // PORTD.6 (LED7) is an output
TRISDbits.TRISD7 = 0; // PORTD.7 (LED8) is an output
INTCONbits.GIE = 1; // Global Interrupt Enable Bit
INTCONbits.RBIE = 1; // External Interrupt Enable Bit
INTCONbits.RBIF = 0; // External Interrupt Flag Bit, make the Flag down
INTCON2bits.RBIP = 1; // External Interrupt 0 Edge Select Bit, making it on rising edge
while(1);
}
#pragma interrupt ISR
void ISR (void)
{
if (PORTBbits.RB7 == 0)
{
PORTDbits.RD0 = 0; /* light up*/
}
else
{
PORTDbits.RD0 = 1; // switch off */
}
INTCONbits.INT0IF = 0; // External Interrupt Flag Bit, make the Flag down
}
#pragma code interrupt_vector_section=0x08
void my_interrupt_vector (void)
{
_asm //Inline ASM codes
goto ISR
_endasm
}
#pragma code
Thanks in advance,
suki
i am currently doing my FYP which requires me to create interrupts for the button on the megapic, the use of the button would be for executing command for (Start, Stop and reset). I have learnt interrupts from my module using chip 18f4520 with the green board but not the megapic. I have been trying to get it working using the megapic but so far i only managed to light up the led light and the interrupt is not working.
my project consist of both hardware and software, i am almost done with the hardware part and doing troubleshooting for the software.
The following code are the one i am currently working with, i simply want to create interrupt for the button so that i can switch on and off for the led light, i hope that you guys can offer me some help and advice so that i can create interrupt for the (start, stop and reset).
for megapic the led light is PORTD and set it to 'low'
#include <p18f4520.h>
void main (void)
{
PORTB = 0; // clear PORTB
TRISBbits.TRISB7 = 1; // assign Interrupt pin
LATD = 0; // Set PORTD output pins state first
TRISDbits.TRISD0 = 0; // PORTD.0 (LED1) is an output
TRISDbits.TRISD1 = 0; // PORTD.1 (LED2) is an output
TRISDbits.TRISD2 = 0; // PORTD.2 (LED3) is an output
TRISDbits.TRISD3 = 0; // PORTD.3 (LED4) is an output
TRISDbits.TRISD4 = 0; // PORTD.4 (LED5) is an output
TRISDbits.TRISD5 = 0; // PORTD.5 (LED6) is an output
TRISDbits.TRISD6 = 0; // PORTD.6 (LED7) is an output
TRISDbits.TRISD7 = 0; // PORTD.7 (LED8) is an output
INTCONbits.GIE = 1; // Global Interrupt Enable Bit
INTCONbits.RBIE = 1; // External Interrupt Enable Bit
INTCONbits.RBIF = 0; // External Interrupt Flag Bit, make the Flag down
INTCON2bits.RBIP = 1; // External Interrupt 0 Edge Select Bit, making it on rising edge
while(1);
}
#pragma interrupt ISR
void ISR (void)
{
if (PORTBbits.RB7 == 0)
{
PORTDbits.RD0 = 0; /* light up*/
}
else
{
PORTDbits.RD0 = 1; // switch off */
}
INTCONbits.INT0IF = 0; // External Interrupt Flag Bit, make the Flag down
}
#pragma code interrupt_vector_section=0x08
void my_interrupt_vector (void)
{
_asm //Inline ASM codes
goto ISR
_endasm
}
#pragma code
Thanks in advance,
suki