欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
四線雙極性電機的單片機程序按鍵沒有反應(yīng)
[打印本頁]
作者:
往事不可逆
時間:
2018-9-12 19:12
標題:
四線雙極性電機的單片機程序按鍵沒有反應(yīng)
有沒有大神幫我看一下問題出在哪里
插上后 按鍵沒反應(yīng)
課設(shè)要做的
希望哪位朋友給點幫助 不勝感激
下面是原程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit K1=P3^0; //定義五個按鍵
sbit K2=P3^1; //
sbit K3=P3^2; //
sbit K4=P3^3; //
sbit K5=P3^4; //
sbit motoA=P1^0;//四線雙極性電機in_A
sbit motoB=P1^1;//in_B
sbit motoC=P1^2;//in_c
sbit motoD=P1^3;//in_d
uchar state=0; //狀態(tài)變量
uint Time=60; //轉(zhuǎn)速
void delay(uint ms) //Ñóê±£¬óÃóúμ÷Ëù
{
uint t;
while(ms--)
for(t=0;t<120;t++);
}
void motor_zz() //正轉(zhuǎn)
{
while(1){
motoA = 1;
motoB = 1;
motoC = 0;
motoD = 1;
delay(Time);
motoA = 0;
motoB = 1;
motoC = 1;
motoD = 1;
delay(Time);
motoA = 1;
motoB = 1;
motoC = 1;
motoD = 0;
delay(Time);
motoA = 1;
motoB = 0;
motoC = 1;
motoD = 1;
delay(Time);
if(P3==0xfe)
{
break;
}
}
}
void motor_fz() //反轉(zhuǎn)
{
while(1)
{
motoA = 1;
motoB = 0;
motoC = 1;
motoD = 1;
delay(Time);
motoA = 1;
motoB = 1;
motoC = 1;
motoD = 0;
delay(Time);
motoA = 0;
motoB = 1;
motoC = 1;
motoD = 1;
delay(Time);
motoA = 1;
motoB = 1;
motoC = 0;
motoD = 1;
delay(Time);
if(P3==0xfe)
{
break;
}
}
}
void main()
{
P1=0x00;
while(1)
{
while(state==0) //×′ì¬0£¬í£Ö1
{
if(K2==0) //°′ÏÂK2£¬μç»úÕy×a
{
state=1;
break;
}
if(K3==0) //°′ÏÂK3£¬μç»ú·′×a
{
state=2;
break;
}
P0=0x00;
}
while(state==1) //×′ì¬1£¬Õy×a
{
if(K1==0) //°′ÏÂK1£¬μç»ú·′×a
{
state=0;
break;
}
if(K2==0) //°′ÏÂK2£¬μç»úÕy×a
{
state=1;
break;
}
if(K3==0) //°′ÏÂK3£¬μç»ú·′×a
{
state=2;
break;
}
if(K4==0) //°′ÏÂK4£¬μç»ú¼óËù
{
Time=Time-5;
if(Time<20)
Time=20;
while(K4==0);
}
if(K5==0) //°′ÏÂK5£¬μç»ú¼õËù
{
Time=Time+5;
if(Time>100)
Time=100;
while(K5==0);
}
motor_zz(); //×′ì¬1£¬Õy×a
}
while(state==2) //×′ì¬2£¬·′×a
{
if(K1==0) //°′ÏÂK1£¬μç»ú·′×a
{
state=0;
break;
}
if(K2==0) //°′ÏÂK2£¬μç»úÕy×a
{
state=1;
break;
}
if(K3==0) //°′ÏÂK3£¬μç»ú·′×a
{
state=2;
break;
}
if(K4==0) //°′ÏÂK4£¬μç»ú¼óËù
{
Time=Time-5;
if(Time<20)
Time=20;
while(K4==0);
}
if(K5==0) //°′ÏÂK5£¬μç»ú¼õËù
{
Time=Time+5;
if(Time>100)
Time=100;
while(K5==0);
}
motor_fz(); //×′ì¬2£¬·′×a
}
}
}
復(fù)制代碼
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1