当前位置:网站首页>单片机学习笔记之点亮led 灯
单片机学习笔记之点亮led 灯
2022-07-07 11:26:00 【ly_zszcyx】
使用开发板:
普中科技开发板
编译软件:
keil
简单复习一下发光二极管(led),发光二极管的核心部分是由P型半导体和N型半导体组成的晶片,在P型半导体和N型半导体之间有一个过渡层,称为PN结。具有单向导电性。
正负极判断:
通常情况下:
1、有缺口的一端为负极;
2、有横杠的一端为负极;
3、有白色双杠的一端为负极;
4、三角形箭头方向的一端为负极;
5、插件二极管丝印小圆一端是负极,大圆是正极。
在立式焊接的情况下原件本体在正极圈里
6、插件发光二极管方孔为第一脚为正极。
开发板原理图:
点亮一盏灯,把相应管教置位低电平
sbit 变量名=地址值;
代码:
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
#include<intrins.h> //因为要用到左右移函数,所以加入这个头文件
sbit led0 = P2^0; //将单片机的P2.0端口定义为led0
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;
//点亮 8 个 led 灯
void lighterLed()
{
while(1)
{
led0=0; //P2.0端口设置为低电平
led1=0; //P2.1端口设置为低电平
led2=0; //P2.2端口设置为低电平
led3=0; //P2.3端口设置为低电平
led4=0; //P2.4端口设置为低电平
led5=0; //P2.5端口设置为低电平
led6=0; //P2.6端口设置为低电平
//led7=0; //P2.7端口设置为低电平
}
}
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
lighterLed(); //点亮LED
}
边栏推荐
- Sed of three swordsmen in text processing
- 【学习笔记】zkw 线段树
- 货物摆放问题
- 工具箱之 IKVM.NET 项目新进展
- 解决缓存击穿问题
- 国泰君安证券开户怎么开的?开户安全吗?
- Practical example of propeller easydl: automatic scratch recognition of industrial parts
- Cmu15445 (fall 2019) project 2 - hash table details
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- JS判断一个对象是否为空
猜你喜欢
LIS 最长上升子序列问题(动态规划、贪心+二分)
[Presto profile series] timeline use
通过Keil如何查看MCU的RAM与ROM使用情况
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
达晨与小米投的凌云光上市:市值153亿 为机器植入眼睛和大脑
Awk of three swordsmen in text processing
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
飞桨EasyDL实操范例:工业零件划痕自动识别
Ogre入门尝鲜
随机推荐
10 张图打开 CPU 缓存一致性的大门
存储过程的介绍与基本使用
Isprs2021/ remote sensing image cloud detection: a geographic information driven method and a new large-scale remote sensing cloud / snow detection data set
Practical example of propeller easydl: automatic scratch recognition of industrial parts
[untitled]
“新红旗杯”桌面应用创意大赛2022
单片机原理期末复习笔记
Cmu15445 (fall 2019) project 2 - hash table details
为租客提供帮助
[untitled]
学习突围2 - 关于高效学习的方法
Realbasicvsr test pictures and videos
MongoDB优化的几点原则
[untitled]
Users, groups, and permissions
工具箱之 IKVM.NET 项目新进展
test
Sequoia China completed the new phase of $9billion fund raising
MongoDB复制(副本集)总结
RealBasicVSR测试图片、视频