CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

impossible to use RB0 as interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
doudlap



Joined: 10 Aug 2006
Posts: 7

View user's profile Send private message

impossible to use RB0 as interrupt
PostPosted: Thu Aug 10, 2006 1:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 1:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 2:06 pm     Reply with quote

Ok, I have change but my value x no change. Sad
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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 2:14 pm     Reply with quote

See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=27868
doudlap



Joined: 10 Aug 2006
Posts: 7

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 3:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 3:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 3:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 3:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 4:07 pm     Reply with quote

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. Crying or Very sad

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

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 12:23 am     Reply with quote

Sad nobody have an idea ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 1:42 am     Reply with quote

doudlap wrote:
Sad 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

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 4:54 am     Reply with quote

my version is 3.249
t's possible that come of my version ?
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 6:01 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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