//解释下载可见
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit IN1=P3^7;
sbit IN2=P3^6;
sbit IN3=P3^1; //????k3?P3^5
sbit IN4=P3^0;
sbit ENA=P1^7; //???
sbit ENB=P1^6; //???
sbit k6=P3^2;
sbit k5=P3^3;
sbit k4=P3^4; //???? //??????????ε?????????
sbit k3=P3^5; //????
uchar pwm_count,count;
void delay(uint z)
{
uint x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
void Init()
{
count=0;
pwm_count=1;
TMOD=0x01;
TH0=(65536-500)/256;
TL0=(65536-500)%256;
TR0=1;
ET0=1;
EA=1;
}
void keyscan()
{
if(k6==0) //??????
{
delay(5);
if(k6==0)
{
IN2=1;
IN1=0;
}
while(!k6);
}
if(k5==0) //??????
{
delay(5);
if(k5==0)
{
IN2=0;
IN1=1;
}
while(!k5);
}
if(k4==0)
{
delay(5);
if(k4==0)
{
count=0;
pwm_count++;
if(pwm_count==41)
{
pwm_count=40; //
}
}
while(!k4);
}
if(k3==0)
{
delay(5);
if(k3==0)
{
count=0;
pwm_count--;
if(pwm_count==0)
{
pwm_count=1; //?????
}
}
while(!k3);
}
}
void main()
{
Init();
while(1)
{
keyscan();
}
}
void Timer0() interrupt 1
{
TR0=0;
TH0=(65536-500)/256;
TL0=(65536-500)%256;
if(count<pwm_count)
{
ENA=1;
}
else
{
ENA=0;
}
count++;
if(count==40)
{
count=0;
}
TR0=1;
}
|