初级会员

- 积分
- 150
- 金钱
- 150
- 注册时间
- 2016-5-7
- 在线时间
- 29 小时
|
10金钱
话不多说,这是简单的51的测试代码, 怎么在32上实现,#include <reg52.h>
//TB6560输入控制端定义
sbit CLK = P1^0;
sbit DIR = P1^1;
sbit ENA = P1^2;
sbit key1 = P3^4;
sbit key2 = P3^5;
/** 函数名称: void Delay(unsigned int cnt)
** 功能描述: 简单的延时函数
** 输 入: cnt:0-65535之间的任意整数
** 输 出: 无
****************************************/
void Delay(unsigned int cnt)
{
while(--cnt);
}
void main()
{
ENA = 0;
DIR = 0;
CLK = 0;
P1 = 0x00;
while(1)
{
if(key1 == 0)
{
Delay(10);
if(key1 == 0)
{
P1= 0xf0;
DIR = 1;
ENA = 1;
CLK = 1;
Delay(1000);//delay函数略
}
}
if(key2 == 0)
{
Delay(10);
if(key2 == 0)
{
P1= 0x0f;
DIR = 0;
ENA = 0;
CLK = 0;
Delay(1000);//delay函数略
}
}
}
}
实现了按键控制步进电机正反转, 想换成32的,PWM控制,有没有人可以给个思路?
|
最佳答案
查看完整内容[请看2#楼]
这个简单啊,PWM信号输出和DIR输出经过与门后去到电机驱动芯片,比方正转DIR = 1,那么按一下按键就将DIR取反就是了
|