|
# include"reg52.h"
# define uchar unsigned char
# define GPIO_motor P1
sbit K1=P3^0;
sbit K2=P3^1;
sbit K3=P3^2;
sbit K4=P3^3;
uchar code FZ[]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};
uchar code ZZ[]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1};
uchar Direction,Speed;
void Delay(unsigned int t)
{
unsigned int k;
while(t--)
{
for(k=0; k<80; k++)
{ }
}
}
void Motor()
{
uchar i;
for(i=0;i<8;i++)
{
if(Direction==1)
GPIO_motor=FZ[i]&&0x1f;
if(Direction==2)
GPIO_motor=ZZ[i]&&0x1f;
Delay(Speed);//μ÷½ú×aËù
}
}
void main()
{
uchar i;
Speed=30;
while(1)
{
if(K1==0)
{
Delay(5);
if(K1==0)
{
Direction=1;
}
while(K1==0);
}
if(K2==0)
{
Delay(5);
if(K2==0)
{
Direction=2;
}
while(K2==0);
}
if(K2==0)
{
Delay(5);
if(K2==0)
{
Direction=2;
}
while(K2==0);
if(K3==0)
{
Delay(5);
if(K3==0)
{
Speed=1;
}
while(K3==0);
}
}
if(K4==0)
{
Delay(5);
if(K4==0)
{
Speed=5;
}
while(K4==0);
}
Motor();
}
}
|
|