亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標題:
關于LCD1602的步進電機程序和原理圖
[打印本頁]
作者:
LLL123
時間:
2015-7-21 11:43
標題:
關于LCD1602的步進電機程序和原理圖
C51單片機寫的步進電機程序,有需要拿去吧
/***************************************************
程序使用1毫秒定時器中斷實現(xiàn)轉速精確控制
步進電機用8拍驅動(A-AB-B-BC-C-CD-D-DA)
****************************************************/
#include <reg52.h>
#include "LCD1602.H"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
/*****端口定義************/
#define P_key P3
sbit motor_a=P1^0;
sbit motor_b=P1^1;
sbit motor_c=P1^2;
sbit motor_d=P1^3;
bit run=0;
uint speed;
uint temp_t1,temp_t2;
uchar KeyValue ;
uchar motor_step;
void Disply(void); //顯示
uchar GetKey(void);//返回鍵盤值0--16
void ScanKey(void);//鍵盤掃描處理
void SetMotorSpeed(uint nSpeed);//設置電機轉速 nSpeed:轉速 step/s
void delayNms(uint z);//延時
/*****主函數(shù)************/
void main()
{
lcd1602_init();
motor_a=0;
motor_b=1;
motor_c=1;
motor_d=1;
motor_step=0;
TMOD = 0x01;
TH0 = 0x0FC;
TL0 = 0x18;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1)
{
Disply();
ScanKey();
}
}
/*****延時************/
void delayNms(uint z)
{
uint x;
for( ;z>0;z--)
for(x=124;x>0;x--)
;
}
/*****設置電機轉速************/
void SetMotorSpeed(uint nSpeed)// nSpeed:轉速 step/s
{
speed=nSpeed;
if(speed!=0)
{
run=1;
//計算每步需要多少毫秒
temp_t2=1000/nSpeed;
}
else
{
run=0;
}
}
/*****1毫秒定時器************/
void Timer0Interrupt(void) interrupt 1
{
if(run)
{
temp_t1++;
if(temp_t1>temp_t2)
{
temp_t1=0;
motor_step++;
if(motor_step>7) motor_step=0;
switch (motor_step)
{
case 0:
{
motor_a=0; motor_b=1;
motor_c=1; motor_d=1;
break;
}
case 1:
{
motor_a=0; motor_b=0;
motor_c=1; motor_d=1;
break;
}
case 2:
{
motor_a=1; motor_b=0;
motor_c=1; motor_d=1;
break;
}
case 3:
{
motor_a=1; motor_b=0;
motor_c=0; motor_d=1;
break;
}
case 4:
{
motor_a=1; motor_b=1;
motor_c=0; motor_d=1;
break;
}
case 5:
{
motor_a=1; motor_b=1;
motor_c=0; motor_d=0;
break;
}
case 6:
{
motor_a=1; motor_b=1;
motor_c=1; motor_d=0;
break;
}
case 7:
{
motor_a=0; motor_b=1;
motor_c=1; motor_d=0;
break;
}
default: break;
}
}
}
TH0 = 0x0FC;
TL0 = 0x18;
}
/***********顯示************/
void Disply( )
{
uchar DisBuff[16];
DisBuff[0]='S';
DisBuff[1]='p';
DisBuff[2]='e';
DisBuff[3]='e';
DisBuff[4]='d';
DisBuff[5]=speed>9999 ? speed%100000/10000+0x30 : 0x20;
DisBuff[6]=speed>999 ? speed%10000/1000+0x30 : 0x20;
DisBuff[7]=speed>99 ? speed%1000/100+0x30 : 0x20;
DisBuff[8]=speed>9 ? speed%100/10+0x30 : 0x20;
DisBuff[9]=speed%10+0x30;
DisBuff[10]='s';
DisBuff[11]='t';
DisBuff[12]='e';
DisBuff[13]='p';
DisBuff[14]='/';
DisBuff[15]='s';
if(run)
lcd1602_showStr(0,0," Run ");//第一行
else lcd1602_showStr(0,0," Stop ");
lcd1602_showStr(0,1,DisBuff);//第二行
}
/***********返回鍵盤值0--16************/
uchar GetKey()
{
P_key=0xfe;
if((P_key&0x80)!=0x80) return 0x03;
if((P_key&0x40)!=0x40) return 0x07;
if((P_key&0x20)!=0x20) return 0x0b;
if((P_key&0x10)!=0x10) return 0x0f;
P_key=0xfd;
if((P_key&0x80)!=0x80) return 0x02;
if((P_key&0x40)!=0x40) return 0x06;
if((P_key&0x20)!=0x20) return 0x0a;
if((P_key&0x10)!=0x10) return 0x0e;
P_key=0xfb;
if((P_key&0x80)!=0x80) return 0x01;
if((P_key&0x40)!=0x40) return 0x05;
if((P_key&0x20)!=0x20) return 0x09;
if((P_key&0x10)!=0x10) return 0x0d;
P_key=0xf7;
if((P_key&0x80)!=0x80) return 0x00;
if((P_key&0x40)!=0x40) return 0x04;
if((P_key&0x20)!=0x20) return 0x08;
if((P_key&0x10)!=0x10) return 0x0c;
return 0xff;
}
/***********鍵盤掃描處理************/
void ScanKey()
{
if(KeyValue==GetKey()) return;
delayNms(2); //防抖
if(KeyValue==GetKey()) return;
KeyValue=GetKey();
switch(KeyValue)
{
case 0x00: //按鍵0
{
SetMotorSpeed(0);
break;
}
case 0x01: //按鍵1
{
SetMotorSpeed(5);
break;
}
case 0x02: //按鍵2
{
SetMotorSpeed(10);
break;
}
case 0x03: //按鍵3
{
SetMotorSpeed(15);
break;
}
case 0x04: //按鍵4
{
SetMotorSpeed(20);
break;
}
case 0x05: //按鍵5
{
SetMotorSpeed(25);
break;
}
case 0x06: //按鍵6
{
SetMotorSpeed(30);
break;
}
case 0x07: //按鍵7
{
SetMotorSpeed(35);
break;
}
case 0x08: //按鍵8
{
SetMotorSpeed(40);
break;
}
case 0x09: //按鍵9
{
SetMotorSpeed(45);
break;
}
case 0x0a: //按鍵A
{
SetMotorSpeed(50);
break;
}
case 0x0b: //按鍵B
{
SetMotorSpeed(55);
break;
}
case 0x0c: //按鍵C
{
SetMotorSpeed(60);
break;
}
case 0x0d: //按鍵D
{
SetMotorSpeed(65);
break;
}
case 0x0e: //按鍵E
{
SetMotorSpeed(70);
break;
}
case 0x0f://按鍵F
{
SetMotorSpeed(75);
break;
}
default: break;
}
}
復制代碼
lcd1602 motor.zip
2015-7-21 11:42 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
79.56 KB, 下載次數(shù): 52, 下載積分: 黑幣 -5
作者:
大青辣椒
時間:
2015-8-27 14:06
真棒,感謝樓主分享
作者:
mirage
時間:
2017-2-8 16:37
感謝樓主分享
作者:
faridzled
時間:
2017-2-9 13:10
amazing, thanks for sharing
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1