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 CCS Technical Support

PIC12F675 INT

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



Joined: 07 Jan 2017
Posts: 16

View user's profile Send private message

PIC12F675 INT
PostPosted: Fri Jan 13, 2017 2:52 pm     Reply with quote

Hi dear friends =) !

I made this code for pic12f675 interrupt and I got it working but I don't know why when I press the button it won't initialize the interrupt until I switch it off. If I hold the pushbutton it won't trigger the interrupt until I leave it. Here is my code.

main.h
Code:

#include <12F675.h>
#device ADC=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset

#use delay(internal=4MHz)
#use STANDARD_IO( A )

main.c
Code:

#include <main.h>

#use fast_io(a)
#INT_EXT

void  EXT_isr(void)
{
if ( !input(PIN_A2) == 1 ) {
output_high(PIN_A0);
delay_ms(3000);
output_low(PIN_A0);
}
}


void main()
{

 enable_interrupts(INT_EXT); // Habilita la interrupción en RB0
enable_interrupts(GLOBAL); // Habilitación general de interrupción
ext_int_edge(H_TO_L); // Config. int. por flanco descendente. (L_TO_H) para ascendente
input(PIN_A2);
set_tris_a(0x4);

   while(TRUE)
   {
     output_high(PIN_A5);
     delay_ms(200);
     output_low(PIN_A5);
     delay_ms(200);
     output_high(PIN_A4);
     delay_ms(200);
     output_low(PIN_A4);
     delay_ms(200);
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 13, 2017 3:10 pm     Reply with quote

Does your button circuit look like this ? Or something else ?
In this circuit, when you press the button it puts Ground on the PIC pin.
When you don't press it, it has 5v on the pin.
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
A2                            --- GND
                               -   
 
ViperARG



Joined: 07 Jan 2017
Posts: 16

View user's profile Send private message

PostPosted: Fri Jan 13, 2017 3:43 pm     Reply with quote

PCM programmer wrote:
Does your button circuit look like this ? Or something else ?
In this circuit, when you press the button it puts Ground on the PIC pin.
When you don't press it, it has 5v on the pin.
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
A2                            --- GND
                               -   
 




Mine was pull down with a 10k resistor, now I tried pull up and it works better, sometimes it miss, and I tried with cables and another switches and does the same thing, sometimes wont register the push... so weird.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 13, 2017 4:34 pm     Reply with quote

Since you have delays in the interrupt and in main(), you will be getting
the interrupts disabled warning. (Do you have compiler warnings
enabled ?). This means you won't get interrupts for the duration of each
delay statement in main(). Your program will seem somewhat unresponsive.

See this CCS faq article for a suggested fix:
http://www.ccsinfo.com/faq.php?page=delay_in_interrupt
It uses two #use delay() statements to generate separate delay routines
for the interrupt code and the code in main(). This removes the conflict.
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