# include # define uchar unsigned char
# define uint unsigned int
sbit CLR=P0^0;
sbit D=P0^1;
sbit CLK=P0^2;
sbit PR=P0^3;
sbit Q5=P0^4;
sbit Q6=P0^5;
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
void delay(uint);
uchar a,b,c,d;
void main()
{
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
P0 = 0xff;
a=0;
while (1)
{
P3=P0;
if (K1==0)
{
delay(10);
if (K1==0)
{
while(K1==0);
CLR=~CLR;
}
}
if (K2==0)
{
delay(10);
if (K2==0)
{
while(K2==0);
D=~D;
}
}
if (K3==0)
{
delay(10);
if (K3==0)
{
while(K3==0);
CLK=~CLK;
}
}
if (K4==0)
{
delay(10);
if (K4==0)
{
while(K4==0);
PR=~PR;
}
}
if (PR==0&&CLR==1)
{
Q5=1;Q6=~Q5;
}
if (PR==1&&CLR==0)
{
Q5=0;Q6=~Q5;
}
if (PR==0&&CLR==0)
{
Q6=1;Q5=Q6;
}
if (PR==1&&CLR==1)
{
}
if (CLK==0&&PR==1&&CLR==1) //设a=0
{
a=0;
}
if (CLK==1&&PR==1&&CLR==1&&a==0) //当a==0&&CLK==1时a=1。从而实现CLK上升沿有效
{
a=1;
if (D==0)
{
Q5=0;Q6=~Q5;
}
if (D==1)
{
Q5=1;Q6=~Q5;
}
}
}
}
void delay(uint z)
{
uint x;
uchar y;
for(x=z;x>0;x--)
for(y=245;y>0;y--);
}