日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

单片机led闪烁代码_单片机驱动LED发光二极管的电路以及编程

發布時間:2024/7/23 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 单片机led闪烁代码_单片机驱动LED发光二极管的电路以及编程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、單片機驅動單個發光二極管

1.電路

代碼:

1.點亮單個LED二極管

#include《reg51.h> sbit LED1=P1^0;void main(void){LED1=1;while(1);{LED1=0} }

2.單個LED數碼管以固定頻率閃爍

#include<reg51.h> sbit LED1=P1^0;void Delay(unsigned int t);void main(void){while(1){LED1=1;Delay(30000);LED1=0;Delay(30000);} } void Delay(unsigned int t){while(--t); }

效果:

使單個LED數碼管以固定頻率爍https://www.zhihu.com/video/1245660428543778816

二、單片機點亮多個LED電路

1.電路

代碼:

1.多個LED二極管以固定頻率閃爍

#include<reg51.h>void Delay(unsigned int t);void main(void){while(1){P1=0xFF;Delay(30000);P1=0x00;Delay(30000);} } void Delay(unsigned int t){while(--t); }

效果

多個LED二極管以固定頻率閃爍https://www.zhihu.com/video/1245670402866753536

2控制多個LED逐漸點亮(最后LED全亮)

代碼:

#include<reg51.h>void Delay(unsigned int t);void main(void){while(1){unsigned char i;P1=0xfe;for(i=0;i<8;i++){Delay(30000);P1=P1<<1;}} } void Delay(unsigned int t){while(--t); }

效果:

控制多個LED逐漸點亮https://www.zhihu.com/video/1245701956095971328

3控制LED循環點亮(始終只有一個亮)

1.代碼

#include<reg51.h>void Delay(unsigned int t);void main(void){while(1){unsigned char i;P1=0xfe;for(i=0;i<8;i++){Delay(30000);P1=P1<<1|0x01;}} } void Delay(unsigned int t){while(--t); }

2.效果

控制LED循環點亮https://www.zhihu.com/video/1245707326478393344

4.控制LED花樣點亮

1.代碼

#include<reg51.h>void Delay(unsigned int t);void main(void){while(1){unsigned char i;P1=0xfe;for(i=0;i<8;i++){Delay(30000);P1 <<=1;}P1=0x7f;for(i=0;i<8;i++){Delay(30000);P1 >>=1;}P1=0xfe;for(i=0;i<8;i++){Delay(30000);P1 >>=1;P1 |=0x01;}P1=0x7f;for(i=0;i<8;i++){Delay(30000);P1 >>=1;P1 |=0x80;}} } void Delay(unsigned int t){while(--t); }

2.效果

控制LED花樣點亮https://www.zhihu.com/video/1245710486429745152

總結

以上是生活随笔為你收集整理的单片机led闪烁代码_单片机驱动LED发光二极管的电路以及编程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。