当前位置:网站首页>Turn on the LED
Turn on the LED
2022-07-26 02:23:00 【Pear blossom presses Begonia】
Preface
As the saying goes : A good beginning is half the battle ! I quite agree with this sentence , This is the simplest basic program , But if you want to complete this program, you need to understand the programming process , What information do you need to see 、 The framework of the program, etc . That solved the problem , The later programming path can be too smooth . I also checked a lot of information to solve , Just leave some experience for the later scholars .
The information of these circuits and chips can be found on XXX learning website
Programming flow
1. First of all, we must look at the chip pin name , And analyze LED Circuit .
Take a look at the distribution and name of the pins , It will be used later .
Here is LED And the circuit diagram of the nixie tube , Let's not look at the digital tube here , Only study light-emitting diodes :
You can see 8 Diode Common Cathode , If you want to light them , Cathode should provide low level .P2.3 Pass a Inverter ( Exchange high and low levels Connected to the cathode of the diode , So one condition for lighting up is P2.3 Provide high level at .
P0 Of 0 To 7 Which one is 1 The corresponding diode controlled will light up .
After analyzing the circuit, you can write a program . First put the code below and then analyze it step by step .
#include <STC15F2K60S2.H>
sbit led_sel=P2^3;
void Init(){
P0M0=0xff;
P0M1=0x00;
P2M0=0x08;
P2M1=0x00;
led_sel=1;
}
void main(){
Init();
while(1){
P0=0xf0;
}
}
This procedure is to make the high four bits of the diode light , The lower four digits are not lit .
Effect after downloading 
Let's analyze the code :
1. First of all, you must include the header file of the chip 
2. The following two lines are the control circuit diagram P2.3 High level at
It is stipulated in the chip data that the writing method is fixed as follows , If you change these two lines to sbit P2^3=1; You're going to report a mistake
sbit led_sel=P2^3;
led_sel=1;
3.Init() The function is initialized P2.3 And set the push-pull output 
The material introduces four output settings , Push pull output is strong pull up . Here is either 5v Or 0v For strong pull-up , Therefore, it is set as push-pull output .
Push pull output is written as follows :
because P2 It's only used. P2.3 So when setting push-pull output P2M0 by 0x08(0000 1111). and P0,8 All pins are used , When setting push-pull output P0M0 by 0xff(1111 1111).M1 The end is all 0x00 There is no difference .
4.main The initialization function is called in the function .
Use here while The loop keeps the program refreshed ,P0 Set up LED Light on and off , change P0 The value of can be changed LED The situation of .
Postscript
Welcome to exchange if you have any questions
If you like it, you can leave a favor before you leave , Hey .
边栏推荐
- scipy.sparse.csr_matrix
- 1. Mx6ul core module serial -iot-6ulx core module brief introduction (I)
- National standard gb28181 protocol video platform easygbs message pop-up mode optimization
- 一款可插拔的AM335X工控模块板载wifi模块
- 1. Mx6ul core module serial WiFi test (VIII)
- scipy.sparse.vstack
- I.MX6UL核心模块使用连载-nand flash读写测试 (三)
- 栈题目:文件的最长绝对路径
- prometheus+blackbox-exporter+grafana 监控服务器端口及url地址
- 图解B+树的插入过程
猜你喜欢

Adruino basic experimental learning (I)

I.MX6UL核心模块使用连载-TF卡读写测试 (五)

I came to the library applet one click sign in and one click grab location tool

Obsidian mobile PC segment synchronization

Sword finger offer 28. symmetric binary tree

I.MX6UL核心模块使用连载-以太网测试 (七)

1. Mx6ul core module serial use - touch screen calibration (IX)

MySQL(4)

Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"

I came to the library applet check-in process analysis
随机推荐
2022-07-17
Are you still using ==0 null equal to judge null values? How much do you know about isempty and isblank
020-024 polymorphism review
记录之目标检测NMS(非极大值抑制)
获取时分秒
LeetCode302场周赛第三题--裁剪数字后查询第 K 小的数字
1. Mx6ul core module use serialization - view system information (II)
prometheus+blackbox-exporter+grafana 监控服务器端口及url地址
Master-slave replication in MySQL
Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"
Binary logs in MySQL
Implementation of Ti am335x industrial control module network and file system nfs
1. Mx6ul core module serial WiFi test (VIII)
npm link的简单介绍及使用
[2021] [paper notes] 6G technology vision - otfs modulation technology
3. Upload the avatar to qiniu cloud and display it
必会面试题:1.浅拷贝和深拷贝_深拷贝
19_请求表单与文件
本地仓库导致的报错
【PyQt5打包为exe】