要求单片机接12个灯,逐一点亮发光二极管画出电路图并编程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int //加黑的都是定义头文件
sbit led0=P2^0;
sbit led1=P2^1;
sbit led2=P2^2;
sbit led3=P2^3;
sbit led4=P2^4;
sbit led5=P2^5;
sbit led6=P2^6;
sbit led7=P2^7;
sbit led8=P3^0;
sbit led9=P3^1;
sbit led10=P3^2;
sbit led11=P3^3;
void delay(uint x) //延时
{
uchar i;
while(x--)
{
for(i=0;i<120;i++);
}
}
void main() //主程序
{
uchar i;
while(1)
{
P2=0xff;
P3=0xff;
delay(200);
led0=0;
delay(200);
led1=0;
delay(200);
led2=0;
delay(200);
led3=0;
delay(200);
led4=0;
delay(200);
led5=0;
delay(200);
led6=0;
delay(200);
led7=0;
delay(200);
led8=0;
delay(200);
led9=0;
delay(200);
led10=0;
delay(200);
led11=0;
delay(200);
}
}