View previous topic :: View next topic |
Author |
Message |
INTO3
Joined: 28 Aug 2013 Posts: 1 Location: korea
|
I want to use RB interrupts |
Posted: Wed Aug 28, 2013 6:23 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Wed Aug 28, 2013 6:40 am |
|
|
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: 19518
|
|
Posted: Wed Aug 28, 2013 7:23 am |
|
|
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. |
|
|
|