自己写的用十六进制逐渐加1的方式点亮8个LED
时间:10-02
整理:3721RD
点击:
#include<reg51.h>
char code led1[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
char code led2[]={0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0};
char i=0;
char j=0;
char CD1,CD2;
void delay()
{
unsigned int a;
unsigned int b;
for(a=200;a>0;a--)
for(b=500;b>0;b--);
}
void main()
{
P1=0x00;
while(1)
{
for(j=0;j<16;j++)
{
CD2=led2[j];
P1=~CD2;
delay();
for(i=0;i<16;i++)
{
CD1=led1[i];
P1=~(CD1|CD2);
delay();
}
}
}
}
char code led1[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
char code led2[]={0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0};
char i=0;
char j=0;
char CD1,CD2;
void delay()
{
unsigned int a;
unsigned int b;
for(a=200;a>0;a--)
for(b=500;b>0;b--);
}
void main()
{
P1=0x00;
while(1)
{
for(j=0;j<16;j++)
{
CD2=led2[j];
P1=~CD2;
delay();
for(i=0;i<16;i++)
{
CD1=led1[i];
P1=~(CD1|CD2);
delay();
}
}
}
}