// arlotto 2008 c18 // démonstration 18f2520 en mode veille #include #include // configuration #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config PBADEN = OFF #define AliveLed PORTBbits.RB1 #define TrisAliveLed TRISBbits.TRISB1 #define WakeUpLed PORTBbits.RB2 #define TrisWakeUpLed TRISBbits.TRISB2 int t=0 ; int nbtour = 0 ; void main(void) { TrisAliveLed = 0 ; AliveLed = 1 ; TrisWakeUpLed = 0 ; WakeUpLed = 0 ; OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_32 ); INTCONbits.GIEH = 0 ; // pas d'autorisation high INTCONbits.PEIE= 0 ; // Primary Idle mode : cpu off and peripheral clocked when sleeping OSCCONbits.IDLEN = 1 ; OSCCONbits.SCS1 = 0 ; OSCCONbits.SCS0 = 0 ; for (;;) { t++; if(nbtour > 100 ) { nbtour = 0 ; AliveLed = 0 ; INTCONbits.TMR0IF = 0 ; WriteTimer0(0); //RAZ timer 0 _asm SLEEP // reveil dans 32*65536*Th soit environ 2s à 4Mhz _endasm if(INTCONbits.TMR0IF ) { WakeUpLed = 1 ; // Prouve que le reveil est bien fait par T0 ! } t=0; } if(t>1000) { t=0; AliveLed = !AliveLed ; if(nbtour>10){ WakeUpLed = 0 ; } nbtour++; } } }