标题: Proteus仿真stm32f103实现SPI [打印本页]

作者: hecheng0503    时间: 2018-8-23 15:12
标题: Proteus仿真stm32f103实现SPI
stm32f103实现SPI的仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "spi.h"
  3. #include "Module.h"

  4. #include<stdio.h>



  5. void Delay_Ms(u16 time);
  6. void RCC_Configuration(void);
  7. //void GPIO_Configuration(void);
  8. u32 retry=0;       
  9. int i=0;

  10. /* Private functions ---------------------------------------------------------*/
  11. /*******************************************************************************
  12. * Function Name  : main
  13. * Description    : Main program.
  14. * Input          : None
  15. * Output         : None
  16. * Return         : None
  17. *******************************************************************************/
  18. int main(void)
  19. {

  20.           RCC_Configuration();//使能外设时钟
  21.         //GPIO_Configuration();
  22.         SEG_Init();
  23.         SPI1_Init();       
  24.         //SPI1_SetSpeed(SPI_BaudRatePrescaler_256);       
  25.        
  26.        

  27.        

  28.        
  29.        
  30.        

  31.        

  32.         //========实现数码管显示==========
  33.           while (1)
  34.           {
  35.                        
  36.                        

  37. SEG_Display(8830,0);
  38.                        
  39.                        
  40.                 /*for(i=0;i<9999;i++)
  41.                 {
  42.                         for(j=0;j<500;j++)
  43.                                 SEG_Display(i,0);
  44.                 }        */          
  45.                 //SEG_Display(1234,3);
  46.           }
  47. }

  48. /*******************************************************************************
  49. * Function Name  : Delay_Ms
  50. * Description    : delay 1 ms.
  51. * Input          : time (ms)
  52. * Output         : None
  53. * Return         : None
  54. *******************************************************************************/
  55. void Delay_Ms(u16 time)  //延时函数
  56. {
  57.         u16 i,j;
  58.         for(i=0;i<time;i++)
  59.                   for(j=1000;j>0;j--);
  60. }

  61. /*******************************************************************************
  62. * Function Name  : RCC_Configuration
  63. * Description    : Configures the different system clocks.
  64. * Input          : None
  65. * Output         : None
  66. * Return         : None
  67. *******************************************************************************/
  68. void RCC_Configuration(void)
  69. {
  70.         //==========================使用外部RC晶振========================================
  71.           RCC_DeInit();                                //初始化为缺省状态
  72.         //RCC_HSICmd(ENABLE);
  73.           RCC_HSEConfig(RCC_HSE_ON);  //高速时钟使能
  74.           while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);  //等待高速时钟使能就绪

  75.     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);        //Enable Prefetch Buffer
  76.     FLASH_SetLatency(FLASH_Latency_2);                                                  // Flash 2 wait state
  77.     RCC_HCLKConfig(RCC_SYSCLK_Div1);                                                 // HCLK = SYSCLK
  78.     RCC_PCLK2Config(RCC_HCLK_Div1);                                                        // PCLK2 = HCLK
  79.     RCC_PCLK1Config(RCC_HCLK_Div2);                                                          // PCLK1 = HCLK/2
  80.     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);        // PLLCLK = 8MHz * 9 = 72 MHz  
  81.     RCC_PLLCmd(ENABLE);                                                                                  // Enable PLL
  82.     while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);                // Wait till PLL is ready

  83.     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);                                  // Select PLL as system clock source
  84.     while(RCC_GetSYSCLKSource() != 0x08);                                        // Wait till PLL is used as system clock source
  85.        
  86.        
  87.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);        // 使能APB2外设GPIOA时钟
  88.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);        // 使能APB2外设GPIOB时钟
  89.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);        // 使能APB2外设GPIOC时钟
  90.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 , ENABLE);        // 使能APB2外设SPI1时钟
  91. }
复制代码

所有资料51hei提供下载:
protues stm32 f103 实现spi.rar (1.56 MB, 下载次数: 253)



作者: gaoyanzeng    时间: 2018-12-4 22:21
感谢分享,非常感谢。
作者: rxr1996    时间: 2018-12-8 16:35
感谢分享,非常感谢。
作者: fly_apple    时间: 2018-12-8 22:13
不错不错,谢谢楼主
作者: xiesonny    时间: 2019-4-23 03:01
真的好东西啊,感谢
作者: xdrxdr    时间: 2019-9-26 11:52
Thanks  for  your  share
作者: caivivi    时间: 2019-12-28 19:26
请问如果连液晶显示屏如何在protues上实现呢

作者: ahahaha2333    时间: 2020-3-3 16:58
谢谢

作者: 人生不设限    时间: 2020-3-5 11:13
这个好,感谢分享,自己也试着做一套,这样用来放仿真一些简单的电路就很方便了
作者: c1651006118    时间: 2020-3-5 17:14
问一下,为什么我protues8.0打开楼主的工程文件会导致软件自退啊
作者: 1244986336    时间: 2020-3-27 09:39
很不错,感谢分享
作者: pojian    时间: 2020-7-14 17:00
谢谢大佬谢谢大佬谢谢大佬谢谢大佬谢谢大佬谢谢大佬谢谢大佬谢谢大佬




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1