你试试我这个程序,我这发光二极管是给0亮的,按键按下会得到一个低电平的共阳接法
/***********共阳接法*******************************/
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define dat P0
sbit key1=P3^0;
sbit key2=P3^1;
uchar led,temp,num;
void key_pd();
void delay(uint aa)
{
uchar bb;
for(;aa>0;aa--)
for(bb-110;bb>0;bb--);
}
void xianshi1()
{
led=0xaa;
if(temp==1)
{
num=2;
while(num--)
{
dat=led;
delay(1000);
delay(1000);
led=_crol_(led, 1);
delay(1000);
delay(1000);
}
}
}
void xianshi2()
{
led=0xfe;
if(temp==2)
{
num=8;
while(num--)
{
dat=led;
delay(1000);
delay(1000);
led=_cror_(led, 1);
delay(1000);
delay(1000);
}
}
}
void key_pd()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1);
temp=1;
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
temp=2;
}
}
}
void main()
{
led=0xff;
dat=led;
while(1)
{
key_pd();
xianshi1();
xianshi2();
}
}