原理圖:開發板原理圖置于附件中。
功能說明:此程序為入門級程序,我也是一枚剛入門stm32的菜鳥。開發板中的紅、綠、黃、藍燈每相隔0.5s閃一次,同時伴隨著蜂鳴器的響一聲,如此往復
微信圖片_20190529170319.jpg (1.78 MB, 下載次數: 71)
下載附件
2019-5-29 17:03 上傳
電路原理圖如下:
0.png (83.54 KB, 下載次數: 71)
下載附件
2019-5-30 05:43 上傳
主函數代碼:
- /**********時間:2019年5月28日16:53:45*********************/
- #include "stm32f10x.h"
- #include "delay.h"
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void delay(unsigned int ncount);
- unsigned char i = 0; //循環標志
- unsigned int led[4];
- int main(void)
- {
- RCC_Configuration(); //系統時鐘初始化
- GPIO_Configuration(); //端口初始化
- GPIO_SetBits(GPIOC,GPIO_Pin_7);
- GPIO_SetBits(GPIOC,GPIO_Pin_8);
- GPIO_SetBits(GPIOA,GPIO_Pin_12);
- GPIO_SetBits(GPIOC,GPIO_Pin_10);
- Delay_Init();
- led[0] = GPIO_Pin_7;
- led[1] = GPIO_Pin_8;
- led[2] = GPIO_Pin_12;
- led[3] = GPIO_Pin_10;
- //GPIO_SetBits(GPIOB,GPIO_Pin_3);
- while(1)
- {
- for(i=0;i<4;i++)
- {
- if(i!=2)
- GPIO_ResetBits(GPIOC,led[i]);
- else
- GPIO_ResetBits(GPIOA,led[i]);
-
- GPIO_ResetBits(GPIOB,GPIO_Pin_3);
- DelayMs(500);
- GPIO_SetBits(GPIOB,GPIO_Pin_3);
-
- if(i!=2)
- GPIO_SetBits(GPIOC,led[i]);
- else
- GPIO_SetBits(GPIOA,led[i]);
- DelayMs(500);
-
- }
-
- }
- }
- void delay(unsigned int ncount)
- {
- for(;ncount!=0;ncount--);
- }
- void RCC_Configuration(void)
- {
- SystemInit(); //系統時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE); //打開GPIOA和GPIOC時鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure; //定義GPIO結構體
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_10|GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOC,&GPIO_InitStructure);
-
- //GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); //禁止JTAG功能
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- }
復制代碼 全部資料51hei下載地址:
程序+原理圖.7z
(253.32 KB, 下載次數: 18)
2019-5-30 05:43 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|