Last active
August 29, 2015 14:15
-
-
Save JulioAlexanderAguilarAngulo/5bfe1a27f81b9476d2d9 to your computer and use it in GitHub Desktop.
Pic Micro Simple Sleep mode Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Julio Alexander Aguilar Angulo ([email protected]) | |
* ISEN - Toulon: http://www.isen.fr/toulon/ | |
* myblog: alliselectronics.tumblr.com | |
* compilateur: XC8. mcu: 12F1840. Intosc:32KHz | |
* Design notes: | |
* In order to achieve the ULP features on cpu-circuit, | |
* we will use the 32Khz LP internal oscillator to sleep-drive a system | |
*/ | |
#include <xc.h> | |
//#include <stddef.h> | |
#include <pic12lf1840.h> | |
#pragma config CP=OFF, CPD=OFF, BOREN=OFF, WDTE=ON// | |
#pragma config PWRTE=ON, FOSC=INTOSC, MCLRE=ON, IESO=OFF, CLKOUTEN=OFF | |
#pragma config PLLEN=OFF, LVP=OFF, BORV=LO, WRT=OFF//ON | |
#define _XTAL_FREQ 31000//000 uncalibrated 31Khz | |
#define FOSC 31000//000 32Khz ulp | |
// macros to set the wdt engine | |
// ----------------------------------------------------------------- | |
void main() { | |
char counter; | |
// then, setup OPTION as a first thing to do after each reset | |
OPTION_REG = 0b10001111; // GPWU off, GPPU off, | |
// RB0 falling edge int | |
// TMR0 internal source (Fosc/4) | |
// no TMR0 prescalling | |
// optional 1:8 scale | |
WPUA=0; | |
WDTCON =0b0011100; // wdt each 2sec, wdte on by code | |
// just to avoid an undesirable transient, let's reset ports first | |
TRISA = 0b011101; | |
OSCCON = 0b00000010 ; // Set the int-osc= 31khz -LP(uncal) | |
// Ck src int-osc - no pll | |
while(OSCSTATbits.LFIOFR==0){}; //wait untill LPOSC is ready | |
// just to avoid an undesirable transient, let's reset ports here too | |
// As datasheet + users say, reload I/O setup again after reallocate ressources | |
TRISA = 0b011101; | |
while(1) | |
{ | |
CLRWDT(); | |
LATA =0b000000; | |
__delay_ms(12000); | |
LATA =0b00010; | |
SLEEP(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment