From 87711a38ca4c2bb5403c4eb5940827893ede8779 Mon Sep 17 00:00:00 2001 From: Nidan Date: Sun, 13 Jan 2013 16:35:09 +0100 Subject: [PATCH] hardware initialisation --- firmware/cup.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 firmware/cup.c diff --git a/firmware/cup.c b/firmware/cup.c new file mode 100644 index 0000000..d24fe62 --- /dev/null +++ b/firmware/cup.c @@ -0,0 +1,62 @@ +#include +#include +#include + +#define TEMP_PIN 0 +#define IMPULS0_PIN 1 +#define IMPULS1_PIN 2 +#define TAST_PIN 3 + +#define FET0_PIN 0 +#define FET1_PIN 1 + +uint8_t led_color = 0; + +void io_init(void) +{ + PORTA = (1 << TAST_PIN) | (1 << IMPULS1_PIN) | (1 << IMPULS0_PIN);/* enable pullups on inputs */ + PORTB = 0; + DDRA = (1 << OC0B);/* led outputs ... */ + DDRB = (1 << OC0A) | (1 << FET0_PIN) | (1 << FET1_PIN);/* ... and FET output */ +} + +void led_init(void) +{ + TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << COM0B0) | (1 << WGM1) | (1 << WGM0);/* pwm enable: fast, A not inverted, B inverted */ + TCCR0B = (1 << CS02) | (1 << CS00);/* prescaler / 1024 */ + TCNT0 = 0;/* reset counter */ + OCR0A = OCR0B = led_color; +} + +void led_set(void) +{ + OCR0A = OCR0B = led_color; +} + +void adc_init(void) +{ + ADMUX = (1 << REFS1) | (TEMP_PIN << MUX0);/* Vref = 1.1, pin selection */ + ADCSRA = (1 << ADEN) | (1 << ADATE);/* adc enable, triggered */ + ADCSRB = (1 << ADTS2);/* trigger on counter 0 overflow */ + DIDR0 = (1 << TEMP_PIN);/* disable digital input on adc pin */ + /* result in (ADCH << 8) | ADCL, accessable as ADC? */ +} + +void input_init(void) +{ + GIMSK = (1 << PCIE0);/* interrupt on change on PORT A */ + PCMSK0 = (1 << TAST_PIN) | (1 << IMPULS1_PIN) | (1 << IMPULS0_PIN); +} + +int main(void) +{ + /* if we store the last setting somewhere get calculate led_color from it before calling led_init() */ + + io_init(); + + led_init(); + adc_init(); + input_init(); + + return 0; +}