微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51控制直流电机正反转

51控制直流电机正反转

时间:11-17 来源:互联网 点击:
C代码:

/*************** writer:shopping.w ******************/
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit K1 = P3^0;
sbit K2 = P3^1;
sbit K3 = P3^2;
sbit LED1 = P0^0;
sbit LED2 = P0^1;
sbit LED3 = P0^2;
sbit MA = P1^0;
sbit MB = P1^1;

void main(void)
{
LED1 = 1;
LED2 = 1;
LED3 = 0;
while(1)
{
if(K1 == 0)
{
while(K1 == 0);
LED1 = 0;
LED2 = 1;
LED3 = 1;
MA = 0;
MB = 1;
}
if(K2 == 0)
{
while(K1 == 0);
LED1 = 1;
LED2 = 0;
LED3 = 1;
MA = 1;
MB = 0;
}
if(K3 == 0)
{
while(K1 == 0);
LED1 = 1;
LED2 = 1;
LED3 = 0;
MA = 0;
MB = 0;
}
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top