数码之家

 找回密码
 立即注册
搜索
查看: 2512|回复: 11

[STM] 请大家帮忙给写一个stm32的频闪灯程序吧

[复制链接]
发表于 2020-8-11 13:31:25 来自手机浏览器 | 显示全部楼层 |阅读模式
30家元
请大家帮忙给写一个stm32的频闪灯程序吧,就是控制灯快速的闪烁2下之后过个30秒在闪烁2次频闪的效果,如果不用单片机用电路也可以请大家帮忙谢谢。

发表于 2020-8-11 15:40:18 | 显示全部楼层
1块钱的8脚stm8s003,程序百度一下5分钟也能搞定了
回复

使用道具 举报

发表于 2020-8-11 16:27:40 | 显示全部楼层
这应该是最简单的点灯程序了。单片机如果不干别的事,直接软件延时,用cube配置好管脚,几行代码就行了。如果单片机还要干别的事,开一个定时器,定时到30秒闪灯就好。更高级的用RTOS。
回复

使用道具 举报

发表于 2020-8-11 23:57:08 | 显示全部楼层

上STM32就浪费了,8脚的STC15F104就够了。不用单片机的话就用两个NE555,不过电路太复杂了,还要调参数。8脚的STC不香么。

#include <AT89X51.h>

sbit LED = P3^
3;        //LED低电平点亮

//延时约1ms
void Delay(unsigned int t)
{
   
unsigned int a,b;
   
for (a=0; a<t; a++)
        
for (b=0; b<123; b++)
            ;
}

void main(void)
{
    LED =
1;
   
while(1)
    {
        Delay(
30000);   //延时30S
        
        LED =
0;        //亮0.3S
        Delay(300);
        
        LED =
1;        //灭0.3S
        Delay(300);
        
        LED =
0;        //亮0.3S
        Delay(300);
        
        LED =
1;        //灭0.3S
        Delay(300);
    }
}




打赏

参与人数 1家元 +16 收起 理由
数码家园 + 16 熱心會員

查看全部打赏

回复

使用道具 举报

发表于 2020-8-12 08:13:01 | 显示全部楼层
elecfunwb 发表于 2020-8-11 23:57
上STM32就浪费了,8脚的STC15F104就够了。不用单片机的话就用两个NE555,不过电路太复杂了,还要调参数。8 ...

用6脚的OTP单片机,成本2-3毛,不更爽?

顺便说一下,楼上没有指明STC15F104的工作频率。
回复

使用道具 举报

