找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 624|回复: 0
收起左侧

STM32F1定时器程序

[复制链接]
ID:858372 发表于 2020-12-20 21:51 | 显示全部楼层 |阅读模式
  1. #include "main.h"

  2. void delay()
  3. {
  4.         u16 i,j=10000;
  5.         for(i=0;i<42;i++)
  6.                 while(j--);
  7. }

  8. u8 flag_500ms=0;
  9. u8 flag_300ms=0;

  10. int main()
  11. {
  12.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  13.         RCC_Configuration();
  14.         GPIO_Config();
  15.         TIM2_Init();
  16.         TIM3_Init();
  17.         while(1)
  18.         {       
  19.                 if(flag_300ms==1)
  20.                 {
  21.                         flag_300ms=0;
  22.                         GPIO_WriteBit(GPIOA,GPIO_Pin_8,(BitAction)(!GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_8)));
  23.                 }
  24.                 if(flag_500ms==1)
  25.                 {
  26.                         flag_500ms=0;
  27.                         GPIO_WriteBit(GPIOA,GPIO_Pin_4,(BitAction)(!GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_4)));
  28.                 }
  29.         }
  30. }
复制代码


定时器.7z

177.58 KB, 下载次数: 6, 下载积分: 黑币 -5

回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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