打印

AD转换控制步进电机

[复制链接]
1708|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
sycma|  楼主 | 2010-2-2 13:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请各位大虾指点一下,综合A/D转换控制电机转速。当输入的模拟电压为0~2V时,电机转速缓慢;当输入模拟电压为2~3V时,电机中速旋转;当输入模拟电压为3~5V时电机高速旋转。
#include "reg52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define p0 P0
unsigned char s;
long int ll;
uchar shu;
uchar a;
sbit CP=P0^0;//CP
sbit DIR=P0^1;//DR
sbit RL=P0^2;//RL
sbit LL=P0^3;
sbit CS=P2^0;
sbit RD1=P2^1;
sbit WR1=P2^2;
sbit EOC=P2^3;
void ADC();
void delay1(uchar c)
{
uchar x,y;;
for(x=c;x>0;x--)
for(y=5;y>0;y--);
}
void delay(uint tt)
{
uint x,y;
for (x=tt;x>0;x--)
for (y=110;y>0;y--);
}
void main(void)
{
s=1;
DIR=0;
while(1)
{
  ADC();   
}
}
void ADC(void)
{
WR1=1;
CS=0;
        delay(2);
WR1=0;
CS=0;
        delay(2);
WR1=1;
CS=0;
    delay(2);
while(!EOC);
RD1=0;
CS=0;
    delay(10);
    shu=P3;
RD1=1;
      if(shu<102) a=6;
if(shu>102&&shu<153) a=3;
if(shu>153) a=1;
        if(s==1)
  {
  CP=0;
  delay1(a);
  CP=1;
  delay1(a);
  DIR=0;
  if(LL==1)
  {
  delay(5);
  if(LL==1)
  {s=2;}
  }
  }   
  if(s==2)
  {
  CP=0;
  delay1(a);
  CP=1;
  delay1(a);
  DIR=1;
  if(RL==1)
  {
  delay(5);
  if(RL==1)
                {s=1;}
}
  }
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

6

帖子

1

粉丝