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 CCS Technical Support

simple interrupt program do not work!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

simple interrupt program do not work!
PostPosted: Thu Nov 21, 2013 11:28 am     Reply with quote

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;
    }
}
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 1:51 pm     Reply with quote

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);
  }
}
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

Still I have problem.
PostPosted: Thu Nov 21, 2013 4:59 pm     Reply with quote

Thank you!
I have tried your mention.
But still program do not skip to interrupt vector.
I don't know what is wrong.
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 4:59 pm     Reply with quote

What compiler version are you using?
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

my compiler is v5.008
PostPosted: Thu Nov 21, 2013 6:44 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 7:14 pm     Reply with quote

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.
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

I have pull up resistor.
PostPosted: Thu Nov 21, 2013 9:22 pm     Reply with quote

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.
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 9:27 pm     Reply with quote

Quote:
and what is proteus project.


Good
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 10:48 pm     Reply with quote

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 ?
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

No error in circuit.
PostPosted: Fri Nov 22, 2013 12:20 am     Reply with quote

I am sure no error in circuit.
because I have demo2 plus board.
Problem is something else.
What can I for problem.
Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 22, 2013 1:51 am     Reply with quote

When you don't want to answer questions, the person helping you will
stop and leave the thread.
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

I want answer.
PostPosted: Fri Nov 22, 2013 2:14 am     Reply with quote

I want answer and I am korean.
so my english is short.
Please understand me.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Fri Nov 22, 2013 2:38 am     Reply with quote

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);
  }
}
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

LED is ON!
PostPosted: Fri Nov 22, 2013 3:02 am     Reply with quote

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
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

LED is not off.
PostPosted: Fri Nov 22, 2013 5:23 am     Reply with quote

LED remains ON.
when I push button, LED is ON.
Why interrupt don't work.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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