原创 学习STM32F的第一个实验跑马灯

2008-6-7 14:44 5493 9 10 分类: MCU/ 嵌入式

为了完成这个实验我是费了九牛二虎之力啊!刚开始是因为库文件的路径没设对编译通不过,好不容易在几位大侠的指点下改了路径编译通过了.仿真运行时系统又一个劲提示堆栈溢出,可是却找不到堆栈设置的地方.后来看了函数库才知道我没有初始化堆栈指针.初始化了NVIC终于调试通过了!


经过这一翻的折磨才发现NVIC的配置是程序运行的最必要条件,没有NVIC的配置程序根本不能正常运行!象其他的RCC和SYSTICK也都很重要但不是必要的,在程序不初始化也可以按照默认方式运行.


/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"


ErrorStatus HSEStartUpStatus;
vu32 count = GPIO_Pin_4;


/*******************************************************************************
* 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 [设置中断向量表的起始位置0x20000000]*/
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 [设置中断向量表的起始位置0x0x08000000]*/
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);  
#endif
}
/*******************************************************************************
* Function Name  : Led_Configuration
* Description    : LED输出配置
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Led_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;


  /* Enable GPIOC clock [使能GPIOC时钟]*/
  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_4 | GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}


/*******************************************************************************
* Function Name  : Led_RW_OFF
* Description    : LED输出低电平
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Led_RW_OFF(void)
{   
  GPIO_ResetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_4 | GPIO_Pin_5);
}


/*******************************************************************************
* Function Name  : Led_RW_ON
* Description    : 轮流点亮4个LED
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Led_RW_ON(void)
{
  switch(count)
  {
      case GPIO_Pin_4:
      {
          Led_RW_OFF();         
          GPIO_SetBits(GPIOC,GPIO_Pin_4 );
          count = GPIO_Pin_5;
      }break;
      case GPIO_Pin_5:
      {
          Led_RW_OFF();      
          GPIO_SetBits(GPIOC,GPIO_Pin_5 );
          count = GPIO_Pin_6;         
      }break;  
      case GPIO_Pin_6:
      {
          Led_RW_OFF(); 
          GPIO_SetBits(GPIOC,GPIO_Pin_6 );
          count = GPIO_Pin_7;
      }break;
      case GPIO_Pin_7:
      {
          Led_RW_OFF(); 
          GPIO_SetBits(GPIOC,GPIO_Pin_7 );
          count = GPIO_Pin_4;         
      }break;       
      default :
      {
          count = GPIO_Pin_4;         
      }break; 
  }
}


/*******************************************************************************
* Function Name  : delay
* Description    : 延时
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void delay(void)
{
  u32 i,j;
  for (i=0; i<0x0fffff; i++)
  {
      j ++;
  }
}



/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{


#ifdef DEBUG
  debug();/*[初始化外围设备指针]*/
#endif
  NVIC_Configuration();
  Led_Config();


  while(1)
  {
      Led_RW_ON();
      delay();
  }
}


#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
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

用户194589 2009-5-10 21:49

不需要configure the system clocks即RCC_configuration();吗? 初学者,莫见笑。
相关推荐阅读
小可歌 2016-05-31 13:54
【转帖】模拟电路的四重境界
无意中看到这个文章,虽然自己也搞了4 年模电了,但后看完之后发现自己原来根本就没有入门阿!现发上来和大家共享!·············   复旦攻读微电子专业模拟芯片设计方向研究生开始到...
小可歌 2016-05-28 07:14
发帖庆祝用app inventor的录音机保存MP3格式录音成功!
看似简单的功能,可是把我难够呛,刚学APP INVENTOR没几天,手里的两本书翻来掉去的看了N遍。APP INVENTOR的录音机默认是保存录音文件为3GP格式,我想保存成MP3文件就没有地方找...
小可歌 2016-02-22 08:56
C语言Printf格式,调试最好的助手!
    C中格式字符串的一般形式为: %[标志][输出最小宽度][.精度][长度]类型, 其中方括号[]中的项为...
小可歌 2016-02-19 15:19
对于SRAM的地址线和数据线是可以打乱顺序用的!!!!
因为SRAM的地址具有唯一性,其实数据线也有唯一性。 也就是A0~A18,D0~D15,都是唯一的。 正常是:A0~A18,接FSMC的A0~A18。 D0~D15,接FSMC的D0~D15. 假...
小可歌 2016-02-02 11:29
Linux系统下基本命令
Linux系统下基本命令: 要区分大小写  uname 显示版本信息(同win2K的 ver)  dir 显示当前目录文件,ls -al 显示包括隐藏文件(同win2K的 dir)  pwd...
小可歌 2016-02-02 11:28
DOS命令大全
对于一般的网民来说,dos命令是什么真的不知道,dos命令有些什么作用也不知道。但是黑客们却精通dos命令,经常利用dos命令进行各种任务,以达到自己的目的。下面笔者为大家汇总出dos命令大全,希...
我要评论
1
9
关闭 站长推荐上一条 /1 下一条