全球首發 全世界第一個protues 仿真stm32 f103 實現spi
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
01.jpg (87.46 KB, 下載次數: 200)
下載附件
2017-9-4 17:53 上傳
0.png (47.63 KB, 下載次數: 146)
下載附件
2017-9-4 18:06 上傳
stm32單片機源程序如下:
- #include "stm32f10x.h"
- #include "spi.h"
- #include "Module.h"
- #include<stdio.h>
- void Delay_Ms(u16 time);
- void RCC_Configuration(void);
- //void GPIO_Configuration(void);
- u32 retry=0;
- int i=0;
- /* Private functions ---------------------------------------------------------*/
- /*******************************************************************************
- * Function Name : main
- * Description : Main program.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- int main(void)
- {
- RCC_Configuration();//使能外設時鐘
- //GPIO_Configuration();
- SEG_Init();
- SPI1_Init();
- //SPI1_SetSpeed(SPI_BaudRatePrescaler_256);
-
- //========實現數碼管顯示==========
- while (1)
- {
-
-
- SEG_Display(8830,0);
-
-
- /*for(i=0;i<9999;i++)
- {
- for(j=0;j<500;j++)
- SEG_Display(i,0);
- } */
- //SEG_Display(1234,3);
- }
- }
- /*******************************************************************************
- * Function Name : Delay_Ms
- * Description : delay 1 ms.
- * Input : time (ms)
- * Output : None
- * Return : None
- *******************************************************************************/
- void Delay_Ms(u16 time) //延時函數
- {
- u16 i,j;
- for(i=0;i<time;i++)
- for(j=1000;j>0;j--);
- }
- /*******************************************************************************
- * Function Name : RCC_Configuration
- * Description : Configures the different system clocks.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- //==========================使用外部RC晶振========================================
- RCC_DeInit(); //初始化為缺省狀態
- //RCC_HSICmd(ENABLE);
- RCC_HSEConfig(RCC_HSE_ON); //高速時鐘使能
- while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); //等待高速時鐘使能就緒
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //Enable Prefetch Buffer
- FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state
- RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
- RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
- RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHz
- RCC_PLLCmd(ENABLE); // Enable PLL
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // Wait till PLL is ready
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source
- while(RCC_GetSYSCLKSource() != 0x08); // Wait till PLL is used as system clock source
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); // 使能APB2外設GPIOA時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE); // 使能APB2外設GPIOB時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE); // 使能APB2外設GPIOC時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 , ENABLE); // 使能APB2外設SPI1時鐘
- }
復制代碼
所有資料51hei提供下載:
protues stm32 f103 實現spi.rar
(1.56 MB, 下載次數: 859)
2017-9-4 18:07 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|