pentabug/firmware/main.c

72 lines
1.1 KiB
C
Raw Normal View History

2012-07-17 01:05:27 +02:00
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>
#include "main.h"
2012-07-18 15:55:20 +02:00
static inline void init_pwm(void)
{
2012-07-18 02:34:15 +02:00
//PB1 set to output:
DDRB |= 0b10;
2012-07-18 16:12:48 +02:00
OCR1B = 0xefff; //preselect some default
ICR1 = 0xffff; // TOP-wert
TCCR1A = (1<<COM1B1) | (1<<WGM11); // only b-chan , fastpwm (mode 14)
TCCR1B = (1<<WGM13)|(1<<WGM12) | (1<<CS10); //Fastpwm, no prescale
return
2012-07-18 02:34:15 +02:00
}
2012-07-18 15:55:20 +02:00
static void init_leds(void)
2012-07-17 01:05:27 +02:00
{
//enable LED channels as output
2012-07-18 15:55:20 +02:00
DDRC |= (1 << PORTC0) | (1 << PORTC2) | (1 << PORTC3) | (1 << PORTC1);
PORTC = 1; //one led is on...
return;
}
2012-07-18 02:34:15 +02:00
2012-07-18 15:55:20 +02:00
inline void setleds(uint8_t state)
{
//set leds according to
PORTC |= (state | 0 b00001111);
PORTC &= ~(state | 0 b11110000);
return;
}
2012-07-17 01:05:27 +02:00
2012-07-18 15:55:20 +02:00
static void init_motor(void)
{
//vibration motor on B1:
DDRB |= (1 << PORTB1);
2012-07-17 01:05:27 +02:00
2012-07-18 15:55:20 +02:00
}
2012-07-18 02:34:15 +02:00
2012-07-18 15:55:20 +02:00
static void stupid_pwmtest(void)
{
for (;;) {
2012-07-18 02:34:15 +02:00
OCR1BH = 0;
OCR1BL = 0;
_delay_ms(1);
OCR1BH = 0xff;
OCR1BL = 0xff;
_delay_ms(1);
2012-07-17 01:05:27 +02:00
}
2012-07-18 16:12:48 +02:00
return; //never
2012-07-17 01:05:27 +02:00
}
2012-07-18 15:55:20 +02:00
int main(void)
{
2012-07-18 16:12:48 +02:00
//hardware initialisation:
2012-07-18 15:55:20 +02:00
init_leds();
init_motor();
init_pwm();
2012-07-18 16:12:48 +02:00
//just stupid test for now....
2012-07-18 15:55:20 +02:00
stupid_pwmtest();
//never get here
return;
}