发表于 2020-8-12 09:25:13 | 显示全部楼层
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * [url=home.php?mod=space&uid=650075]@brief[/url]          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>© Copyright (c) 2020 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19. /* USER CODE END Header */

  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "gpio.h"

  23. /* Private includes ----------------------------------------------------------*/
  24. /* USER CODE BEGIN Includes */

  25. /* USER CODE END Includes */

  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN PTD */

  28. /* USER CODE END PTD */

  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN PD */
  31. /* USER CODE END PD */

  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN PM */

  34. /* USER CODE END PM */

  35. /* Private variables ---------------------------------------------------------*/

  36. /* USER CODE BEGIN PV */

  37. /* USER CODE END PV */

  38. /* Private function prototypes -----------------------------------------------*/
  39. void SystemClock_Config(void);
  40. /* USER CODE BEGIN PFP */

  41. /* USER CODE END PFP */

  42. /* Private user code ---------------------------------------------------------*/
  43. /* USER CODE BEGIN 0 */

  44. /* USER CODE END 0 */

  45. /**
  46.   * @brief  The application entry point.
  47.   * @retval int
  48.   */
  49. int main(void)
  50. {
  51.   /* USER CODE BEGIN 1 */

  52.   /* USER CODE END 1 */

  53.   /* MCU Configuration--------------------------------------------------------*/

  54.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  55.   HAL_Init();

  56.   /* USER CODE BEGIN Init */

  57.   /* USER CODE END Init */

  58.   /* Configure the system clock */
  59.   SystemClock_Config();

  60.   /* USER CODE BEGIN SysInit */

  61.   /* USER CODE END SysInit */

  62.   /* Initialize all configured peripherals */
  63.   MX_GPIO_Init();
  64.   /* USER CODE BEGIN 2 */

  65.   /* USER CODE END 2 */

  66.   /* Infinite loop */
  67.   /* USER CODE BEGIN WHILE */
  68.   while (1)
  69.   {
  70.     /* USER CODE END WHILE */
  71.    HAL_GPIO_TogglePin(GPIOC, led_Pin);
  72.    HAL_Delay(500);
  73.     /* USER CODE BEGIN 3 */
  74.   }
  75.   /* USER CODE END 3 */
  76. }

  77. /**
  78.   * @brief System Clock Configuration
  79.   * @retval None
  80.   */
  81. void SystemClock_Config(void)
  82. {
  83.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  84.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  85.   /** Initializes the CPU, AHB and APB busses clocks
  86.   */
  87.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  88.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  89.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  90.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  91.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  92.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL8;
  93.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  94.   {
  95.     Error_Handler();
  96.   }
  97.   /** Initializes the CPU, AHB and APB busses clocks
  98.   */
  99.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  100.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  101.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  102.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  103.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  104.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  105.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  106.   {
  107.     Error_Handler();
  108.   }
  109. }

  110. /* USER CODE BEGIN 4 */

  111. /* USER CODE END 4 */

  112. /**
  113.   * @brief  This function is executed in case of error occurrence.
  114.   * @retval None
  115.   */
  116. void Error_Handler(void)
  117. {
  118.   /* USER CODE BEGIN Error_Handler_Debug */
  119.   /* User can add his own implementation to report the HAL error return state */

  120.   /* USER CODE END Error_Handler_Debug */
  121. }

  122. #ifdef  USE_FULL_ASSERT
  123. /**
  124.   * @brief  Reports the name of the source file and the source line number
  125.   *         where the assert_param error has occurred.
  126.   * @param  file: pointer to the source file name
  127.   * @param  line: assert_param error line source number
  128.   * @retval None
  129.   */
  130. void assert_failed(uint8_t *file, uint32_t line)
  131. {
  132.   /* USER CODE BEGIN 6 */
  133.   /* User can add his own implementation to report the file name and line number,
  134.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  135.   /* USER CODE END 6 */
  136. }
  137. #endif /* USE_FULL_ASSERT */

  138. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码


回复

使用道具 举报

发表于 2020-8-12 09:28:22 | 显示全部楼层
这是编译好的文件

LED001.rar

3.5 KB, 下载次数: 1, 下载积分: 家元 -55

回复

使用道具 举报

发表于 2020-8-12 13:28:48 | 显示全部楼层
路过羊圈的狼 发表于 2020-8-12 08:13
用6脚的OTP单片机,成本2-3毛,不更爽?

顺便说一下,楼上没有指明STC15F104的工作频率。 ...

烧录器不要钱么
因为我没具体测延时时间
回复

使用道具 举报

发表于 2020-8-12 15:48:46 来自手机浏览器 | 显示全部楼层
路过羊圈的狼 发表于 2020-8-12 08:13
用6脚的OTP单片机,成本2-3毛,不更爽?

顺便说一下,楼上没有指明STC15F104的工作频率。 ...

我不会单片机,我的电路也是两个555做的
回复

使用道具 举报

发表于 2020-8-12 23:58:20 | 显示全部楼层
一定要STM32吗?单片机仅仅只是闪灯?还干别的活不?
回复

使用道具 举报

发表于 2020-8-13 10:46:12 | 显示全部楼层
如果时间不是严格的话,一片CD4060就够了。成本0.1元

回复

使用道具 举报

发表于 2020-8-18 17:34:33 | 显示全部楼层
7毛包邮的STC8G1K08  SOP8 不香?
回复

使用道具 举报

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

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-4-30 10:23 , Processed in 0.327601 second(s), 13 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

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