Ignition monitor: Initial commit
Implemented: * sleep mode * monitoring portb pin3 * switching portb pin4 Missing: * shutdown guard time
This commit is contained in:
42
src/main.c
Normal file
42
src/main.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define F_CPU 1000000UL
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#define IGNITION_PIN 4
|
||||
#define POWER_PIN 3
|
||||
|
||||
int main(void)
|
||||
{
|
||||
DDRB = 0xff;
|
||||
DDRB &= ~(1 << IGNITION_PIN);
|
||||
PORTB |= (1 << PB0) | (1 << PB1) | (1 << PB2);
|
||||
|
||||
wdt_enable(WDTO_8S);
|
||||
while(1) {
|
||||
wdt_reset();
|
||||
if(PINB & (1 << IGNITION_PIN)) {
|
||||
PORTB |= (1 << POWER_PIN);
|
||||
} else {
|
||||
if(PINB & (1 << POWER_PIN)) {
|
||||
for(uint8_t i = 0; i < 100; ++i) {
|
||||
wdt_reset();
|
||||
_delay_ms(100);
|
||||
}
|
||||
PORTB &= ~(1 << POWER_PIN);
|
||||
}
|
||||
wdt_enable(WDTO_8S);
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
sleep_enable();
|
||||
sleep_cpu();
|
||||
sleep_disable();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user