|
发表于 2008-8-12 10:52:50
|
显示全部楼层
对于Bit Band的操作,可以看看下面的这个Example,里面涉及到几种方法使用这个功能。在IAR下是可以支持的,MDK下不知道,我没试过。例子来源与ST在07年6月做的CM3培训 动手练习4。
点击此处下载 ourdev_375173.rar(文件大小:70K) (原文件名:LAB4.rar)
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Date First Issued : 02/05/2007
* Description : Main program body
********************************************************************************
* History:
* 04/02/2007: V0.2
* 02/05/2007: V0.1
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//#define LAB4_PART1
//#define LAB4_PART2
#define LAB4_PART3
/* GPIOC offset */
#define GPIOC_OFFSET (GPIOC_BASE - PERIPH_BASE)
/* GPIOC BSRR offset */
#define GPIOC_BSRR_OFFSET (GPIOC_OFFSET + 0x10)
#ifdef LAB4_PART2
/* define the bit set number for PC0.6, PC.07, PC.08 & PC.09 in the BSRR*/
#define GPIOC_Bit6_SET ((u8)0x06)
#define GPIOC_Bit7_SET ((u8)0x07)
#define GPIOC_Bit8_SET ((u8)0x08)
#define GPIOC_Bit9_SET ((u8)0x09)
/* define the bit set address in the alias region for PC0.6, PC.07, PC.08 & PC.09*/
#define GPIOC_Bit6_SET_BB (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit6_SET * 4))
#define GPIOC_Bit7_SET_BB (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit7_SET * 4))
#define GPIOC_Bit8_SET_BB (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit8_SET * 4))
#define GPIOC_Bit9_SET_BB (PERIPH_BB_BASE + (GPIOC_BSRR_OFFSET * 32) + (GPIOC_Bit9_SET * 4))
#endif
#ifdef LAB4_PART3
#define GPIOC_BRR_OFFSET (GPIOC_OFFSET + 0x14)
#endif
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* Enable GPIOC clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* Configure PC.06, PC.07, PC.08 and PC.09 as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1)
{
#ifdef LAB4_PART1
/* Turn on led connected to PC.06 pin */
GPIO_Write(GPIOC, GPIO_Pin_6);
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.07 pin */
GPIO_Write(GPIOC, GPIO_Pin_7);
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.08 pin */
GPIO_Write(GPIOC, GPIO_Pin_8);
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.08 pin */
GPIO_Write(GPIOC, GPIO_Pin_9);
/* Insert delay */
Delay(0x7FFFF);
#endif /* LAB4_PART1 */
#ifdef LAB4_PART2
/* Turn off leds connected to PC.06, PC.07, PC.08 & PC.09 pin */
GPIO_Write(GPIOC, (u16) ~(GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9));
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.06 pin using bit band */
*(vu32 *) GPIOC_Bit6_SET_BB = 1;
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.07 pin using bit band */
*(vu32 *) GPIOC_Bit7_SET_BB = 1;
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.08 pin using bit band */
*(vu32 *) GPIOC_Bit8_SET_BB = 1;
/* Insert delay */
Delay(0x7FFFF);
/* Turn on led connected to PC.09 pin using bit band */
*(vu32 *) GPIOC_Bit9_SET_BB = 1;
/* Insert delay */
Delay(0x7FFFF);
#endif /* LAB4_PART2 */
#ifdef LAB4_PART3
/* Turn on leds connected to PC.06, PC.07, PC.08 & PC.09 pin */
*(vu32 *) (GPIOC_BRR_OFFSET + PERIPH_BASE) = (u32) (GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
/* Insert delay */
Delay(0x7FFFF);
/* Turn off leds connected to PC.06, PC.07, PC.08 & PC.09 pin */
*(vu32 *) (GPIOC_BRR_OFFSET + PERIPH_BASE) = (u32) (GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
/* Insert delay */
Delay(0x7FFFF);
#endif /* LAB4_PART3 */
}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
{
}
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK */
RCC_PCLK1Config(RCC_HCLK_Div1);
/* Select HSE as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
/* Wait till HSE is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x04)
{
}
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert error has occurred.
* Input : - file: pointer to the source file name
* - line: assert error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
void Delay(vu32 nCount)
{
for(; nCount!= 0;nCount--);
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/ |
|