|
|
View previous topic :: View next topic |
Author |
Message |
Alyn P.
Joined: 01 Aug 2011 Posts: 5 Location: U.K.
|
interrupt(s) sleep/wake on 12f629 an appeal! to betters |
Posted: Tue Aug 02, 2011 5:12 am |
|
|
Hello,
I am a new member, but I am ok with the lowly PIC 12f509. Trying to get to grips with 12f629 as its more versatile, ie interrupts. I have 'devised' a programme but unsure as to the correct syntax and proper positioning of what I want it to do. Basically at introduction of power it flashes a led (which seems to just stay on) in order to tell me power is present. Then supposed to 'go to sleep' and wait for a trigger event, go through another led flash routine, go to sleep and wait for another trigger event (on a different pin) and go through another routine! thus there are two interrupts required at different times. Sleep is important as its a power issue.
I have tried a multitude of permutations and spent an inordinate amount of time trying to teach myself, I really have run out of anymore angles- methinks the more experienced will spot my feeble efforts and put me straight please (and to shame), I will take any flack and bow to betters.
Please see following
Code: |
#include <12F629.h>
#define GP0 PIN_A0 // define GP pins
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
#define INT_GP0 0x0010B08
#define INT_GP3 0x0080B08
#define Int_Ext1 GP3
#define Int_Ext GP0
#use delay (clock=4000000) // oscillator frequency for delay_ms()
// Config: ext reset, no code protect, no watchdog, 4MHz int clock,internal rc osc no clockout
#fuses NOMCLR,NOPROTECT,NOBROWNOUT,NOWDT,INTRC_IO,
//Initialisation
void Int_Ext_isr(void)
{
input(GP0);
}
void Int_Ext1_isr(void)
{
input(GP3);
}
void Main(void)
{
output_high(GP5); //flash led
delay_ms (6000);
output_low (GP5);
// configure timer0: timer mode, prescale = 256 (increment every 256us)
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED);
delay_ms(100);
Ext_Int_Edge(H_To_L); //set up interrupts
Enable_Interrupts(Int_Ext);
Enable_Interrupts(Int_Ext1);
Enable_Interrupts(Global);
delay_ms(100);
sleep();
delay_ms(100);
while (input(GP0)==1); //wake up on pushbutton press
{
output_high(GP2); //flash leds
delay_ms (6000);
output_low (GP2);
delay_ms(100);
output_high(GP1);
delay_ms (6000);
output_low (GP1);
delay_ms(100);
sleep();
delay_ms(100);
}
while (input(GP3)==1); //wake up on pushbutton press
{
output_high(GP1);
delay_ms (6000);
output_low (GP1);
}} |
_________________ Al |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 02, 2011 12:40 pm |
|
|
Here's an example of how to do an interrupt-on-change on one pin:
http://www.ccsinfo.com/forum/viewtopic.php?t=39835&start=3
That example expects you to have an external circuit on Pin A4 that
looks like this:
Code: |
+5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin GP4 |
--- GND
-
|
Instead of using the external pull-up resistor, you could enable
the internal weak pull-up resistor inside the PIC for that pin.
To do this, put this line near the beginning of main():
Code: |
port_a_pullups(0x10); // Enable internal pull-up on pin GP4
|
Note that pin GP3 does not have an internal pull-up available. It must
have an external pull-up added to the pin, as shown in the schematic above.
Also note that the #int_ra interrupt-on-change interrupt is different than
the #int_ext interrupt. |
|
|
Alyn P.
Joined: 01 Aug 2011 Posts: 5 Location: U.K.
|
|
Posted: Tue Aug 02, 2011 3:45 pm |
|
|
thanks for the info, all information is more than greatly received for anyone giving the code more scrutiny! to get it to run/at all. _________________ Al |
|
|
|
|
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
|