当前位置:网站首页>单片机学习笔记之点亮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
}边栏推荐
- 为租客提供帮助
- Day26 IP query items
- 共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
- - Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
- Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
- Query whether a field has an index with MySQL
- 自定义线程池拒绝策略
- Adopt a cow to sprint A shares: it plans to raise 1.85 billion yuan, and Xu Xiaobo holds nearly 40%
- PACP学习笔记一:使用 PCAP 编程
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
猜你喜欢

Introduce six open source protocols in detail (instructions for programmers)
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

MySQL入门尝鲜

leecode3. 无重复字符的最长子串
![[learning notes] agc010](/img/2c/37f2537a4dadd84adacf3da5f1327a.png)
[learning notes] agc010

Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
![[Presto profile series] timeline use](/img/c6/83c4fdc5f001dab34ecf18c022d710.png)
[Presto profile series] timeline use

“新红旗杯”桌面应用创意大赛2022

Cinnamon Applet 入门

线程池拒绝策略最佳实践
随机推荐
初学XML
MongoDB优化的几点原则
Awk of three swordsmen in text processing
[untitled]
【学习笔记】AGC010
QQ的药,腾讯的票
Lingyunguang of Dachen and Xiaomi investment is listed: the market value is 15.3 billion, and the machine is implanted into the eyes and brain
[learning notes] segment tree selection
Star Enterprise Purdue technology layoffs: Tencent Sequoia was a shareholder who raised more than 1billion
PAcP learning note 1: programming with pcap
【学习笔记】zkw 线段树
[learning notes] zkw segment tree
MATLAB中polarscatter函数使用
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
File operation command
分屏bug 小记
MongoDB 遇见 spark(进行整合)
JNA learning notes 1: Concepts
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
【无标题】