当前位置:网站首页>Summary of common register bit operation modes in MCU

Summary of common register bit operation modes in MCU

2022-06-24 00:03:00 Passing bear~

brief introduction

Register operations are mainly read operations and write operations .

Register write operation

Multiple register bit operations

//GPIO (LED)

#define GPIO_CON (*(volatile unsigned int*)(0xE0200280))

GPIO_CON &= 0XFFFFF8FF; // Need modification D8~D10 position , Make sure D8~D10 Position as 0, Other bits remain the same ( Only for 0 To ensure that the value of this bit can be modified correctly )
GPIO_CON |= 0X00000100; // change D8~D10 state  D8~D10 Written as 001 Configure to GPIO function 

Single register bit operation

#define GPIO_CON (*(volatile unsigned int*)(0xE0200280))

GPIO_CON &= ~(1<<7);	//D7 Location 1 Take the opposite , Equivalent to setting 0( The purpose of this is to ensure that other bits are not affected , Change only the bits that need to be changed )
GPIO_CON |= (1<<7); // Will be the first 7 Bit is set to 1


Register read operation

#define GPIO_CON (*(volatile unsigned int*)(0xE0200280))

GPIO_CON = 0xaa;
printf("reginst====%d======\n", GPIO_CON);
// Take... Respectively 8、7、6、5bit position 
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;
// obtain 1-4bit position 
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);
		
原网站

版权声明
本文为[Passing bear~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206232114040509.html