Paste: servo
Author: | crest |
Mode: | c |
Date: | Sat, 17 Jan 2009 17:50:27 |
Plain Text |
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define ever (;;)
volatile uint8_t servo = 0x01;
volatile uint8_t index = 0;
static const uint16_t slot_len = 2500;
volatile uint16_t servo_pos[8] =
{
1000, 1000, 1000, 1000,
1000, 1000, 1500, 2000
};
ISR(_VECTOR( 5))
{
PORTB &= ~(servo);
servo = (servo << 1) | (servo >> 7);
index = (index + 1) & 7;
}
ISR(_VECTOR(13))
{
PORTB |= servo;
OCR1A = servo_pos[index];
TCNT1 = 0x0000;
}
int main (void)
{
PORTB = 0x01;
DDRB = 0xFF;
TIMSK = (1 << OCIE1A) | (1 << OCIE1B);
OCR1A = servo_pos[index];
OCR1B = slot_len;
TCCR1B = (1 << CS10);
sei();
for ever;
}
New Annotation