📄 sivo4.c
字号:
#include <avr/io.h>
#include <avr/signal.h>
#define uchar unsigned char
#define uint unsigned int
//规定开始减速时的剩余点数
#define speed_low 560
//最高速度,9位PWM
#define speed_hi 510
//how much moto running
int run,speed_add=0; //run是电机要走过的点数
uint a;
unsigned int howlong=0; //run how much
void delay(unsigned int t)
{
for(;t>0;t--);
}
void init()
{
run=280; //旋转的总点数
DDRB=0XFF; //PORTB is setting on out
DDRD=0X20; //设置OC1A为输出
PORTB=0X7F; //PORTB is "1"
TCCR1A=0x82; //OC1A is "0",9 BITS PWM C3,1;;;83,0
TCCR1B=0X42; //噪声消除,上升捕获 bu neng yong ping bi
TCNT1=0; //initial volue
SREG=0X80; //总中断开
TIMSK=0X20; //open the capture interrupt
if(run<=840) OCR1A=300; //3圈内中速启动,
else OCR1A=510; //全速启动
}
//==================================================
SIGNAL(SIG_INPUT_CAPTURE1) //T1捕获中断
{
TIMSK=00; //close capture interrupt
PORTB=0X00; //PB灯闪亮
delay(3);
PORTB=0X7f;
if(run>=1)run--; //每次中断剩余旋转点数减1
else if(run==0) //规定的点数走完停,等待给run送新值
{ //run=0;
OCR1A=0;
PORTB=0XFF;
//delay(10000);
while(run==0);
}
if(run<=speed_low) //当到达减速值时开始减速
{
if(OCR1A>57)OCR1A-=1; //限制最低转速
}
TIMSK=0X20; //open capture interrupt
}
//==============================================
int main (void)
{
init();
// while(1);
while(1)
{
// if((b%200)==0)uart_putchar(0xff); //发送测试数据
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -