📄 electromotion.c
字号:
#pragma small
#include "reg66x.h"
#include "commun.h"
unsigned char respiration_ratio[6]= { 1, 2, 3, 4, 5, 6 }; //对应呼吸比1:0.5~1:3
unsigned char respiration_frequency; //呼吸频率
unsigned int tide; //潮气量
unsigned char ratio; //设定的吸呼比
unsigned int motor_speed, //步进电机速度
motor_steps; //步进电机步数
unsigned char data_send[8]={0,0,0,0,0,0,0,0};
main()
{
unsigned int time_inspiration, //吸气时间ms
time_inspiration_fact, //实际步进电机吸气时间ms
time_inspiration_plate, //吸气平台时间ms
time_respiration; //一个呼吸周期时间ms
unsigned long temp = 0;
unsigned char i = 0;
motor_speed = 0;
motor_steps = 0;
time_inspiration = 0;
time_inspiration_fact = 0;
time_inspiration_plate = 0;
byte_responses = 0;
ratio = respiration_ratio[3];
respiration_frequency = 20;
tide = 1200;
time_respiration = (60 * 1000)/(unsigned int)respiration_frequency;
time_inspiration = time_respiration *2 /(2 + ratio);
time_inspiration_fact = time_inspiration * 9/10;
time_inspiration_plate = time_inspiration /10;
motor_steps = tide * 5 / 2; //根据潮气量得到总步数;
temp = (unsigned long)time_inspiration_fact * 1000;
temp /=(unsigned long)motor_steps;
temp -= 66;
temp *= 2;
motor_speed = (unsigned int)temp; //步进电机速度us(1个字=0.5us)
data_send[0] = motor_speed / 0x100;
data_send[1] = motor_speed % 0x100;
data_send[2] = motor_steps / 0x100;
data_send[3] = motor_steps % 0x100;
data_send[4] = time_inspiration_plate / 0x100;
data_send[5] = time_inspiration_plate % 0x100;
data_send[6] = time_respiration / 0x100;
data_send[7] = time_respiration % 0x100;
init_timer();
scon_send(0x80);
while(byte_responses !=0x81);
for(i = 0;i < 8; i++)
{
scon_send(data_send[i]);
}
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -