永发信息网

急求这个代码的原理图及仿真图

答案:1  悬赏:60  手机版
解决时间 2021-04-15 11:47

#include <iom16v.h>
#include <macros.h>
#include "iodata.h"

unsigned int location_x=0,location_y=50;

void motoX_ctrl(void)
{
unsigned char speed;
speed=adc_x>>3;
if (speed>0x4b)
{
motoX_forward(0x7f-speed);
location_x++;
}
if (speed<0x3b)
{
motoX_backward(speed-5);
location_x--;
}
}
void motoX_forward(unsigned char speed)
{
a3972_X(0b01111111,0b01111111); //ab
delay_temp(speed);
a3972_X(0b00111111,0b01111111); //-ab
delay_temp(speed);
a3972_X(0b00111111,0b00111111); //-a-b
delay_temp(speed);
a3972_X(0b01111111,0b00111111); //a-b
delay_temp(speed);
}
void motoX_backward(unsigned char speed)
{
a3972_X(0b01111111,0b00111111); //a-b
delay_temp(speed);
a3972_X(0b00111111,0b00111111); //-a-b
delay_temp(speed);
a3972_X(0b00111111,0b01111111); //-ab
delay_temp(speed);
a3972_X(0b01111111,0b01111111); //ab
delay_temp(speed);
}
void motoY_ctrl(void)
{
unsigned char speed;
speed=adc_y>>3;
if (speed>0x4b)
{
if (location_y>99) location_y=100;
else
{
motoY_forward(0x7f-speed);
location_y++;
}
}
if (speed<0x3b)
{
if (location_y<2) location_y=1;
else
{
motoY_backward(speed-5);
location_y--;
}
}
}
void motoY_forward(unsigned char speed)
{
a3972_Y(0b01111111,0b01111111); //ab
delay_temp(speed/2);
a3972_Y(0b01001111,0b01111111); //ab
delay_temp(speed/2);
a3972_Y(0b00001111,0b01111111); //ab
delay_temp(speed/2);

a3972_Y(0b00111111,0b01111111); //-ab
delay_temp(speed/2);
a3972_Y(0b00111111,0b01001111); //-ab
delay_temp(speed/2);
a3972_Y(0b00111111,0b00001111); //-ab
delay_temp(speed/2);

a3972_Y(0b00111111,0b00111111); //-a-b
delay_temp(speed/2);
a3972_Y(0b00001111,0b00111111); //-a-b
delay_temp(speed/2);
a3972_Y(0b01001111,0b00111111); //-a-b
delay_temp(speed/2);

a3972_Y(0b01111111,0b00111111); //a-b
delay_temp(speed/2);
a3972_Y(0b01111111,0b00001111); //a-b
delay_temp(speed/2);
a3972_Y(0b01111111,0b01001111); //a-b
delay_temp(speed/2);

}
void motoY_backward(unsigned char speed)
{
a3972_Y(0b01111111,0b00111111); //a-b
delay_temp(speed/2);
a3972_Y(0b01001111,0b00111111); //a-b
delay_temp(speed/2);
a3972_Y(0b00001111,0b00111111); //a-b
delay_temp(speed/2);

a3972_Y(0b00111111,0b00111111); //-a-b
delay_temp(speed/2);
a3972_Y(0b00111111,0b00001111); //-a-b
delay_temp(speed/2);
a3972_Y(0b00111111,0b00100111); //-a-b
delay_temp(speed/2);

a3972_Y(0b00111111,0b01111111); //-ab
delay_temp(speed/2);
a3972_Y(0b00001111,0b01111111); //-ab
delay_temp(speed/2);
a3972_Y(0b01001111,0b01111111); //-ab
delay_temp(speed/2);

a3972_Y(0b01111111,0b01111111); //ab
delay_temp(speed/2);
a3972_Y(0b01111111,0b01001111); //ab
delay_temp(speed/2);
a3972_Y(0b01111111,0b00001111); //ab
delay_temp(speed/2);

}

//
//A3972控制程序,bridge1\bridge2为两个线圈不同的开关状态
//
void a3972_X(unsigned char bridge1,unsigned char bridge2)
{
A3972_CLK_low;
A3972X_ST_low;
a3972_word0(bridge1,bridge2);
A3972X_ST_high;
// A3972X_ST_low;
}
void a3972_Y(unsigned char bridge1,unsigned char bridge2)
{
A3972_CLK_low;
A3972Y_ST_low;
a3972_word0(bridge1,bridge2);
A3972Y_ST_high;
// A3972Y_ST_low;
}
void a3972_word0(unsigned char bridge1,unsigned char bridge2)
{
A3972_DAT_high; //ITRIP = VDAC/4RS
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //Internal 2V
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x80) A3972_DAT_high; //Bridge 2 mode
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x80) A3972_DAT_high; //Bridge 1 mode
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x40) A3972_DAT_high; //Bridge 2 phase
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x40) A3972_DAT_high; //Bridge 1 phase
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x20) A3972_DAT_high; //Bridge2, DAC, bit6
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x10) A3972_DAT_high; //Bridge2, DAC, bit5
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x08) A3972_DAT_high; //Bridge2, DAC, bit4
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x04) A3972_DAT_high; //Bridge2, DAC, bit3
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x02) A3972_DAT_high; //Bridge2, DAC, bit2
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge2&0x01) A3972_DAT_high; //Bridge2, DAC, bit1
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x20) A3972_DAT_high; //Bridge1, DAC, bit6
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x10) A3972_DAT_high; //Bridge1, DAC, bit5
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x08) A3972_DAT_high; //Bridge1, DAC, bit4
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x04) A3972_DAT_high; //Bridge1, DAC, bit3
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x02) A3972_DAT_high; //Bridge1, DAC, bit2
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;
if (bridge1&0x01) A3972_DAT_high; //Bridge1, DAC, bit1
else A3972_DAT_low;
A3972_CLK_high;
A3972_CLK_low;

A3972_DAT_low; //word select=0
A3972_CLK_high;
A3972_CLK_low;
}


//
//A3972初始化程序,根据不同工作模式而定
//
void a3972X_init(void)
{
A3972_CLK_low;
A3972X_ST_low;
a3972_word1();
A3972X_ST_high;
// A3972X_ST_low;
}
void a3972Y_init(void)
{
A3972_CLK_low;
A3972Y_ST_low;
a3972_word1();
A3972Y_ST_high;
// A3972Y_ST_low;
}

void a3972_word1(void)
{
A3972_DAT_high; //idle mode
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //Synchronous Rectification 15 (1=passive 0=active)
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //Synchronous Rectification 14
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //Oscillator Control C1
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //Oscillator Control C0
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //fast-decay time MSB
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_high; //fast-decay time bit2
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //fast-decay time bit1
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //fast-decay time LSB
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //off-time MSB
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //off-time bit3
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_high; //off-time bit2
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //off-time bit1
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //off-time LSB
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_high; //blank-time MSB
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_low; //blank-time LSB
A3972_CLK_high;
A3972_CLK_low;
A3972_DAT_high; //word select=1
A3972_CLK_high;
A3972_CLK_low;
}

谢谢!

最佳答案
你好。
很幸运看到你的问题。
但是又很遗憾到现在还没有人回答你的问题。也可能你现在已经在别的地方找到了答案,那就得恭喜你啦。
可能是你问的问题有些专业了,没人会。或者别人没有遇到或者接触过你的问题,所以帮不了你。建议你去问题的相关论坛去求助,那里的人通常比较多,也比较热心,可能能快点帮你解决问题。
希望我的回答也能够帮到你!
祝你好运~!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
好好赚钱吧!没有钱,你拿什么呵护你的亲情,
什么季节可以补营养 什么季节容易流失营养
作文题目是 那时花开
早产28周婴儿未能存活产妇休假多少天
PSP游戏王GX4
宣城怎么到舒城?
贷款四万月利率是0.0023年利率是多少啊
云南体育运动职业技术学院的简介
抢车位的经验是怎么计算的?
征途升学问题
雷记餐馆这个地址在什么地方,我要处理点事
WOW怎么查看身份证是不是在验证中
QQ密码丢了怎么办
新破天一剑打护法F
法拉利跑车性能最好的是什么型号???
推荐资讯
李小龙大概有多少个徒弟
成都最好的证券公司是哪家?
哪里可以找到非主流唯美图片?
是什么力量让我撑下去的呢?
北方农家的谚语有哪些,一天,天晴,第二天晚上
搜索我们的回忆
广东雅素丽艺术背景墙地址有知道的么?有点事
我刚刚下载的QQ旋舞为什么安装不上?
圣瑞祥壹佰商场地址在什么地方,想过去办事
佳丽石油地址有知道的么?有点事想过去
双鱼座女生最适合做什么工作
求东方神起的手机主题 配诺基亚的5320XM。。
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?