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

12F683 interrupt problem

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



Joined: 22 Dec 2003
Posts: 82

View user's profile Send private message

12F683 interrupt problem
PostPosted: Sun Sep 30, 2012 1:56 am     Reply with quote

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: 19394

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 2:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 6:37 am     Reply with quote

Changed to INT_RA and it works thanks
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