我用是上面那个图,STC12系列单片机,写了程序电机就是不转,高手分析下什么原因,程序如下!
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar num,temp;
sbit N1=P3^4;
sbit N2=P3^5;
sbit N3=P3^6;
sbit N4=P3^7;
sbit PWM1=P1^2;
sbit PWM2=P1^4;
void init()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
N1=1;
N2=0;
N3=1;
N4=0;
}
void main()
{
init();
while(1)
{
if(num==20)
{
num=0;
PWM1=~PWM1;
}
if(temp==20)
{
temp=0;
PWM2=~PWM2;
}
}
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void time1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
temp++;
} |