当前位置:网站首页>mcu常用寄存器位操作方式汇总
mcu常用寄存器位操作方式汇总
2022-06-23 22:18:00 【路过的小熊~】
简介
寄存器的操作主要是读操作以及写操作。
寄存器写操作
多个寄存器位操作
//GPIO (LED)
#define GPIO_CON (*(volatile unsigned int*)(0xE0200280))
GPIO_CON &= 0XFFFFF8FF; //需要修改D8~D10位,确保D8~D10位为0,其他位不变(只有为0才能确保能正确修改该位的值)
GPIO_CON |= 0X00000100; //更改D8~D10状态 D8~D10写为001配置为GPIO功能
单个寄存器位操作
#define GPIO_CON (*(volatile unsigned int*)(0xE0200280))
GPIO_CON &= ~(1<<7); //D7位置1取反,相当于置0(这样做的目的是为了保证别的位不受影响,只改变需要改变的位)
GPIO_CON |= (1<<7); //将第7位设置为1
寄存器读操作
#define GPIO_CON (*(volatile unsigned int*)(0xE0200280))
GPIO_CON = 0xaa;
printf("reginst====%d======\n", GPIO_CON);
//分别取第8、7、6、5bit位
int a1 = (GPIO_CON & 0x80) >> 7;
int b1 = (GPIO_CON & 0x40) >> 6;
int c1 = (GPIO_CON & 0x20) >> 5;
int d1 = (GPIO_CON & 0x10) >> 4;
int e1 = (GPIO_CON & 0x08) >> 3;
int f1 = (GPIO_CON & 0x04) >> 2;
int g1 = (GPIO_CON & 0x02) >> 1;
int h1 = (GPIO_CON & 0x01) >> 1;
//获取1-4bit位
int i1 = (GPIO_CON & 0x0f);
printf("bit8====%d======\n", a1);
printf("bit7====%d======\n", b1);
printf("bit6====%d======\n", c1);
printf("bit5====%d======\n", d1);
printf("bit4====%d======\n", e1);
printf("bit3====%d======\n", f1);
printf("bit2====%d======\n", g1);
printf("bit1====%d======\n", h1);
printf("bit1-4bit====%d======\n", i1);
边栏推荐
- Digital supply chain management system for metallurgical industry: platform lean enterprise management to help the high-quality development of the industry
- A cartoon reading app highly imitating Tencent comics
- 关于H5移动端用什么自动化测试
- One person even broke up a Netease cloud music Cloud Village
- 这个高仿小米商城项目太惊艳了
- Loop caused by add of sublist in list
- 组合总数II[每个元素只能用一次 + 去重复解集]
- 6月25日PMP考试敏捷怎么考?替你分忧解难
- The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format
- Improvement of DC power distribution with open hall current sensor
猜你喜欢

【HackTheBox】 meow

Taylor formula and common expansion

docker redis集群配置

Leetcode——链表笔试题

Why do MySQL indexes use b+ trees at the bottom? After reading this article, you can easily handle the interview.

Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)

Under the background of aging, the comprehensive energy efficiency management platform escorts hospitals

IDEA 自动生成单元测试,效率倍增!

PyQt5_ Qtablewidget paging radio right-click menu control

开口式霍尔电流传感器助力直流配电改造
随机推荐
Thinking (87): Protocol encryption and compression
Under the background of aging, the comprehensive energy efficiency management platform escorts hospitals
Why can't the netherworld fortress machine be remotely connected to the server? What are the ways to solve such problems?
PyQt5_QTableWidget分页单选右键菜单控件
Recommend 4 flutter heavy open source projects
APP性能优化之启动流程分析
Embedded interface review materials
Taylor formula and common expansion
The digital transformation index report 2021 released by Tencent Research Institute has accelerated the digital transformation and upgrading of mainland enterprises!
Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)
The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format
iNFTnews | 创造者经济的未来在Web3世界中该去向何处?
ACM. HJ89 24点运算 ●●●
再来一个高仿开眼的短视频APP
Leetcode——链表笔试题
文言文能编程???
完整开源项目之诗词吧 APP
Some common tool functions in work
Stm32----- timer
Generative countermeasure networks (Gans) and variants