#include"reg52.h"
sbit lone=P1^5;
sbit ltwo=P1^6;
sbit start=P3^0;
sbit stop=P3^1;
sbit AUTO=P3^2;
sbit hand=P3^3;
sbit forward=P3^4;
sbit reverse=P3^5;
sbit acceleration=P3^6;
sbit deceleration=P3^7;
sbit direction=P1^0; //zhuanfan
sbit RS=P1^1; //on off
sbit PMW=P1^2; //kongzhi
int CYCLE,PWM_ON,count;
void initial()
{
CYCLE=20;
PWM_ON=0;
count=0;
}
void DelayMs(unsigned char z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void nit_Timer0(void)
{
TMOD|=0x01;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
EA=1;
ET0=1;
TR0=1;
}
void Timer0_isr(void) interrupt 1
{
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
if(count==PWM_ON)//如果定时等于on的时间说明作用时间结束,输出低电平
{
PMW=0;
}
if(count==CYCLE)//反之低电平时间结束后返回高电平
{
count=0;
if(PWM_ON!=0)//如果开启时间是0保持原来状态
{
PMW=1;
}
}
count++;
}
void accelerate()
{
if(PWM_ON==CYCLE)
{
}
else
{PWM_ON++;}
}
mian()
{
initial();
Iint_Timer0();
while(1)
{
if(!stop)
{
lone=1;
PWM_ON=0;
ltwo=1;
PWM_ON=0;
while(start)
{
RS=0;
}
}
}
}
|