找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 10871|回复: 0
打印 上一主题 下一主题
收起左侧

stm32滴答SYSTICK中断模式设置

[复制链接]
跳转到指定楼层
楼主
ID:82781 发表于 2015-6-14 01:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
SYSTICK中断模式!实验
这是MAIN文件
  1. #include "main.h"
  2. #include "myuse.h"
  3. extern unsigned int count;
  4. /*
  5.   全局变量在多文件中的定义方法,。h文件只是用来声明变量和函数的,不是用来定义实体变量的
  6.   要在一个.c文件和另一个。c文件中使用同一个变量,要在一个.c文件中先定义入:uint a;然后再在
  7.   另一个.c文件中用 extern uint a;定义一下,就OK乐,就是全局变量!!!!!而且是同一个变量!
  8.   ,天津第四项目部宿舍


  9. */

  10. /** @addtogroup STM32F10x_StdPeriph_Examples
  11.   * @{
  12.   */

  13. /** @addtogroup SysTick_TimeBase
  14.   * @{
  15.   */

  16. /* Private typedef -----------------------------------------------------------*/
  17. /* Private define ------------------------------------------------------------*/
  18. /* Private macro -------------------------------------------------------------*/
  19. /* Private variables ---------------------------------------------------------*/
  20. static __IO uint32_t TimingDelay;

  21. /* Private function prototypes -----------------------------------------------*/
  22. void Delay(__IO uint32_t nTime);

  23. /* Private functions ---------------------------------------------------------*/

  24. /**
  25.   * @brief  Main program.
  26.   * @param  None
  27.   * @retval None
  28.   */
  29. GPIO_InitTypeDef GPIO_InitStructure;
  30. void mysysint()//系统初始化程序
  31. {
  32. ErrorStatus HSEStartUpStatus;//说明标志位
  33. RCC_DeInit();//所有外设全部缺省设置

  34. /* Enable HSE */
  35. RCC_HSEConfig(RCC_HSE_ON);
  36. /* Wait till HSE is ready and if Time out is reached exit */
  37. HSEStartUpStatus = RCC_WaitForHSEStartUp();
  38. if(HSEStartUpStatus == SUCCESS)//启动成功
  39. {
  40. /*这两条FLASH指令必须加上,不知为啥?不加上就运行几秒后出错,参照系统初始化*/
  41. /* Enable The Prefetch Buffer */
  42. FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//FLASH缓存开启
  43. /* Configure the Latency cycle: Set 2 Latency cycles */
  44.   FLASH_SetLatency(FLASH_Latency_2);  //设置FLASH这些位表示SYSCLK(系统时钟)周期与闪存访问时间的比例,为010:两个等待状态,当 48MHz < SYSCLK ≤ 72MHz
  45. /* Set PLL clock output to 72MHz using HSE (8MHz) as entry clock */
  46. RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//外部时钟为8M,PLL的输入时钟=8MHZ,倍频系数9,

  47. /* Configure HCLK such as HCLK = SYSCLK */
  48. RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置了啦AHB分频器的分频系数=1,即HCLK=SYSCLK=72MHZ
  49. /* Configure PCLK1 such as PCLK1 = HCLK/2 */
  50. RCC_PCLK1Config(RCC_HCLK_Div2);//设置了APB1外设的时钟频率最大是36M这里是APB1的分频器设为2,PCLK1=HCLK/2=72/2=36MHZ正好是最大值
  51. /* Configure PCLK2 such as PCLK2 = HCLK */
  52. RCC_PCLK2Config(RCC_HCLK_Div1);//设置PLCK2=HCLK=72MHZ,的APB2分频器=1
  53. /* Select the PLL as system clock source */
  54. RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//设置了SYSCLK的提供者为PLL,频率由上面算出=72MHZ
  55. /* disable PLL Ready interrupt */
  56. RCC_ITConfig(RCC_IT_PLLRDY, DISABLE);//PLL中断关闭
  57. /* disable PLL Ready interrupt */
  58. RCC_ITConfig(RCC_IT_HSERDY,DISABLE);//HSE中断关闭
  59. /* disable PLL Ready interrupt */
  60. RCC_ITConfig(RCC_IT_HSIRDY, DISABLE); //HSI中断关闭
  61. /* disable PLL Ready interrupt */
  62. RCC_ITConfig(RCC_IT_LSERDY, DISABLE); //LSE中断关闭
  63. /* disable PLL Ready interrupt */
  64. RCC_ITConfig(RCC_IT_LSIRDY, DISABLE); //LSI中断关闭

  65. /* PLL clock divided by 1.5 used as USB clock source */
  66. RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);//设置USB的时钟为=72、1.5=48mhz
  67. /* Configure ADCCLK such as ADCCLK = PCLK2/2 */
  68. RCC_ADCCLKConfig(RCC_PCLK2_Div2);//设置ADC时钟=PCLK2/2= 36MHZ
  69. /* disable the LSE */
  70. RCC_LSEConfig(RCC_LSE_OFF);//外部低速晶振关闭

  71. /*DISable the RTC clock */
  72. RCC_RTCCLKCmd(DISABLE);
  73. /* DISable the Clock Security System */
  74. RCC_ClockSecuritySystemCmd(DISABLE);
  75. /* Enable the PLL */
  76. RCC_PLLCmd(ENABLE);//使能PLL







  77. /* PLL ans system clock config */
  78. }
  79. else
  80. {
  81. /* Add here some code to deal with this error */
  82. }





  83. }
  84. void mysystickint()
  85. {
  86. SysTick->LOAD=71999;//加载值=1ms
  87. SCB->SHP[11]=15;//设置SYSTICK的优先级为15,注意SYSTICK属于系统异常,所以他的优先级在SCB里设置。
  88. SysTick->CTRL=7;//开启中断,开启定时器,时钟设置为HCLK=72mhz






  89. }

  90. int main(void)
  91. {
  92.   mysysint();//系统初始化
  93.    /* GPIOD Periph clock enable */
  94.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);//使能时钟
  95. /* Configure PD0 and PD2 in output pushpull mode */
  96.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11;
  97.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  98.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  99.   GPIO_Init(GPIOD, &GPIO_InitStructure);

  100.   mysystickint();  //w我设置的SYStick工作在中断模式
  101.   while(1);

  102.    

  103. }
复制代码





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表