在前面我们已经知道了LED的闪烁原理,现在我们来学习一下LED灯是如何闪烁的,电路如图
![d86fe196bacf235bc784d9100e3d2a6b.png](https://i-blog.csdnimg.cn/blog_migrate/198eb26c10b4672b0f151f2482fad7a1.jpeg)
有了电路之后我们只需看着电路进行代码编写就可以了、由于单片机读代码是一行一行的读,所以我们只有要把我们想要实现的功能进行代码编写就可以了。#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit led=P1^0;
sbit led1=P1^1;
main()
{
uint a;
while(1)
{ a=50000;
led=1;
while(a--);
a=50000;
led=0;
while(a--);
}
}
代码编写完毕把代码转为hex文件就可以导入单片机使用了。