View previous topic :: View next topic |
Author |
Message |
edi
Joined: 22 Dec 2003 Posts: 82
|
12F683 interrupt problem |
Posted: Sun Sep 30, 2012 1:56 am |
|
|
PIC12F683
Compiler - 4.120
Tool - MPLAB ICD2
The code suppose to blink the LED when the TACT push button is pressed.
All other time stay in sleep.
1. The INT does not work, any idea why?
2. The code start to run the first 8 test blinks only with the ICD2 pluged, but not when the board is stand alone, why?
Thanks
Code: |
#include <12F683.h>
#fuses MCLR,INTRC_IO,PUT,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=4000000)
#byte OSCCAL = 0x80 // 0x80 is the center frequency
#byte porta=0x05
#byte trisa=0x85
#bit LED1 = porta.5
#bit TACT = porta.4 // Push Button connect to GP4 and GND
void init()
{
porta = 0b111111; // | LED | TACT | | | | |
trisa = 0b011111; // | OUT | IN | IN | IN | IN | IN |
PORT_A_PULLUPS(0b110000); // Pull up on GP5 and 4
LED1 = 0; //LED ON
delay_ms(10); // Built-in delay function
LED1 = 1;
delay_ms(50); // Built-in delay function
}
#INT_EXT
void ext_isr() {
if (!TACT)
{
LED1 = 0; //LED ON
delay_ms(10); // Built-in delay function
LED1 = 1;
delay_ms(100); // Built-in delay function
}
}
void main()
{
int8 loop;
init();
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT_H2L);// turn on interrupts
enable_interrupts(GLOBAL);
for (loop=0; loop<8; loop++) // blink LED 8 times at start up
{
LED1 = 0; //LED ON
delay_ms(10); // Built-in delay function
LED1 = 1;
delay_ms(100); // Built-in delay function
}
while(1)
{
sleep();
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Sep 30, 2012 2:43 am |
|
|
The obvious problem is that INT_EXT, is on pin A2, not A4. This is where _reading the data sheet_ is vital.
Best Wishes |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Sun Sep 30, 2012 6:37 am |
|
|
Changed to INT_RA and it works thanks |
|
|
|