当前位置:网站首页>Fundamentals of C language
Fundamentals of C language
2022-07-25 09:55:00 【Work makes me happy】
Preface
For those used in work C Language grammar , Part of the content comes from the reference blog .
Not specializing in the software industry , Code is only the foundation to meet functional requirements . Update and enrich the content in the later stage .
1 grammar
1.1 Structure
-> It's a whole , It is used to point to the structure 、C++ Medium class And other pointers containing sub data are used to get sub data . In other words , If we were C Language defines a structure , Then declare a pointer to the structure , Then we need to use the pointer to get the data in the structure , You use “->”
struct Data
{
int a,b,c;
}; /* Defining structure */
struct Data * p;/* Define structure pointer */
struct Data A = {1,2,3};/* Declare variables A*/
int x;/* Declare a variable x*/
p = &A ; /* Give Way p Point to A*/
x = p->a;/* This sentence means to take out p Data items contained in the pointed structure a Assign a value to x*/
/* Because of this time p Point to A, thus p->a == A.a, That is to say 1*/
For the first question p = p->next; This should appear in C Linked list of languages , there next It should be one with p Structure pointer of the same type , Its definition format should be :
struct Data
{
int a;
struct Data * next;
};/* Defining structure */
…………
main()
{
struct Data * p;/* Declare pointer variables p*/
……
p = p->next;/* take next The value in is assigned to p*/
}

1.2 Register sheet bit operation
take 32bit Bit wide register GPIOx_CRL A certain bit ( The first n bit , n from 0 start ) Set up 1, Take measures :
GPIOx_CRL = GPIOx_CRL | (0x01 << n) //n from 0 Start
GPIOx_CRL = GPIOx_CRL | (0x01 << 0) // take GPIOx_CRL[0] Set up 1
GPIOx_CRL = GPIOx_CRL | (0x01 << 3) // take GPIOx_CRL[3] Set up 1take 32bit Bit wide register GPIOx_CRL A certain bit ( The first n bit , n from 0 start ) Set up 0, Take measures :
GPIOx_CRL = GPIOx_CRL & (~(1 << n)) /* Clear the ground n bit position */
// analysis , if GPIOx_CRL = 1001 1111,n=2,
(1<<2) Get the binary number :0000 0100
Reverse is :1111 1011
GPIOx_CRL = (1001 1111) & (1111 1011) = 1001 10111.3 There are many registers bit assignment
take 32bit Bit wide register GPIOx_CRL Medium bit[6:2] Assign a new value , You need to first put this bit[6:2] Zero clearing , Then assign a value . Steps are as follows :
// Reference code --------------------------------------------------------
// First , take GPIOx_CRL[6:2] Zero clearing . Clear the zero table bit Just a few bit Of 1 Move left and reverse 、 Then with the original register value “ Meet each other ”
GPIOx_CRL = GPIOx_CRL & (~(0x1f << 2)) /* Clear the ground [6:2] bit position */
// secondly , take GPIOx_CRL[6:2] Assign new values to "0xd" , Just move the new value to the left 、 With the original value “ Phase or ”
GPIOx_CRL = GPIOx_CRL | (0xd << 2)
// Code parsing --------------------------------------------------------
// if GPIOx_CRL = 1001 1111, The clearing steps are as follows :
(0x1f<<2) Get the binary number :0111 1100
Reverse is :1000 0011
GPIOx_CRL = (1001 1111) & (1000 0011) = 1000 0011
// assignment
0xd Binary is :1101
(0xd << 2) yes :110100
GPIOx_CRL = GPIOx_CRL | (0xd << 2) = 1000 0011 | 11 0100 =1011 0111
give an example , Put the following register bit0 Set up 1, All functional segments of this register can be completed Declaration definition , Then use the following method
GPIOx_CRL = GPIOx_CRL | (0x01 << BLOCK_COUNT_ENABLE) // take GPIOx_CRL.BLOCK_COUNT_ENABLE Set up 1Here we need to pay attention to , The above operation is in the register BLOCK_COUNT_ENABLE The seat width is 1bit
If necessary AUTO_CMD_ENABLE Modify its value , Like this 2bit The original value is 0x3, If it needs to be modified to 0x1, The following expression may have problems
GPIOx_CRL = GPIOx_CRL | (0x01 << AUTO_CMD_ENABLE) //therefore , If you need to register some bit Field assignment , You can consider these first bit Zero clearing , Then assign a value .

