这个程序不知为什么无法运行,各位大佬帮忙看一下,试了半天也没搞懂问题所在
单片机源程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uint a,b,c,d,e,PWM_T,time,count,value;
sbit ADD=P0^0; //一键加速
//sbit SUB=P0^1;
sbit STOP=P0^2;
sbit DIR=P0^3;
sbit PWM=P2^1;
sbit KA1=P0^4;
sbit KA2=P0^5;
bit PWM_OUTDAT=0;
void delay(uint z);
void add();
//void sub();
void stop();
void dir();
void timeconfig();
PWM_OUT(uint Cycle,uint PWM_ON);
void main()
{
timeconfig();
PWM=0;
while(1)
{
add();
// sub();
stop();
dir();
if(a==1)
{
if(PWM_T>=1000)
{
PWM_T=0;
count++;
if(count<=19)
{
count=19;
}
}
}
if(b==1)
{
if(PWM_T>=100)
{
PWM_T=0;
count--;
if(count==0)
{
count=0;
}
}
}
switch(count)
{
case 0:
PWM=PWM_OUT(1000,950);
break;
case 1:
PWM=PWM_OUT(1000,900);
break;
case 2:
PWM=PWM_OUT(1000,850);
break;
case 3:
PWM=PWM_OUT(1000,800);
break;
case 4:
PWM=PWM_OUT(1000,750);
break;
case 5:
PWM=PWM_OUT(1000,700);
break;
case 6:
PWM=PWM_OUT(1000,650);
break;
case 7:
PWM=PWM_OUT(1000,600);
break;
case 8:
PWM=PWM_OUT(1000,550);
break;
case 9:
PWM=PWM_OUT(1000,500);
break;
case 10:
PWM=PWM_OUT(1000,450);
break;
case 11:
PWM=PWM_OUT(1000,400);
break;
case 12:
PWM=PWM_OUT(1000,350);
break;
case 13:
PWM=PWM_OUT(1000,300);
break;
case 14:
PWM=PWM_OUT(1000,250);
break;
case 15:
PWM=PWM_OUT(1000,200);
break;
case 16:
PWM=PWM_OUT(1000,150);
break;
case 17:
PWM=PWM_OUT(1000,100);
break;
case 18:
PWM=PWM_OUT(1000,50);
break;
case 19:
PWM=PWM_OUT(1000,0);
break;
}
}
}
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=0;y<180;y++);
}
void add()
{
if(ADD==0)
{
delay(5);
if(ADD==0)
{
a=1;
b=0;
}
}
/* else
{
b=1;
a=0;
} */
}
void timeconfig()
{
TMOD=0x01; //¶¨ê±Æ÷01¤×÷óú·½ê½1
TH0=0xFF;
TL0=0xFF;
TR0=1;
ET0=1;
EA=1;
}
void time0() interrupt 1
{
TH0=0xFF;
TL0=0xFF;
value++;
PWM_T++;
}
PWM_OUT(uint Cycle,uint PWM_ON)
{
if(value>=PWM_ON)
PWM_OUTDAT=0;
else
if(value>=Cycle)
{
value=0;
if(PWM_ON!=0)
{
PWM_OUTDAT=1;
}
}
return PWM_OUTDAT;
}
|