当前位置:网站首页>单片机学习笔记之点亮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
}边栏推荐
- JS determines whether an object is empty
- 高端了8年,雅迪如今怎么样?
- How to make the new window opened by electorn on the window taskbar
- MATLAB中polarscatter函数使用
- 一文读懂数仓中的pg_stat
- 【无标题】
- php——laravel缓存cache
- [learning notes] segment tree selection
- centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
- [untitled]
猜你喜欢

Per capita Swiss number series, Swiss number 4 generation JS reverse analysis

【黑马早报】华为辟谣“军师”陈春花;恒驰5预售价17.9万元;周杰伦新专辑MV 3小时播放量破亿;法华寺回应万元月薪招人...

详细介绍六种开源协议(程序员须知)

Awk of three swordsmen in text processing

Isprs2021/ remote sensing image cloud detection: a geographic information driven method and a new large-scale remote sensing cloud / snow detection data set

Scrapy教程经典实战【新概念英语】

飞桨EasyDL实操范例:工业零件划痕自动识别

共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf

Ogre入门尝鲜

聊聊伪共享
随机推荐
飞桨EasyDL实操范例:工业零件划痕自动识别
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
PCAP学习笔记二:pcap4j源码笔记
About how appium closes apps (resolved)
详细介绍六种开源协议(程序员须知)
[Presto profile series] timeline use
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
JS缓动动画原理教学(超细节)
信号强度(RSSI)知识整理
Query whether a field has an index with MySQL
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
Enterprise custom form engine solution (XII) -- experience code directory structure
Initialization script
Practical case: using MYCAT to realize read-write separation of MySQL
Differences between MySQL storage engine MyISAM and InnoDB
Scrapy教程经典实战【新概念英语】
[untitled]
Cmu15445 (fall 2019) project 2 - hash table details
Analysis of DHCP dynamic host setting protocol
服务器到服务器 (S2S) 事件 (Adjust)