标题: CHSF103C8T6单片机点亮led [打印本页]

作者: liqingb    时间: 2021-3-25 10:23
标题: CHSF103C8T6单片机点亮led
CHSF103C8T6为国产32位单片机,性能也挺好,可部分代替说stm32F103C8T6。
本次程序为点亮led:
  1. //io引脚配置
  2. #include "led.h"

  3. //LED IO初始化
  4. void LED_Init(void)
  5. {

  6. GPIO_InitTypeDef  GPIO_InitStructure;
  7.          
  8. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);         //使能PB,PE端口时钟
  9.         
  10. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;                                 //LED0-->PB.5 端口配置
  11. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //推挽输出
  12. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                 //IO口速度为50MHz
  13. GPIO_Init(GPIOC, &GPIO_InitStructure);                                         //根据设定参数初始化GPIOB.5
  14. GPIO_SetBits(GPIOC,GPIO_Pin_13);                                                 //PB.5 输出高
  15. }


  16. #include "delay.h"
  17. #include "sys.h"
  18. #include "led.h"
  19. #include "timer.h"

  20. int main(void)
  21. {
  22.         u16 t;
  23.         delay_init();
  24.         LED_Init();
  25.         while(1)
  26.         {
  27.                 LED0=0;
  28.                 delay_ms(1000);
  29.                 LED0=1;
  30.                 delay_ms(1000);
  31.         }
  32. }



复制代码

{

GPIO_InitTypeDef  GPIO_InitStructure;
         
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);         //使能PB,PE端口时钟
        
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;                                 //LED0-->PB.5 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                 //IO口速度为50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure);                                         //根据设定参数初始化GPIOB.5
GPIO_SetBits(GPIOC,GPIO_Pin_13);                                                 //PB.5 输出高
}






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