
Это я уже понял, интересно получаеться человек тебе говорит, что тут всего два проводка спаять, и програмки готовые есть. А потом начинет выесняться что не два проводка а 200 да и програмку самому писать надо. Стабильности нет

#include <io2313v.h>
#include <macros.h>
void port_init(void);
void timer0_init(void);
void init_devices(void);
void delaysa(unsigned int mks);
unsigned char deltaServo1 = 100;
unsigned int maxServo1 = 4000;
unsigned int minServo1 = 900;
void nomovieServo1(void);
const int period = 30800; //period = 20 ms
int N = 2497; //neutral servo = 1.5 ms
//TIMER0 initialize - prescale:256
// desired value: 200Hz
// actual value: 200,321Hz (0,2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop timer
TCNT0 = 0x3D; //set count
TCCR0 = 0x04; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:7
void timer0_ovf_isr(void)
{
TCNT0 = 0x3D; //reload counter value
if (PIND==0x04)
forwardServo1(deltaServo1);
if (PIND==0x08)
backwardServo1(deltaServo1);
if((PIND!=0x04)&&(PIND!=0x08))
nomovieServo1();
}
//The first servo
void forwardServo1(unsigned char deltaServo1)
{
if(N<maxServo1)
{
N=N+deltaServo1;
PORTB|=0x10;
delaysa(N);
PORTB&=~0x10;
delaysa(period);
}
}
void backwardServo1(unsigned char deltaServo1)
{
if(N>minServo1)
{
N=N-deltaServo1;
PORTB|=0x10;
delaysa(N);
PORTB&=~0x10;
delaysa(period);
}
}
void nomovieServo1(void)
{
N=N-0;
PORTB|=0x10;
delaysa(N);
PORTB&=~0x10;
delaysa(period);
}
void delaysa(unsigned int mks)
{
while(mks>0)
{
mks--;
}
}
//Init ports
void port_init(void)
{
PORTB = 0x00;
DDRB = 0xFF;
PORTD = 0x0C; // for buttons
DDRD = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
MCUCR = 0x00;
GIMSK = 0x00;
TIMSK = 0x02;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
while(1);
}
#include <io2313v.h>
#include <macros.h>
void port_init(void);
void init_devices(void);
void delaysa(unsigned int mks);
void forward(unsigned char delta);
void backward(unsigned char delta);
void nomovie(void);
const int period = 30800; //period = 20 ms
int N=2497;//neutral servo = 1.5 ms
unsigned char delta = 20;//skorost` perekladki
void forward(unsigned char delta)
{
if(N<4000){
N=N+delta;
PORTB|=0xFF;
delaysa(N);
PORTB&=~0xFF;
delaysa(period);
}
}
void backward(unsigned char delta1)
{
if(N>900){
N=N-delta;
PORTB|=0xFF;
delaysa(N);
PORTB&=~0xFF;
delaysa(period);
}
}
void nomovie(void)
{
N=N-0;
PORTB|=0xFF;
delaysa(N);
PORTB&=~0xFF;
delaysa(period);
}
void delaysa(unsigned int mks)
{
while(mks>0){
mks--;
}
}
void port_init(void)
{
PORTB = 0x00;
DDRB = 0xFF;
PORTD = 0x0C;// for buttons
DDRD = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GIMSK = 0x00;
TIMSK = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
main()
{
init_devices();
while(1){
if (PIND==0x08)
forward(delta);
if (PIND==0x04)
backward(delta);
if((PIND!=0x04)&&(PIND!=0x08))
nomovie();
}
return(0);
}
Тимофей писал(а):Купил я сегодня atmega8-8pi (кстати, 2313 у меня называлась at90s2313-10pi, цифра-это частота кварца, как я понимаю?)
Вернуться в Новичкам или основы основ роботостроения.
Сейчас этот форум просматривают: Yandex [Bot] и гости: 0