I'm using a servo motor with atmega32A MCU. I want to turn the motor by sending the degree to a function. Here is my main method.
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "servo.h"
int main(void)
{
DDRC = 0b00000001;
PORTC = 0x00;
while(1)
{
turnTo(90);
}
}
And this is my Servo motor code.
#ifndef F_CPU
#define F_CPU 8000000UL // 8 MHz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
int turnTo(double degree){
int pulse=(degree*500/90)+1000;
PORTC = 0x01;
_delay_us(pulse);
PORTC = 0x00;
return 0;
}
I tried the below answers. But anything didn't work. How can I fix this?
How to fix error message "__builtin_avr_delay_cycles expects a compile time integer constant make"?