for example , You need to set the second 0 position bit=1 when , It cannot be simply set to :GPIOx_CRL=0x01 , Such a method will make the low configuration register GPIOx_CRL All other bits of are set to 0.
For binary operations :
No matter the original value of this bit is 0 still 1, It goes with 0 Conduct & operation , All the results are 0, And follow 1 Conduct & operation , The original value will remain the same ;
No matter the original value of this bit is 0 still 1, It goes with 1 Conduct | operation , All the results are 1, And follow 0 Conduct | operation , The original value will remain the same .

Common grammar
1、if else grammar
if(age>=18){
printf(" Congratulations , You are an adult , You can use the software !\n");
}else{
printf(" I'm sorry , You're underage , It is not suitable to use this software !\n");
}
2、while grammar
#include <stdio.h>
int main(void){
int i,sum=0;
i=1;
while(i<=100){
sum=sum+i;
i++;
}
printf("%d\n",sum);
return 0;
}
#include <stdio.h>
int main(void){
int n=0;
printf("input a string:\n");
while(getchar()!='\n') n++;
printf("%d",n);
return 0;
}
3、 Function definition and use


Reference resources
| 1、 author | post |
| 【 turn 】C In language -> What does that mean? ? | |
| C Language bit operation - bit 、byte Zero clearing , Set up 1, extract , Judge | |
| C Language bit operations on registers |
边栏推荐
- Connection and data reading of hand-held vibrating wire vh501tc collector sensor
- MLX90640 红外热成像传感器测温模块开发笔记(二)
- ARMV8体系结构简介
- Minkowskiengine installation
- Kotlin realizes file download
- [data mining] nearest neighbor and Bayesian classifier
- 十进制整数转换为其它进制的数
- Hyperautomation for the enhancement of automation in industries 论文翻译
- ARMV8 datasheet学习
- pytorch使用tensorboard实现可视化总结
猜你喜欢
![Customize the view to realize the background of redeeming lottery tickets [elementary]](/img/97/53e28673dcd52b31ac7eb7b00d42b3.png)
Customize the view to realize the background of redeeming lottery tickets [elementary]

Gartner 2022年顶尖科技趋势之超级自动化
![[deep learning] self encoder](/img/7e/c3229b489ec72ba5d527f6a00ace01.png)
[deep learning] self encoder

CCF 201604-2 俄罗斯方块
![[Android studio] batch data import to Android local database](/img/fc/758df0ba1c4c5b4f0eb8ccbcb4952c.png)
[Android studio] batch data import to Android local database

First knowledge of opencv4.x ---- mean filtering

How to import a large amount of data in MATLAB

First knowledge of opencv4.x --- image histogram matching

Mixed supervision for surface-defect detection: from weakly to fully supervised learning:表面缺陷检测的混合监督

CCF 201509-4 高速公路
随机推荐
Defect detection network -- hybrid supervision (kolektor defect data set reproduction)
数据分析面试记录1-5
CCF 201509-2 日期计算
深入理解pytorch分布式并行处理工具DDP——从工程实战中的bug说起
ARMV8体系结构简介
CDA LEVELⅠ2021新版模拟题二(附答案)
Kotlin basic knowledge points
Wechat applet realizes the rotation map (automatic switching & manual switching)
工程监测多通道振弦传感器无线采集仪外接数字传感器过程
First knowledge of opencv4.x --- image histogram drawing
Mixed supervision for surface defect detection: from weakly to fully supervised learning
matlab如何导入大量数据
Coredata storage to do list
【数据挖掘】第二章 认识数据
如何安装pytorch?—— 一种最简单有效的方法!
Gartner 2022年顶尖科技趋势之超级自动化
无线振弦采集仪参数配置工具的设置
Chmod and chown invalidate the files of the mounted partition
matlab的find()函数的一些用法(快速查找符合条件的值)
数字IC设计SOC入门进阶