一、建立项目模板
![](/attachment/201702/1/29512885_1485957968Tthd.png)
Output中选择Create HEXFile,并且可以选择输出路径。
Listing中可以选择输出路径。
然后在C/C++中加入两个宏:
- STM32F10X_MD,USE_STDPERIPH_DRIVER
![](/attachment/201702/1/29512885_148595808374SS.png)
在Debug中,使用J-Link,并设置
在Utilities,选择J-Link并Setting中:
![](/attachment/201702/1/29512885_1485958138kmwa.png)
二、写点LED代码
GPIO初始化:- /**8位的LED的IO口***/
- #define PIN_LED (GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_11 |GPIO_Pin_12 |GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15)
- void LED_INIT(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = PIN_LED;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
-
- /*打开LED使用的GPIO的时钟使能*/
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- /*进行初始化*/
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- /****************************
- * Function Name : LED_SET
- * Description : 设置LED的状态,使用了8位。因为一次使用16位,所以要先读取
- * Input : data
- * Output : None
- * Return : None
- *****************************/
- void LED_SET(uint8_t data)
- {
- uint16_t setValue;
-
- setValue = GPIO_ReadOutputData(GPIOB);
- setValue &= 0x00ff; //使用高8位
- setValue |= (uint16_t)data <<8;
-
- GPIO_Write(GPIOB, setValue);
- }
- /****************************************************************************
- * Function Name : main
- * Description : Main program.
- * Input : None
- * Output : None
- * Return : None
- ****************************************************************************/
-
- int main(void)
- {
- LED_INIT();
- LED_SET(0x0f);
-
- while (1)
- {
- LED_SET(0xff);
- Delay(10);
- LED_SET(0x00);
- Delay(10);
- }
- }
-
- /*******************************************************************************
- * Function Name : Delay
- * Description : ???±???ò
- * Input : c
- * Output : None
- * Return : None
- *******************************************************************************/
-
- void Delay(uint16_t c)
- {
- uint16_t a,b;
- for(; c>0; c--)
- for(a=1000; a>0; a--)
- for(b=1000; b>0; b--);
- }
- GPIO_WriteBit(GPIOB, GPIO_Pin_15, Bit_SET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_15, Bit_RESET);
给主人留下些什么吧!~~
评论热议