|
|
View previous topic :: View next topic |
Author |
Message |
JosedeJesusC
Joined: 29 Mar 2013 Posts: 24
|
Simple interrupt code doesn't do anything |
Posted: Sat Oct 19, 2013 7:20 pm |
|
|
Hi Again !!!
I've been trying to make a simple interrupt code but the microcontroller doesn't do anything, why!!!!! it just is in the while loop, I tried with the RB1 interrupt but nothing, I hope don't be inconvenient, the code is this
Code: |
#include<18f26J50.h>
#fuses HSPLL, NOWDT, NOPROTECT, NODEBUG, PLLDIV1, NOCPUDIV, STVREN, NOXINST, NOSTVREN, NODSBOR, NODSWDT, NOWPDIS, NOFCMEN, NOIESO, RTCOSC_T1, NOWPCFG
#USE delay(clock = 48MHZ)
#BYTE INTCON = 0XFF2
#bit GIEH = INTCON.7// setup global all high priority interrupts
#bit GIEL = INTCON.6// setup global all low priority interrupts
#bit INT0IE = INTCON.4// enable interrupts by RB0
#bit INT0F = INTCON.1// Flag if interrupt occurred
#byte INTCON2 = 0XFF1
#bit INTEDG0 = INTCON2.6
#byte INTCON3 = 0XFF0
#bit RBIP = INTCON3.0
#byte RCON = 0xFD0
#bit IPEN = RCON.7
#locate OSCTUNE = 0XF9B
#INT_EXT
void verify_interrupt(void)
{
delay_ms(1);
output_high(PIN_B7);
delay_ms(500);
output_low(PIN_B7);
delay_ms(500);
output_high(PIN_B7);
delay_ms(500);
output_low(PIN_B7);
delay_ms(500);
output_high(PIN_B7);
delay_ms(500);
output_low(PIN_B7);
delay_ms(500);
}
void main(void)
{
set_tris_b(0x01);
setup_oscillator(OSC_PLL_ON);
setup_adc(NO_ANALOGS);
setup_wdt(WDT_OFF);
INTCON = 0X00;
INTCON2 = 0X00;
INTCON3 = 0X00;
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT);
INTEDG0 = FALSE;
IPEN = TRUE;
GIEH = TRUE;
GIEL = TRUE;
output_low(PIN_B7);
while(1)
{
output_high(PIN_B6);
delay_ms(500);
output_low(PIN_B6);
delay_ms(500);
}
}//end of main | I don't use enable_interrupts(global); it's the same behavior and the ASM code is this:
MOVLW C0 //11000000
IORWF FF2,F
using this code part, the pic just execute the interrupt when it's turning on
only the first time but it doesn't anything when the falling edge occurs (I push the button connected to RB1).
.................... enable_interrupts(INT_EXT1);
0180: BSF FF2.4
.................... clear_interrupt(INT_EXT1 by RB1);
0182: BCF FF2.1
.................... INTEDG1 = FALSE; //falling edge
0184: BCF FF1.6
.................... IPEN = TRUE; //priority high
0186: BSF FD0.7
.................... GIEH = TRUE; // enable GLOBAL high priority interrupts
0188: BSF FF2.7
.................... GIEL = TRUE; // enable GLOBAL low priority interrupts
018A: BSF FF2.6
.................... output_low(PIN_B7);
0190: BCF F93.7
0192: BCF F8A.7
I did everything that datasheet says but I don't know where else itÅ› wrong
Best regards!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 19, 2013 10:55 pm |
|
|
Quote: | I tried with the RB1 interrupt but nothing.
#include<18f26J50.h>
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT);
#INT_EXT
void verify_interrupt(void)
{
delay_ms(1);
output_high(PIN_B7);
|
If you want to use RB1 interrupt, you need to use #INT_EXT1.
#INT_EXT is for the RB0 interrupt.
Quote: |
INTCON = 0X00;
INTCON2 = 0X00;
INTCON3 = 0X00; enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT);
INTEDG0 = FALSE;
IPEN = TRUE;
GIEH = TRUE;
GIEL = TRUE; |
Get rid of all this stuff and use CCS functions. Your problem is you
were not using #INT_EXT1 for RB1. Don't start changing everything else
to try to work-around your initial mistake. Use the CCS functions. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19568
|
|
Posted: Sun Oct 20, 2013 2:08 am |
|
|
and also, realise that the chip won't respond to the interrupt, even if everything is done correctly, for a long time, because you are using delays in the interrupt code.
Search here and do some research.
What you are posting, could be done in about half the lines, with _two_ interrupts (RB1, and a timer), a counter, and would then respond properly when the even occurs.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|