parent
c3f88152ce
commit
87711a38ca
@ -0,0 +1,62 @@
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
Loading…
Reference in new issue