大佬们这是我的风扇控制程序代码显示是没有报错的,但是输入进单片机里面却是无法运行的。麻烦各位大佬看看这是哪里的问题,用的是52单片机
#include <REGX52.H>
#include<stdio.h>
sbit DJA=P2^0;
sbit DJB=P2^1;
sbit S1=P3^2;
sbit S2=P3^3;
bit flag;
unsigned char number;
void delay(unsigned int i)
{
unsigned int k;
for(k=0;k<i;k++);
}
void pwm(bit a,bit b,unsigned int d1,unsigned int d2)
{
DJB=a;
DJA=b;
delay(d1);
DJA=0;
DJB=0;
delay(d2);
}
void main()
{
flag=0;
number=0x00;
DJA=0;
DJB=0;
while(1)
{
if(S1==0)
{
delay(1200);
if(S1==0)
{
while(!S1);
flag=~flag;
}
if(S2==0)
{delay(1200);
if(S2==0)
{
while(!S2);
if(number<=3)
number++;
else number=0x01;}
}
if(!flag)
{
switch(number)
{
case 0x01:pwm(0,1,720,1680);break;
case 0x02:pwm(0,1,1250,1250);break;
case 0x03:pwm(0,1,1680,720);break;
default:;
}
}
else
{
switch(number)
{
case 0x01:pwm(0,1,720,1680);break;
case 0x02:pwm(0,1,1250,1250);break;
case 0x03:pwm(0,1,1680,720);break;
default:;}
}
}
}
}
|