all sample and legacy code thrown out of main

This commit is contained in:
john stone 2012-08-06 13:25:33 +02:00
parent 634ce4562c
commit 102f482d8e

View File

@ -10,42 +10,51 @@
static void init_sampletimer(void)
{
// Timer 0
// set timer0 to CTC & prescaler 64 == 125k
/*
* Timer 0
*/
/* set timer0 to CTC & prescaler 64 → 125kHz increment */
TCCR0A = (1 << WGM01);
TCCR0B = (1 << CS00) | (1 << CS01);
// count up to 5 :
OCR0A = 3;
OCR0A = 3; /* TOP */
TCNT0 = 0;
// enable interrupt
/*enable interrupt*/
TIMSK0 |= (1<<OCIE0A);
}
static inline void init_pwm(void)
{
// PB2 set to output:
/* set PB2 as output (buzzer pwm port):*/
DDRB |= (1 << PORTB2);
OCR1B = 0x001F; // preselect some default
ICR1 = 0x00FF; // TOP-wert
TCCR1A = (1 << COM1B1) | (1 << WGM11); // only b-chan , fastpwm (mode 14)
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10); // Fastpwm, no prescale
/* analog value preselection :*/
OCR1B = 0x007F;
/* Top value. Timer overflows here. Thus we have a resulting 8bit pwm */
ICR1 = 0x00FF;
/* only b-chan , fastpwm (mode 14), no prescale */
TCCR1A = (1 << COM1B1) | (1 << WGM11);
TCCR1B = (1 << WGM13 ) | (1 << WGM12) | (1 << CS10);
// TIMSK1 |= (1 << OCIE1B); //enable timer 1 Output compare
return;
}
static void init_leds(void)
{
// enable LED channels as output
DDRC |= (1 << PORTC0) | (1 << PORTC2) | (1 << PORTC3) | (1 << PORTC1);
PORTC = 1; //one led is on...
/* enable LED channels as output */
DDRC |= (1 << PORTC0) | (1 << PORTC2) |
(1 << PORTC3) | (1 << PORTC1) ;
/* initially one led is on */
PORTC = 1;
return;
}
inline void setleds(uint8_t state)
{
// set leds according to
/* set leds according to */
PORTC |= (state | 0b00001111);
PORTC &= ~(state | 0b11110000);
return;
@ -53,8 +62,9 @@ inline void setleds(uint8_t state)
static void init_motor(void)
{
// vibration motor on B1:
/* vibration motor on B1, initially off: */
DDRB |= (1 << PORTB1);
PORTB &= ~( 1<<PORTB1);
}
@ -62,51 +72,27 @@ static void init_motor(void)
int main(void)
{
// hardware initialisation:
/* hardware initialisation: */
init_leds();
// init_motor();
init_pwm();
init_sampletimer();
/* syntesizer initialisation */
synth_init();
// OCR1B = 0x00F0;
/* here the show begins:*/
sei();
while(1) {}
for(;;) /* ever */ ;
// never get here
return 0;
/* never */ return 0;
}
// 25kHz
ISR(TIMER0_COMPA_vect)
{
// test stuff
/*
static uint16_t counter = 0;
static uint16_t pulsewidth = 0;
static uint16_t maxcounter = 0x133;
static uint16_t pulsecounter = 0;
counter++;
if (counter > maxcounter){
counter = 0;
};
pulsecounter++;
if (pulsecounter > 0x300){
pulsecounter = 0;
pulsewidth++;
if (pulsewidth > maxcounter){
pulsewidth = 0;
}
}
OCR1B = ((counter > pulsewidth) ? 0xff : 0x00);
*/
/* calculate next analog sample value in synth mixer:*/
OCR1B = synth_mix();
}