www.pudn.com > ARM-Cortex-M3.zip > BitBand.C, change:2007-11-09,size:2905b


/****************************************Copyright (c)**************************************************** 
**                               Guangzhou ZHIYUAN electronics Co.,LTD. 
**                                      
**                                 http://www.embedtools.com 
** 
**--------------File Info--------------------------------------------------------------------------------- 
** File Name:                   BitBand.c 
** Last modified Date:          2007-09-19  
** Last Version:                v1.0 
** Description:                 Stellaris系列单片机BitBand(位操作) 
**  
**-------------------------------------------------------------------------------------------------------- 
** Created By:                  Shaoxuefeng 
** Created date:                2007-09-19  
** Version:                     v1.0 
** Descriptions: 
** 
**-------------------------------------------------------------------------------------------------------- 
** Modified by: 
** Modified date: 
** Version: 
** 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; 
 
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 
*********************************************************************************************************/