83 lines
1.4 KiB
C
83 lines
1.4 KiB
C
/*
|
|
* main.c
|
|
*
|
|
* Created on: 10/gen/2014
|
|
* Author: topicchi
|
|
*/
|
|
#define F_CPU 1000000L
|
|
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#define MIN 125
|
|
#define MAX 250
|
|
|
|
int main (void)
|
|
{
|
|
/*unsigned int loops;
|
|
//Port D pins as input, Pull-Up on all Inputs (0xFF)
|
|
//Pushbuttons to GND on D0, D1, D2 and D3
|
|
DDRD=0x00;
|
|
PORTD=0xFF;
|
|
|
|
// Set PORTB1 pin as output
|
|
// LED on B0
|
|
// Servo on OC1A - PB3
|
|
DDRB=0xFF;
|
|
|
|
//TCCR1A = (1<<COM1A1) | (1<<WGM11); //clear on compare
|
|
//TCCR1B = (1<<WGM12) | (1<<WGM13) | (1<<CS11); //presc 8
|
|
TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
|
|
TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS11);
|
|
//ICR1=20000; //period = 20 ms
|
|
ICR1=2559; //period = 20 ms
|
|
OCR1A = 187;
|
|
while(1)
|
|
{
|
|
if(bit_is_clear(PIND, 3)) {
|
|
//Max Position
|
|
OCR1A = MAX;
|
|
loop_until_bit_is_set(PIND, 3);
|
|
}
|
|
if(bit_is_clear(PIND, 0)){
|
|
//increase duty cycle
|
|
OCR1A +=10;
|
|
if (OCR1A >MAX){
|
|
OCR1A =MAX;
|
|
}
|
|
loop_until_bit_is_set(PIND, 0);
|
|
}
|
|
if(bit_is_clear(PIND, 1)) {
|
|
//decease duty cycle
|
|
OCR1A -=10;
|
|
if (OCR1A <MIN){
|
|
OCR1A =MIN;
|
|
}
|
|
loop_until_bit_is_set(PIND, 1);
|
|
}
|
|
if(bit_is_clear(PIND, 2)) {
|
|
//Min Position
|
|
OCR1A = MIN;
|
|
loop_until_bit_is_set(PIND, 2);
|
|
}
|
|
|
|
|
|
//_delay_ms(500);
|
|
if(loops++<500) {
|
|
_delay_ms(1);
|
|
}
|
|
else {
|
|
PORTB = PORTB ^ 0b00000001;
|
|
loops=0;
|
|
}
|
|
*/
|
|
DDRB=0x00;
|
|
PORTB=0xFF;
|
|
while(1)
|
|
{
|
|
PORTB ^= 0b10000000;
|
|
_delay_ms(500);
|
|
}
|
|
return 0;
|
|
}
|
|
|