程序:
#include
#include
const char zHzhuan[7]={0x06,0x04,0x05,0x01,0x03,0x02,0x00};
const char fanzhuan[7]={0x06,0x02,0x03,0x01,0x05,0x004,0x00};
const int time[5]={4000,3200,2400,1600,800};/*脉冲宽度:0.05m,0.04ms,0.03ms,0.02ms,0.01ms*/
char num; /*将要转动的步数*/
char direct; /*转动方向,0为反转,1为正转*/
char num_run; /*已经转动的步数*/
void main(void)
{
DDRA=0x07;
TCCR1A=0x00;
TCCR1B=0x09;
TIMSK=0x10;
SREG|=0x80;
while(1)
{
;
}
}
#pragma interrupt_handler time1coma:5
void time1coma(void)
{
char i,j;
if(num>9)
{
if(num_run<5) OCR1A=time[num_run]; /*增速*/
else if(num_run>(num-5)) OCR1A=time[num-num_run];/*减速*/
}
else
{
i=(num+1)/2;
if(num_run<(i)) OCR1A=time[num_run]; /*增速*/
else OCR1A=time[num-num_run]; /*减速*/
}
if(num_run {
j=num_run%6;
if(direct==1) PORTA=zhzhuan[j];
else PORTA=fanzhuan[j];
num_run+=1;
}
else
{
OCR1A=0x0fa0;