探讨贴子,新手上路各位大侠多多指教。
单片机管脚直接带多个LED有些吃力。这里用三极管驱动LED
程序就比较简单了
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit d0 = P1^0;
sbit d1 = P1^1;
sbit d2 = P1^2;
sbit d3 = P1^3;
sbit d4 = P1^4;
sbit d5 = P1^5;
sbit d6 = P1^6;
sbit d7 = P1^7; // 定义按键
uint i,j,k;
void delay (uint x)
{ for (i=x;i>0;i--)
{for (j=110;j>0;j--);
}
} // 延迟函数 1ms
void main (void)
{
while(1)
{
d1=d6=0;
delay (10000);
d1=d6=1;
d2=d4=0;
delay (500);
d2=d4=1;
delay (500);
d2=d4=0;
delay (500);
d2=d4=1;
delay (500);
d2=d4=0;
delay (500);
d2=d4=1;
delay (500);
d3=d5=0;
delay (10000);
d3=d5=1;
d2=d4=0;
delay (500);
d2=d4=1;
delay (500);
d2=d4=0;
delay (500);
d2=d4=1;
delay (500);
d2=d4=0;
delay (500);
d2=d4=1;
delay (500);
}
}
|