全球首发 全世界第一个protues 仿真stm32 f103 实现spi
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
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)
|