在
单片机中设计一段智能雨刷器的程序,此处雨滴感应模块用滑动变阻器代替,写了以下程序可是只能实现一种进步电机速度,无法实现根据滑动变阻器值改变 ,速度也改变。是程序还是
电路图有什么问题吗?
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define MotorData P1
uchar phasecw[4] ={0x08,0x04,0x02,0x01};//Õýת µç»úµ¼Í¨ÏàÐò D-C-B-A
uchar phasecw1[4] ={0x08,0x04,0x02,0x01};
uchar phasecw2[4] ={0x08,0x04,0x02,0x01};
uchar phaseccw[4]={0x01,0x02,0x04,0x08};//·´×ª µç»úµ¼Í¨ÏàÐò A-B-C-D
uchar phaseccw1[4]={0x01,0x02,0x04,0x08};
uchar phaseccw2[4]={0x01,0x02,0x04,0x08};
uchar temp,flg;
sbit ST=P3^0;
sbit OE=P3^0;
sbit EOC=P3^0;
sbit CLK=P3^0;
uchar count;
uchar getdata;
//msÑÓʱº¯Êý
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<112;j++);
}
//˳ʱÕëת¶¯
void MotorCW(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phasecw
;
Delay_xms(40);
//תËÙµ÷½Ú
}
}
void MotorCW1(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phasecw;
Delay_xms(4);
//תËÙµ÷½Ú
}
}
void MotorCW2(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phasecw;
Delay_xms(1);
//תËÙµ÷½Ú
}
}
void MotorCCW(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phaseccw;
Delay_xms(500);
//תËÙµ÷½Ú
}
}
void MotorCCW1(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phaseccw;
Delay_xms(100);
//תËÙµ÷½Ú
}
}
void MotorCCW2(void)
{
uchar i;
for(i=0;i<4;i++)
{
MotorData=phaseccw;
Delay_xms(10);
//תËÙµ÷½Ú
}
}
//ֹͣת¶¯
void MotorStop(void)
{
MotorData=0x00;
}
void main (void)
{
uint i;
ET0=1;
ET1=1;
EA=1;
TMOD=0X12;
TH0=246;
TL0=246;
TR0=1;
Delay_xms(50);//µÈ´ýϵͳÎȶ¨
while(1)
{
ST=0;
ST=1;
ST=0;
while(EOC==0){;}
OE=1;
getdata=P0;
OE=0;
temp=getdata;
for(i=0;i<500;i++)
if(temp<=3){MotorCW();}
Delay_xms(500);
if(temp>3&&temp<=6){MotorCW1();}
Delay_xms(500);
if(temp>6&&temp<=12){MotorCW2();}
Delay_xms(500);
if(temp==0){Motorstop();}
Delay_xms(500);
}
}
void timer1(void) interrupt 1
{
CLK=~CLK;
}
-
一周热门 更多>