找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2066|回复: 3
收起左侧

小白初学STM8l152c6第一个小程序

[复制链接]
ID:419511 发表于 2018-11-7 11:41 | 显示全部楼层 |阅读模式
本人学的第一个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
复制代码



回复

使用道具 举报

ID:1 发表于 2018-11-7 15:20 | 显示全部楼层
补全原理图或者详细说明一下电路连接即可获得100+黑币
回复

使用道具 举报

ID:419511 发表于 2018-11-7 15:55 | 显示全部楼层
b0e5850714791711cd79170d.jpg 应坛主要求补上电路图一份
回复

使用道具 举报

ID:419511 发表于 2018-11-7 15:55 | 显示全部楼层
admin 发表于 2018-11-7 15:20
补全原理图或者详细说明一下电路连接即可获得100+黑币

以补上
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表