给你来个简单例子
#include <reg52.h>
#define led P2 //P2连接led,共阳极连接
void delay(int z) //1ms延时
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
while(1)
{
led=0x7f;
delay(100);
led=0xbf;
delay(100);
led=0x5f;
delay(100);
led=0xef;
delay(100);
led=0x77;
delay(100);
led=0xfb;
delay(100);
led=0x7d;
delay(100);
led=0xfe;
delay(100);
}
} |