标题: 小白初学STM8l152c6第一个小程序 [打印本页]

作者: wlsdtiankong    时间: 2018-11-7 11:41
标题: 小白初学STM8l152c6第一个小程序
本人学的第一个STM8l152c6板子的点亮led灯的小程序,不喜勿喷,希望对初学者有帮助,项目建好之后,连接板子,先看看连接有没有问题,如果没问题的话,把下面代码全部覆盖到main.C文件,直接运行ok,有问题@我,看能不能帮上忙谢谢!
  1. #include "stm8l15x.h"
  2. #include "stm8l15x_gpio.h"
  3. #include "stdio.h"
  4. #define BUTTON_GPIO_PORT        GPIOC
  5. #define USER_GPIO_PIN          GPIO_Pin_1

  6. #define LD4_GPIO_PORT           GPIOC
  7. #define LD4                   GPIO_Pin_7
  8. #define LD3_GPIO_PORT           GPIOE
  9. #define LD3                   GPIO_Pin_7
  10. unsigned int x,y;
  11. static void delay_ms(unsigned int ms)//Ñó3ùoˉêy£¬MS ¼¶±e
  12. {
  13. unsigned int x=0,y=0;
  14. for(x = ms;x>0;x--)
  15. {
  16. for(y = 405;y>0;y--);
  17. }
  18. }

  19. void main(void){
  20.   /* ÅäÖà LED4 IO ¿úÎaêä3öÄ£ê½ £¬3õê¼×′ì¬Îaμí*/
  21.   GPIO_Init(LD4_GPIO_PORT, LD4, GPIO_Mode_Out_PP_Low_Fast);
  22.   /* ÅäÖà LED3 IO ¿úÎaêä3öÄ£ê½ £¬3õê¼×′ì¬Îaμí*/
  23.   GPIO_Init(LD3_GPIO_PORT, LD3, GPIO_Mode_Out_PP_Low_Fast);
  24.   while (1){
  25.     if(x==0){
  26.      delay_ms(1000);
  27.      GPIO_ToggleBits(LD4_GPIO_PORT, LD4); //ÇD»» LED4 ×′ì¬
  28.      x++;
  29.     }else if(x==1){
  30.      delay_ms(1000);
  31.      GPIO_ToggleBits(LD3_GPIO_PORT, LD3); //ÇD»» LED3 ×′ì¬
  32.      x=0;
  33.     }
  34.   }
  35. }

  36. #ifdef  USE_FULL_ASSERT
  37. void assert_failed(uint8_t* file, uint32_t line)
  38. {
  39.   while (1)
  40.   {
  41.   }
  42. }
  43. #endif
复制代码




作者: admin    时间: 2018-11-7 15:20
补全原理图或者详细说明一下电路连接即可获得100+黑币
作者: wlsdtiankong    时间: 2018-11-7 15:55
应坛主要求补上电路图一份

作者: wlsdtiankong    时间: 2018-11-7 15:55
admin 发表于 2018-11-7 15:20
补全原理图或者详细说明一下电路连接即可获得100+黑币

以补上




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