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

I want to use RB interrupts

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



Joined: 28 Aug 2013
Posts: 1
Location: korea

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number

I want to use RB interrupts
PostPosted: Wed Aug 28, 2013 6:23 am     Reply with quote

IT can't wake up from sleep.

what problem in this code?

and Anybody help me How to operate RB interrupt for wake up.

Code:

#include <16f84a.h>
#device   pic16f84a    *=8    abc=10             ?
#use delay(clock=4000000)         
#byte   portb = 0x06
#INT_RB
rb_isr(){
}


void main()
{
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
set_tris_b(0xf0);
int i=0;

while(1)
   {
  // delay_ms(500);
  sleep();
  portb = 0xff;
      {
        if(portb == 0x0e)
        {
              portb = 0x07;
              delay_ms(200);
              portb = 0x0f;
             
               i=i+1;
            if(i==1)
            {           
             delay_ms(100);
             
               if(portb == 0x02)
               {
                  reset_cpu();
               }
            }
                        if(i==2)
            {           
             delay_ms(100);
             
               if(portb == 0x02)
               {
                  reset_cpu();
               }
            }
                        if(i==3)
            {           
             delay_ms(100);
             
               if(portb == 0x02)
               {
                  reset_cpu();
               }
            }
                        if(i==4)
            {           
             delay_ms(100);
             
               if(portb == 0x02)
               {
                  reset_cpu();
               }
            }
            if(i==5)
            {
             delay_ms(100);
                portb = 0x0d;
            }
        }
    }
   }
}


temtronic



Joined: 01 Jul 2010
Posts: 9186
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 28, 2013 6:40 am     Reply with quote

you should look at the example code that CCS supplies in the faq section of the manual to see good working code.

one clue is that you don't do anything in the 'interrupt handler'
#INT_RB
rb_isr(){
}

As there's nothing inside the {...}

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19399

View user's profile Send private message

PostPosted: Wed Aug 28, 2013 7:23 am     Reply with quote

Also, general comments:

1) Set-up TRIS before enabling the interrupt.
2) Get into the habit of using the 'traditional' C layout of declaring variables at the start to the code sections. Mid section declarations are a 'non standard' (in C) feature, that CCS 'tries' to support, but it has the habit of causing odd problems if done in large programs. Much safer to get into the habit of using the standard form.
3) Read the data sheet about INT_RB. This will give the hint about what Temtronic is pointing out, and also what else should be done before enabling the interrupt.
4) 'Long term', think about structuring your program to avoid reset_cpu. The later chips like the PIC18's, do have a hardware reset instruction, so can perform a genuine reset. However the PIC16 doesn't, so this can result in the stack becoming unbalanced. Even on chips where this isn't going to happen, it is a slight sign of 'poor thought' in the program structure.
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