View previous topic :: View next topic |
Author |
Message |
doudlap
Joined: 10 Aug 2006 Posts: 7
|
impossible to use RB0 as interrupt |
Posted: Thu Aug 10, 2006 1:19 pm |
|
|
With the code below, I have a problem, I never pass into my interrupt fonction.
Do you know my problem ?
--------------------------------------------------------
Code: | #device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=9)
//Global declares
static int x;
#int_ext
void INTRB0(void);
main()
{
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT); // Add this line
enable_interrupts(GLOBAL);
while(true)
{
printf("%d",x);
delay_ms(1000);
}
}
#INT_EXT
void INTRB0()
{
x = 999;
printf("%d",x);
delay_ms(500);
} |
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Aug 10, 2006 1:25 pm |
|
|
Try moving the body of the ISR _above_ main() and don't declare it as a function.
Ronald
________________
You know you're old when you can remember 'Five and Dime' stores. |
|
|
doudlap
Joined: 10 Aug 2006 Posts: 7
|
|
Posted: Thu Aug 10, 2006 2:06 pm |
|
|
Ok, I have change but my value x no change.
Have you got an another idea ?
Code: | #FUSES NOWDT //No Watch Dog Timer
#FUSES
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=9)
//Global declares
static int x;
#int_EXT
EXT_isr() {
x = 999;
printf("%d",x);
delay_ms(2500);
}
main()
{
ext_int_edge(L_TO_H);
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT); // Add this line
enable_interrupts(GLOBAL);
while(true)
{
printf("%d",x);
delay_ms(1000);
}
} |
thank for all
doudlap |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
doudlap
Joined: 10 Aug 2006 Posts: 7
|
|
Posted: Thu Aug 10, 2006 3:33 pm |
|
|
okay I have review my code but no success.
question : The pin rb0 of the pic 16f88 will be interrupted by this interruption ?
My new code tested is :
Code: | #include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES
#use delay(clock=16000000)
#int_EXT
EXT_isr() {
output_high(PIN_B7);
}
#use delay(clock=16000000)
main()
{
output_low(pin_b7);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(true)
{
}
} |
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Aug 10, 2006 3:36 pm |
|
|
Add NOLVP to your Fuses. There might be other Fuses that should be inserted as well.
Don't use delay() or printf() in an ISR.
Are you sure you should be using 9bits in your RS232?
You don't need the clear_interrupt() command.
You're trying to stuff a value of 999 into a variable that can only accomodate a max of 255.
Have something like:
x++;
in your ISR to see if it is changing when an interrupt happens.
You don't need 'static' when you declare a Global variable.
Is this the entire program or have you edited things out just to post it? It won't work as you've posted it because you don't have your oscillator Fuse in there among some other setup commands.
Does the program even send anything to the RS232 or does it just sit there acting dead? If it's dead then you definately don't have all of the Fuses and setup commands that are needed.
Post a _complete_ program including all Fuses and setup commands.
Ronald |
|
|
jspencer
Joined: 22 Dec 2003 Posts: 57 Location: Boise, ID USA
|
|
Posted: Thu Aug 10, 2006 3:50 pm |
|
|
First thing I would try is to use the project wizard as it will help you setup your project with the options that you need. This is what I got from the project wizard with just a couple of lines that I added.
Code: | #include <16F88.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#use delay(clock=16000000)
int8 b_flag;
#int_EXT
EXT_isr() {
b_flag = TRUE;
}
void main() {
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
setup_oscillator(False);
ext_int_edge(H_TO_L); // or L_TO_H
output_low(PIN_B7);
b_flag = FALSE;
while (1) {
if (b_flag) {
output_high(PIN_B7);
delay_ms(2000);
// reset to catch next interrupt
output_low(PIN_B7);
b_flag = FALSE;
}
}
} |
Looking at your code you are definitely missing a fuse setting for your crystal/oscillator.
I'm not sure that your pic is even running. |
|
|
doudlap
Joined: 10 Aug 2006 Posts: 7
|
|
Posted: Thu Aug 10, 2006 3:54 pm |
|
|
I haven't use CCS before, so I'am sorry for this problem.
It's the full program. and I search to use the pin B0 as an interrupt because when I will find the solution, i will use all pin of port A and B.
but, actually I'm testing the solution with the software proteus. And can use interrupt whit RB4 to RB7. So i think is a problem in my source code.
in the last code, I have delete the delay and the Rs232.
but the interruption is never call. |
|
|
doudlap
Joined: 10 Aug 2006 Posts: 7
|
|
Posted: Thu Aug 10, 2006 4:07 pm |
|
|
jspencer, before testing lots of possibilites, I used the wizard but no result.
I will test your source code in a real pic and not b the software PROTEUS Because I copy/paste your code but th interrupt no work I don't know why.
oh I have made a new test. I take a 16f876 and the code work perfectly. So why with a 16f88 the result no work ?
probebly the software proteus no work well why the pic 16f88 ?? |
|
|
doudlap
Joined: 10 Aug 2006 Posts: 7
|
|
Posted: Fri Aug 11, 2006 12:23 am |
|
|
nobody have an idea ? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 11, 2006 1:42 am |
|
|
doudlap wrote: | nobody have an idea ? | You said you were going to try on real hardware instead of in the Proteus simulator. How did this test go?
Which version number of the CCS compiler are you using? (see the top of the *.lst file to find this number, it looks like 3.xxx). |
|
|
doudlap
Joined: 10 Aug 2006 Posts: 7
|
|
Posted: Fri Aug 11, 2006 4:54 am |
|
|
my version is 3.249
t's possible that come of my version ? |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Fri Aug 11, 2006 6:01 am |
|
|
1. don't use delay_ms ( ) function inside ISR (). It makes your software hang, you can find an explanation of that using the forum search function
2. Measure with a scope on pin RB0 of your PIC. Is it wired OK ? Measure if you have a transition. Should be on PIN 6 of your IC.
http://ww1.microchip.com/downloads/en/DeviceDoc/30487c.pdf
3. Your PIC is dead?
Try to implement jspencer's code
gl |
|
|
|