Description du besoin : faire clignoter une balise sud la nuit.
Présentation succincte du µC

int main (void)
{
DDRB |= _BV(LED); // PBx as output
// configure negative input of analog comparator as AIN1 (Cf p124)
// default value
ADCSRB &= ~ _BV(ACME);
// activate AC (def value)
ACSR &= ~ _BV(ACD);
// Select internal 1.1V reference
ACSR |= _BV(ACBG);
// init done, blink a little
blink_init(LED);
while (1)
{
if ( bit_is_set(ACSR, ACO) ) {
// ACO is set --> dark, switch on led
// PORTB |= _BV(LED);
blink(LED);
}
else {
// ACO is not set --> light, switch off led
PORTB &= ~ _BV(LED);
}
}
return (0);
} /* main */
#define sOFF 0
#define sBLINK 1
volatile int state;
/** Set state from ACO
* @return the state
*/
int setState (void)
{
if (bit_is_set (ACSR,ACO))
return sBLINK;
else
return sOFF;
}
/** Interrupt handler for Analog Comparator
*/
ISR(ANA_COMP_vect)
{
state = setState();
}
/** MAIN
*/
int main (void)
{
DDRB |= _BV(LED); // PBx as output
// TODO: activate internal pull-up
// configure negative input of analog comparator as AIN1 (Cf p124)
// default value
ADCSRB &= ~ _BV(ACME);
// activate AC (def value)
ACSR &= ~ _BV(ACD);
// Select internal 1.1V reference
ACSR |= _BV(ACBG);
// Interrupt on AC output toggle
ACSR &= ~ ( _BV(ACIS1) | _BV(ACIS0) );
// Activate analog comparator interrupt
ACSR |= _BV(ACIE);
sei(); // enable global interrupts
state = setState();
// init done, blink a little
blink_init(LED);
while (1)
{
if ( state == sBLINK ) {
// ACO is set --> dark, switch on led
// PORTB |= _BV(LED);
blink(LED);
}
else { // state == sOFF
// ACO is not set --> light, switch off led
PORTB &= ~ _BV(LED);
}
}
return (0);
} /* main */
sur piles, donc nécessité d'économiser l'NRJ
- Power reduction Register (PRR) p39 pour desactiver des modules
- timer1
- timer0
- USI : oui
- ADC : desctive aussi AnalogComp
- disable ADC
- disable analog comparator (Idle, ADC noise reduction) et tout le temps si internal voltage
- brown-out detection
- internal voltahe (désactivé si inutilisé par BOD, AnalogComp ou ADC)
- watchdog timer
- port pins : cf p59
- input
- activate internal pull-up si non connectée
- desctiver input buffers (DIDR0 p125)
mesures à l'ampèremètre clignotement, reveil par inetr détection de nuit
solution finale avec photos et code tout petit projet mais permet d'appréhender quelques fonctions avancées des AVRs
|