C51代码:
sbit A1=P1^0;
sbit B1=P1^1;
sbit C1=P1^2;
sbit D1=P1^3;
sbit GND=P1^4;
sbit Bu1=P2^1;
sbit Bu2=P2^2;
unsigned int count=0;
unsigned int derta=0;
void Delay(unsigned int k)
{
unsigned int i=0;
unsigned int y=0;
for(i=1;i<=k;i++)
{
for(y=1;y<=248;y++);
for(y=1;y<=248;y++);
}
}
void ClockWise(unsigned int N)
{
unsigned int j;
for(j=0;j<=N;j++)
{
A_ON;
Delay(100);
B_ON;
Delay(100);
C_ON;
Delay(100);
D_ON;
Delay(100);
}
}
void AntiClockWise(unsigned int M)
{
unsigned int x;
for(x=0;x<=M;x++)
{
D_ON;
Delay(100);
C_ON;
Delay(100);
B_ON;
Delay(100);
A_ON;
Delay(100);
}
}
void T0_Init()
{
TMOD=0x00;
TH1=65535;
TL0=10000;
ET0=0;
TR0=0;
EA=1;
}
void T0_InterruptionService() interrupt 1
{
TH1=65535;
TL0=10000;
count++;
}
void Button_Control()
{
if(Bu1==1&&Bu2==0)
{
Delay(5);
if(Bu1==1&&Bu2==0)
{
if(Bu1==0)
derta=count;
count=0;//clear the count
ClockWise(derta);
}
if(Bu2==1&&Bu1==0)
{
Delay(5);
if(Bu2==1&&Bu1==0)
{
if(Bu2==0)
derta=count;
count=0;//clear the count
AntiClockWise(derta);
}
}
}
}
void main()
{
while(1)
{
GND=0;
T0_Init();
Bu1=0;
Bu2=0;
Button_Control();
}
}