micael
Joined: 31 Jul 2006 Posts: 4
|
Posted: Sat Aug 05, 2006 3:01 am Post subject: PIC18F452 interrupts |
|
|
Hi,
Im trying to implement sleep and external interrupts with PIC18F452 but i can't wake up the PIC...
Do i have to use Sleep() in the main function or is enough to use it in #pragma interruptlow low_isr
void main(void)
{
initialise();
while (1) // run forever//
{
{_asm CLRWDT _endasm}
}
}
Complete code:
//ID(821401), PN(1033143), UMO version A19,E48 PNGreen //
#include <p18f452.h>
#include <stdio.h>
#include <delays.h>
#include <timers.h>
/////////////////////////////////////////////////////////////
#pragma interruptlow low_isr
void low_isr (void)
{
if(INTCON3bits.INT1IF == 1) //check for rising edge interrupt at RB1
{
sanity_flasher( ; //*flash LED 8 times*/
INTCON3bits.INT1IF=0; //RESET INTERRUPT FLAG!
}
else
{
Sleep(); // go to sleep
}
}
#pragma code
#pragma code low_vector=0x18
void interrupt_at_low_vector(void)
{
_asm GOTO low_isr _endasm
}
#pragma code
//////////////////////////////////////////////////////////////
void sanity_flasher(int flasher) //LED connected at RB1 pin//
{
char c;
c = 1;
while (c<=flasher)
{
if(INTCON3bits.INT1IF == 1) //Turn LED1 OFF (active low)
Delay1KTCYx(1);
LATDbits.LATD7 = 0; //Turn LED1 on (active low)
Delay1KTCYx(1); // delay
c++;
}
}
// main program
void main(void)
{
TRISBbits.TRISB1 = 1; // RB1 Input
TRISDbits.TRISD7 = 0; //RD7 output
INTCON2bits.INTEDG1 = 1; // Rising-edge sensitive
INTCON3bits.INT1IP = 0;
INTCON3bits.INT1IF = 0;
INTCON3bits.INT1IE = 1;
INTCONbits.GIEL = 1;
INTCONbits.GIEH = 1;
while (1) // run forever//
{
{_asm CLRWDT _endasm} // clear the WDT
}
} |
|