minid_20050711.c
来自「平缝机的单片机伺服控制系统源代码。本程序为用单片机控制永磁同步电机的低成本方案」· C语言 代码 · 共 73 行
C
73 行
//ICC-AVR application builder : 2005-7-11 14:38:07
// Target : M48
// Crystal: 8.0000Mhz
#include "Minid.h"
//函数定义
void adc_init(void); //ADC initialize
void adc_isr(void);
word AdcPedal(word adcp); //踏板信号转换为对应的控制值
void port_init(void)
{
PORTB = 0xff;
DDRB = 0x00;
PORTC = 0xff; //m103 output only
DDRC = 0x00;
PORTD = 0xff;
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();
timer1_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK0 = 0x00; //timer 0 interrupt sources
TIMSK1 = 0x21; //timer 1 interrupt sources
TIMSK2 = 0x00; //timer 2 interrupt sources
PCMSK0 = 0x00; //pin change mask 0
PCMSK1 = 0x00; //pin change mask 1
PCMSK2 = 0x00; //pin change mask 2
PCICR = 0x00; //pin change enable
PRR = 0x00; //power controller
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
dword i;
word j,jj;
byte d;
init_devices();
//insert your functional code here...
PIDInit (&sPID);
while (1)
{
i = g_DeltaEnc;
j ++;
jj = AdcPedal(j);
sPID.I = 0;
sPID.P = 0;
sPID.SetValue = 5000;
d = PIDCalc(&sPID, i);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?