功能八个led灯并排,编号1,2,3,4,5,6,7,8,先是同时亮起(1,8)两个灯,再依次点亮(2,6)(3,7)(4,5)(3,7)(2,6)(1,8),然后一直循环进行。
#include "reg52.h"
#include "intrins.h"
typedef unsigned char u8;
typedef unsigned int u16;
#define led P2
void delay(u16 i)
{
while(i--);
}
void main()
{
while(1)
{
led=0x7e; //亮1,8
delay(50000);
led=0xbd; //亮2,7
delay(50000);
led=0xdb; //亮3,6
delay(50000);
led=0xe7; //亮4,5
delay(50000);
led=0xdb;//亮3,6
delay(50000);
led=0xbd; //亮2,7
delay(50000);
}
}
|