View previous topic :: View next topic |
Author |
Message |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
simple interrupt program do not work! |
Posted: Thu Nov 21, 2013 11:28 am |
|
|
I am studying interrupt.
but simple test program don't skip to interrupt vector.
What is the problem?
Thank your time.
Code: |
#DEVICE pic16f1937
#include <16f1937.h>
#use delay(clock = 500000)
#fuses NOPROTECT,NOLVP,NOWDT
#byte INTCON = 0x0b
#byte PORTB =0x0d
#byte PORTC = 0x0e //PORTC
#byte TRISB = 0x8d
#byte TRISC = 0x8e
#byte LAtC = 0x10E
#int_ext
void ext_isr()
{
bit_clear(INTCON,1);
PORTB=0; // when RB0 is low turn off LED
delay_ms(1000);
}
void main()
{
set_tris_b(0x01);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while (1)
{
PORTB=0xff;
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Thu Nov 21, 2013 1:51 pm |
|
|
I'd double check that you've got the pin wired up you think you do. And that you want it to interrupt on the falling edge.
The delay_ms(1000); call inside your ISR is frowned upon. I do not know if it is the root of your problem.
Try this. Untested, but it generates very similar code to yours and the delay call is no longer in the ISR. Instead you set a bit in the ISR and poll for it in the main loop.
Code: | #DEVICE pic16f1937
#include <16f1937.h>
#use delay(clock = 500000)
#fuses NOPROTECT,NOLVP,NOWDT
#use FAST_IO(B)
short int pause = 0;
#INT_EXT
void ext_isr()
{
output_b(0x00); //when RB0 is low turn off LED
pause = 1;
}
void main(void)
{
set_tris_b(0x01);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
if(pause)
{
pause = 0;
delay_ms(1000);
}
else
output_b(0xFF);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
Still I have problem. |
Posted: Thu Nov 21, 2013 4:59 pm |
|
|
Thank you!
I have tried your mention.
But still program do not skip to interrupt vector.
I don't know what is wrong. |
|
![](templates/subSilver/images/spacer.gif) |
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Thu Nov 21, 2013 4:59 pm |
|
|
What compiler version are you using? |
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
my compiler is v5.008 |
Posted: Thu Nov 21, 2013 6:44 pm |
|
|
Thank you so much for your time.
My compiler version is v5.008.
I think that has nothing to do with problem.
How can I solve problem. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 21, 2013 7:14 pm |
|
|
What is your circuit on Pin B0 ? If you're using a switch, it should look
like this. You must have the pull-up resistor.
Code: |
+5v
|
<
> 4.7K
< ___ Push button switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
Quote: |
#DEVICE pic16f1937
#include <16f1937.h>
#use delay(clock = 500000)
#fuses NOPROTECT,NOLVP,NOWDT
#use FAST_IO(B) |
You don't need the #device line. It's already in the the 16F1937.h file.
Also, why are you using such a low oscillator frequency for the PIC ?
Why only 500 KHz ?
Also, where is your oscillator fuse ? Because you don't have one, I think
this is probably a Proteus project. |
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
I have pull up resistor. |
Posted: Thu Nov 21, 2013 9:22 pm |
|
|
Thank you.
I have pull up resistor.
and I have removed #device line.
and I use internal oscillator.
but I still have problem.
How can I solve problem.
and what is proteus project. |
|
![](templates/subSilver/images/spacer.gif) |
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Thu Nov 21, 2013 9:27 pm |
|
|
Quote: | and what is proteus project. |
Good |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 21, 2013 10:48 pm |
|
|
What pin is used for your LED ?
The LED schematic should look like this:
Code: |
PIC
pin 330 ohms LED
?? ---/\/\/\/------->|----
|
|
----- Ground
---
- |
What is your series resistor value and what PIC pin is connected to it ? |
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
No error in circuit. |
Posted: Fri Nov 22, 2013 12:20 am |
|
|
I am sure no error in circuit.
because I have demo2 plus board.
Problem is something else.
What can I for problem.
Thank you. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 22, 2013 1:51 am |
|
|
When you don't want to answer questions, the person helping you will
stop and leave the thread. |
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
I want answer. |
Posted: Fri Nov 22, 2013 2:14 am |
|
|
I want answer and I am korean.
so my english is short.
Please understand me. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Fri Nov 22, 2013 2:38 am |
|
|
There is an old rule of thumb on this board.
The _first_ thing you should do before posting, is ensure that your chip is actually working. A simple loop (no interrupts etc.), flashing an LED.
Does it flash?.
Does it flash at the right frequency.
It's like saying the first thing to try on a motor car, is if you can start the engine?.
I doubt if your chip is running at all. You are not specifying an oscillator. The default I think will be 'ECH', so unless you have an external oscillator attached to the chip, nothing will run at all. Also the default will be for MCLR to be enabled, so the chip will not run until the MCLR pin is pulled high. You are a bit like the person trying to go motor racing, before they can drive a car....
Code: |
#DEVICE pic16f1937
#include <16f1937.h>
#use delay(clock = 500000)
#fuses INTRC_IO,NOPROTECT,NOLVP,NOWDT,NOMCLR
#use FAST_IO(B)
short int pause = 0;
#INT_EXT
void ext_isr()
{
output_b(0x00); //when RB0 is low turn off LED
pause = 1;
}
void main(void)
{
set_tris_b(0x01);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
if(pause)
{
pause = 0;
delay_ms(1000);
}
else
output_b(0xFF);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
LED is ON! |
Posted: Fri Nov 22, 2013 3:02 am |
|
|
Thank you.
LED is ON.
my test board is demo2 plus board.
so hardware is perfect.and simple loop(no interrupt) is work correctly.
I don't know why the interrupt is not working.
Last edited by pkipyy on Fri Nov 22, 2013 5:39 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
pkipyy
Joined: 21 Nov 2013 Posts: 25
|
LED is not off. |
Posted: Fri Nov 22, 2013 5:23 am |
|
|
LED remains ON.
when I push button, LED is ON.
Why interrupt don't work. |
|
![](templates/subSilver/images/spacer.gif) |
|