📄 iar-
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: BitBand.c
** Last modified Date: 2007.12.20
** Last Version: V1.1
** Description: Stellaris系列单片机BitBand(位操作)
**
**--------------------------------------------------------------------------------------------------------
** Created By: Shaoxuefeng
** Created date: 2007.09.19
** Version: V1.0
** Descriptions:
**
**--------------------------------------------------------------------------------------------------------
** Modified by: Kang qinhua
** Modified date: 2008.01.12
** Version: V1.1
** Description:
**
*********************************************************************************************************/
#define HWREG(x) (*((volatile unsigned long *)(x))) /* 以字的方式访问寄存器 */
#define HWREGBITW(x, b) HWREG(((unsigned long)(x) & 0xF0000000) | 0x02000000 | \
(((unsigned long)(x) & 0x000FFFFF) << 5) | ((b) << 2))
/* 以字的宽度访问内存单元的位 */
unsigned long GulValue;
/*********************************************************************************************************
** Function name: main
** Descriptions: 主函数
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
int main (void)
{
unsigned long ulErrors, ulIdx;
GulValue = 0;
ulErrors = 0;
for (ulIdx = 0; ulIdx < 32; ulIdx++) {
HWREGBITW(&GulValue, 31 - ulIdx) =
(0x12345678 >> (31 - ulIdx)) & 1; /* 位写入 */
}
if (GulValue != 0x12345678) {
ulErrors++;
} /* 变量值与位写入值是否相等 */
for(ulIdx = 0; ulIdx < 32; ulIdx++) {
if(HWREGBITW(&GulValue, ulIdx) != ((0x12345678 >> ulIdx) & 1)){
ulErrors++;
} /* 以位方式读出GulValue各位 */
/* 与0x12345678比较 */
}
if (ulErrors) {
while(1); /* 位操作出错 */
}
while(1); /* 实验正常完成 */
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -