欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
單片機(jī)調(diào)速程序 一直閃 速度很慢 全速完全不行 小車抖的厲害
[打印本頁]
作者:
zxc3663441
時(shí)間:
2018-12-6 17:37
標(biāo)題:
單片機(jī)調(diào)速程序 一直閃 速度很慢 全速完全不行 小車抖的厲害
#include "STC15Fxxxx.h"
#include "LCD1602.h"
#include "delay.h"
#include "Motor.h"
#include "GPIO.h"
sbit ENA=P2^5;
sbit ENB=P2^4;
sbit key=P2^7;
sbit SetSpeedkey=P2^6;
u16 T1InterruptCount=0,MotorPulsCount=0,MotorSpeed=0;
u16 SetSpeed=0;
u8 a=0,b=0,c=0;
void Int0Init( )
{
IT0=1;
EX0=1;
EA=1;
}
void Timer1Init( )
{
AUXR &= 0xBF;
TMOD &= 0x0F;
TL1 = 0x00;
TH1 = 0x4C;
TF1 = 0;
TR1 = 1;
TR0 = 1;
ET1=1;
EA=1;
}
void Timer3Init(void) //1??@11.0592MHz
{
T4T3M |= 0x02;
T3L = 0xCD; //每過1ms 中斷一次
T3H = 0xD4;
T4T3M |= 0x08;
IE2 =IE2|0x20;
}
void SpeedSet()
{
if(0==SetSpeedkey)
{
DelayMS(10);
if(0==SetSpeedkey)
{
SetSpeed=SetSpeed+10;
if(SetSpeed>100)
SetSpeed=50;
while(!SetSpeedkey);//等待釋放
}
}
}
void main( )
{
bit KeyFlag=0;
GPIOInit( );
LCD_Init( );
Int0Init( );
Timer1Init( );
Timer3Init( );
MotorStop( );
while(1)
{
if( 0==key )
{
DelayMS( 10 );
if( 0==key )
{
KeyFlag=!KeyFlag;
while( !key );
if( KeyFlag )
MotorGoHead( );
else
MotorStop( );
}
}
SpeedSet();
if(MotorSpeed<SetSpeed)
{
a++;
c++;
}
LCD_Write_String( 6,0,"SetSpeed" );
LCD_Write_MultChar( 0,1, c );
LCD_Write_MultChar( 0,0,a );
LCD_Write_String( 6,1," MotorSpeed" );
}
}
void Int0_ISR( void ) interrupt 0
{
MotorPulsCount++;
IE0=0;
}
void Timer1_ISR( void ) interrupt 3
{
T1InterruptCount++;
if(T1InterruptCount>=20)//1????
{
TR1=0;
MotorSpeed=MotorPulsCount*3;//MotorPulsCount*60/20/4
MotorPulsCount=0;
TR1=1;
T1InterruptCount=0;
}
}
void Timer3_ISR( void ) interrupt 19
{
b++;
// if(b<a)
//
// MotorGoHead( );//1MS*a運(yùn)動(dòng)時(shí)間 1MS*b 停止時(shí)間 在100MS時(shí)間內(nèi) PWM
// else
// MotorStop( );
if(b<a)
ENA=1;
else
ENA=0;
if(b<c)
ENB=1;
else
ENB=0;
if(b>100)
{
b=0;
}
}
復(fù)制代碼
作者:
zxc3663441
時(shí)間:
2018-12-6 17:39
但是單片機(jī)一直閃 速度很慢 全速完全不行 小車抖的厲害 是怎么回事
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1