Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * mega8servotest.c
- *
- * Created: 2013-05-10 19:04:22
- * Author: Olek
- */
- #include <avr/io.h>
- #include <util/delay.h>
- int main(void)
- {
- DDRD=0x00;
- PORTD=0x02;
- //Set PORTB1 pin as output
- DDRB=0xFF;
- //TOP=ICR1;
- //Output compare OC1A 8 bit non inverted PWM
- //Clear OC1A on Compare Match, set OC1A at TOP
- //Fast PWM
- //ICR1=20000 defines 50Hz PWM
- ICR1=20000;
- TCCR1A|=(0<<COM1A0)|(1<<COM1A1)|(0<<COM1B0)|(0<<COM1B1)|
- (0<<FOC1A)|(0<<FOC1B)|(1<<WGM11)|(0<<WGM10);
- TCCR1B|=(0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(1<<WGM12)|
- (0<<CS12)|(1<<CS11)|(0<<CS10);
- //start timer with prescaler 8
- OCR1A = 1500;
- while(1)
- {
- if(bit_is_clear(PIND, 4)){
- //Lewo
- //OCR1A=515;
- }
- if(bit_is_clear(PIND, 5)) {
- //środek
- //OCR1A=1560;
- }
- if(bit_is_clear(PIND, 6)) {
- //Prawo
- //OCR1A=2560;
- }
- if(bit_is_clear(PIND, 7)) {
- //wyłącz wyjśća PWM, odlącz serwo
- //TCCR1A ^= (1<<COM1A0);
- //TCCR1A ^= (1<<COM1A1);
- //PORTB ^= _BV(1);
- }
- OCR1A=515;
- _delay_ms(500);
- OCR1A=1560;
- _delay_ms(500);
- OCR1A=2560;
- _delay_ms(500);
- OCR1A=1560;
- _delay_ms(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement