我有程序
仿真可以实现公能 硬件连接好了 却实现不了
程序如下:
#include<reg51.h>
#define uchar unsigned char
uchar N=0;
uchar X=40; //占空比初始值为50%
int a,b;
sbit PWM=P2^3; //PWM输出脚
sbit K1=P1^2;//M1启动
sbit K2=P1^3;//M1停止
sbit K3=P1^4;//M1加速
sbit K4=P1^5;//M2减速
sbit led1=P2^5;
sbit led2=P2^6;
sbit led3=P2^7;
sbit IN1=P2^0;//M1
sbit IN2=P2^1;//M1
void delay(uchar i)
{
while(i--);
}
void scjs(void)interrupt 3
{
TH1=0Xff;
TL1=0x17;
b++;
}
main()
{
TMOD=0x00;
IE=0X88;
TH1=0Xff;
TL1=0X17;
TR0=1;
TR1=1;
a=0;
b=0;
while(1)
{
PWM=1;
while(1)
{
b=0;
while(!b);
if (N==X)
PWM=0;
if (N==100)break;
N++;
if(K1==0)//M1启动
{
IN1=1;
IN2=0;
X=50;
led1=0;
led2=led3=1;
}
if(K2==0)//M1停止
{
IN1=1;
IN2=1;
led1=1;
led2=1;
led3=1;
}
if(K3==0)
{
IN1=1;
IN2=0;
X=100;
led1=led2=led3=0;
}
if(K4==0)
{
IN1=1;
IN2=0;
X=20;
led1=led2=0;
led3=1;
}
}
N=0;
}
}
望大神指点!!!
file:///H:Userswsha110AppDataRoamingTencentUsers357602135QQWinTempRichOle421}]H1FER0ELM2B`18(M8P.jpg
-
一周热门 更多>