*Fxx and string

本文介绍了一个字符串匹配的问题,要求找出特定的三个字符'y', 'r', 'x'在字符串中的位置是否形成等比数列,并提供了一种有效的算法实现。

Fxx and string

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 715    Accepted Submission(s): 311


Problem Description
Young theoretical computer scientist Fxx get a string which contains lowercase letters only.

The string S contains n lowercase letters S1S2Sn .Now Fxx wants to know how many three tuple (i,j,k) there are which can meet the following conditions:

1、 i,j,k are adjacent into a geometric sequence.

2、 Si= ' y ' ,Sj= ' r ' ,Sk= ' x '.

3.Either j|i or j|k
 

Input
In the first line, there is an integer T(1T100) indicating the number of test cases.

T lines follow, each line contains a string, which contains only lowercase letters.(The length of string will not exceed 10000 ).
 

Output
For each case, output the answer.
 

Sample Input
  
2 xyyrxx yyrrxxxxx
 

Sample Output
  
0 2
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5960  5959  5958  5957  5956 
题意:给定一个字符串,找出符合要求的:下标成等比数列且对应字母与题中相符。注意1 2 4与4 2 1是两种
题解:一开始想到的是三重循环,不用试也知道超时,所以可以循环比例数j,i为数列最小值,随后是i*j,i*j*j
code:
#include<cstdio>
#include<cstring>
char s[10000];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
	scanf("%s",s+1);
	int l=strlen(s+1);
	int num=0;
	for(int i=1;i<=l;i++)
	{
		for(int j=2;i*j*j<=l;j++)
		{
			if(s[i]=='y'&&s[i*j]=='r'&&s[i*j*j]=='x')
			num++;
			if(s[i]=='x'&&s[i*j]=='r'&&s[i*j*j]=='y')
			num++;
		}
		}
	printf("%d\n",num);	
	} 
	return 0;
 } 


 
#include "oled.h" #include "oledfont.h" #include "i2c.h" #include "main.h" //OLED??? //??????. //[0]0 1 2 3 ... 127 //[1]0 1 2 3 ... 127 //[2]0 1 2 3 ... 127 //[3]0 1 2 3 ... 127 //[4]0 1 2 3 ... 127 //[5]0 1 2 3 ... 127 //[6]0 1 2 3 ... 127 //[7]0 1 2 3 ... 127 /** * @brief OLED???? * @param cmd - ????? * @note ???,????????API?? */ static void OLED_Write_Cmd(uint8_t cmd) { uint8_t buf[2]; buf[0] = 0x00; //control byte buf[1] = cmd; //??HAL??API?? HAL_I2C_Master_Transmit(&hi2c1, 0x78, buf, 2, 0xFFFF); } /** * @brief OLED???? * @param cmd - ????? * @note ???,????????API?? */ static void OLED_Write_Dat(uint8_t dat) { uint8_t buf[2]; buf[0] = 0x40; //control byte buf[1] = dat; //??HAL??API?? HAL_I2C_Master_Transmit(&hi2c1, 0x78, buf, 2, 0xFFFF); } /** * @brief OLED?????? * @param x - X???? * @param y - Y???? */ void OLED_Set_Pos(uint8_t x, uint8_t y) { OLED_Write_Cmd(0xb0+y); OLED_Write_Cmd(((x&0xf0)>>4)|0x10); OLED_Write_Cmd((x&0x0f)|0x01); } /** * @brief OLED???? */ void OLED_Display_On(void) { OLED_Write_Cmd(0X8D); //SET DCDC?? OLED_Write_Cmd(0X14); //DCDC ON OLED_Write_Cmd(0XAF); //DISPLAY ON } /** * @brief OLED???? */ void OLED_Display_Off(void) { OLED_Write_Cmd(0X8D); //SET DCDC?? OLED_Write_Cmd(0X10); //DCDC OFF OLED_Write_Cmd(0XAE); //DISPLAY OFF } /** * @brief OLED????(??????????) */ void OLED_Clear(void) { uint8_t i,n; for(i=0;i<8;i++) { OLED_Write_Cmd(0xb0+i); //?????(0~7) OLED_Write_Cmd(0x00); //??????—???? OLED_Write_Cmd(0x10); //??????—???? for(n=0;n<128;n++) { OLED_Write_Dat(0); } } } /** * @brief OLED????(???????) */ void OLED_On(void) { uint8_t i,n; for(i=0;i<8;i++) { OLED_Write_Cmd(0xb0+i); //?????(0~7) OLED_Write_Cmd(0x00); //??????—???? OLED_Write_Cmd(0x10); //??????—???? for(n=0;n<128;n++) { OLED_Write_Dat(1); } } } /** * @brief ?????????ASCII?? * @param x - 0 - 127 * @param y - 0 - 7 * @param chr - ????ASCII?? * @param size - ASCII???? * ?????12(6*8)/16(8*16)???? */ void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t size) { uint8_t c=0,i=0; c = chr-' '; if(x > 128-1) { x=0; y++; } if(size ==16) { OLED_Set_Pos(x,y); for(i=0;i<8;i++) { OLED_Write_Dat(F8X16[c*16+i]); } OLED_Set_Pos(x,y+1); for(i=0;i<8;i++) { OLED_Write_Dat(F8X16[c*16+i+8]); } } else { OLED_Set_Pos(x,y); for(i=0;i<6;i++) { OLED_Write_Dat(F6x8[c][i]); } } } /** * @brief OLED ??pow?? * @param m - ?? * @param n - ?? */ static uint32_t oled_pow(uint8_t m,uint8_t n) { uint32_t result=1; while(n--)result*=m; return result; } /** * @brief ??????????? * @param x - 0 - 127 * @param y - 0 - 7 * @param num - ??????(0-4294967295) * @param len - ????? * @param size - ASCII???? * ?????12(6*8)/16(8*16)???? */ void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size) { uint8_t t,temp; uint8_t enshow=0; for(t=0;t<len;t++) { temp=(num/oled_pow(10,len-t-1))%10; if(enshow==0&&t<(len-1)) { if(temp==0) { OLED_ShowChar(x+(size/2)*t,y,' ',size); continue; }else enshow=1; } OLED_ShowChar(x+(size/2)*t,y,temp+'0',size); } } /** * @brief ???????????? * @param x - 0 - 127 * @param y - 0 - 7 * @param chr - ????????? * @param size - ASCII???? * ?????12(6*8)/16(8*16)???? */ void OLED_ShowString(uint8_t x,uint8_t y,char *chr,uint8_t size) { uint8_t j=0; while (chr[j]!='\0') { OLED_ShowChar(x,y,chr[j],size); x+=8; if(x>120){x=0;y+=2;} j++; } } /** * @brief ??????????? * @param x - 0 - 127 * @param y - 0 - 7 * @param no - ?????????????(??) * @note ?????oledfont.h????Hzk???,????????????? */ void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no) { uint8_t t,adder=0; OLED_Set_Pos(x,y); for(t=0;t<16;t++) { OLED_Write_Dat(Hzk[2*no][t]); adder+=1; } OLED_Set_Pos(x,y+1); for(t=0;t<16;t++) { OLED_Write_Dat(Hzk[2*no+1][t]); adder+=1; } } /** * @brief ??????????? * @param x1,x2 - 0 - 127 * @param y1,y2 - 0 - 7(8??????) * @param BMP - ?????? * @note ????BMP???bmp.h??? */ void OLED_DrawBMP(uint8_t x0, uint8_t y0,uint8_t x1, uint8_t y1,uint8_t BMP[]) { uint16_t j=0; uint8_t x,y; if(y1%8==0) { y=y1/8; } else { y=y1/8+1; } for(y=y0;y<y1;y++) { OLED_Set_Pos(x0,y); for(x=x0;x<x1;x++) { OLED_Write_Dat(BMP[j++]); } } } /** * @brief OLED??? */ void OLED_Init(void) { HAL_Delay(500); OLED_Write_Cmd(0xAE);//--display off OLED_Write_Cmd(0x00);//---set low column address OLED_Write_Cmd(0x10);//---set high column address OLED_Write_Cmd(0x40);//--set start line address OLED_Write_Cmd(0x81); // contract control OLED_Write_Cmd(0xFF);//--128 OLED_Write_Cmd(0xA1);//set segment remap OLED_Write_Cmd(0xC8);//Com scan direction OLED_Write_Cmd(0xA6);//--normal / reverse OLED_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64) OLED_Write_Cmd(0x3F);//--1/32 duty OLED_Write_Cmd(0xD3);//-set display offset OLED_Write_Cmd(0x00);// OLED_Write_Cmd(0xD5);//set osc division OLED_Write_Cmd(0x80); OLED_Write_Cmd(0xD9);//Set Pre-Charge Period OLED_Write_Cmd(0xF1);// OLED_Write_Cmd(0xDA);//set com pin configuartion OLED_Write_Cmd(0x12);// OLED_Write_Cmd(0xDB);//set Vcomh OLED_Write_Cmd(0x40);// OLED_Write_Cmd(0x20); OLED_Write_Cmd(0x02); OLED_Write_Cmd(0x8D);//set charge pump enable OLED_Write_Cmd(0x14);// OLED_Write_Cmd(0xA4); OLED_Write_Cmd(0xA6); OLED_Write_Cmd(0xAF);//--turn on oled panel OLED_Clear(); OLED_Set_Pos(0,0); } *** Using Compiler 'V6.9', folder: 'F:\Keil_v5\ARM\ARMCLANG\Bin' Build target 'OLED' ../Core/Src/stm32f4xx_it.c(25): warning: In file included from... ../Core/Inc\oled.h(4): warning: In file included from... ../Core/Inc/i2c.h(34): error: unknown type name 'I2C_HandleTypeDef' extern I2C_HandleTypeDef hi2c1; ^ 1 error generated. compiling stm32f4xx_it.c... ../Core/Src/oled.c(1): warning: In file included from... ../Core/Inc\oled.h(4): warning: In file included from... ../Core/Inc/i2c.h(34): error: unknown type name 'I2C_HandleTypeDef' extern I2C_HandleTypeDef hi2c1; ^ ../Core/Src/oled.c(30): warning: implicit declaration of function 'HAL_I2C_Master_Transmit' is invalid in C99 [-Wimplicit-function-declaration] HAL_I2C_Master_Transmit(&hi2c1, 0x78, buf, 2, 0xFFFF); ^ ../Core/Src/oled.c(44): warning: implicit declaration of function 'HAL_I2C_Master_Transmit' is invalid in C99 [-Wimplicit-function-declaration] HAL_I2C_Master_Transmit(&hi2c1, 0x78, buf, 2, 0xFFFF); ^ 2 warnings and 1 error generated. compiling oled.c... i2c.c(21): warning: In file included from... ../Core/Inc\i2c.h(34): error: unknown type name 'I2C_HandleTypeDef' extern I2C_HandleTypeDef hi2c1; ^ i2c.c(27): error: unknown type name 'I2C_HandleTypeDef' I2C_HandleTypeDef hi2c1; ^ i2c.c(35): error: use of undeclared identifier 'I2C_DUTYCYCLE_2' hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; ^ i2c.c(37): error: use of undeclared identifier 'I2C_ADDRESSINGMODE_7BIT' hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; ^ i2c.c(38): error: use of undeclared identifier 'I2C_DUALADDRESS_DISABLE' hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; ^ i2c.c(40): error: use of undeclared identifier 'I2C_GENERALCALL_DISABLE' hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; ^ i2c.c(41): error: use of undeclared identifier 'I2C_NOSTRETCH_DISABLE' hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; ^ i2c.c(42): warning: implicit declaration of function 'HAL_I2C_Init' is invalid in C99 [-Wimplicit-function-declaration] if (HAL_I2C_Init(&hi2c1) != HAL_OK) ^ i2c.c(110): error: unknown type name 'I2C_HandleTypeDef' void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) ^ i2c.c(136): error: unknown type name 'I2C_HandleTypeDef' void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) ^ 1 warning and 9 errors generated. compiling i2c.c... ../Core/Src/main.c(30): warning: In file included from... ../Core/Inc\oled.h(4): warning: In file included from... ../Core/Inc/i2c.h(34): error: unknown type name 'I2C_HandleTypeDef' extern I2C_HandleTypeDef hi2c1; ^ ../Core/Src/main.c(378): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] if(Res_1 <= 15000) OLED_Showdecimal(0,4,Res_1,7,1,16); ^ ../Core/Src/main.c(418): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] OLED_Showdecimal(0,4,Res/1000,4,2,16); ^ ../Core/Src/main.c(419): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(80,4,"uF"); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(442): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] OLED_Showdecimal(0,4,Res,4,2,16); ^ ../Core/Src/main.c(443): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(80,4,"nF"); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(470): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] OLED_Showdecimal(0,4,Res,4,2,16); ^ ../Core/Src/main.c(471): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(80,4,"pF"); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(504): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(0,6,"ESR="); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(505): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] OLED_Showdecimal(32,6,Esr,2,2,16); ^ ../Core/Src/main.c(527): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(0,4,"Vd="); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(528): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] OLED_Showdecimal(32,4,adcget/1000.0,1,2,16); ^ ../Core/Src/main.c(529): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(64,4,"V"); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(541): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(0,4,"Vd="); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ ../Core/Src/main.c(542): warning: implicit declaration of function 'OLED_Showdecimal' is invalid in C99 [-Wimplicit-function-declaration] OLED_Showdecimal(32,4,adcget,1,2,16); ^ ../Core/Src/main.c(543): error: too few arguments to function call, expected 4, have 3 OLED_ShowString(64,4,"V"); ~~~~~~~~~~~~~~~ ^ ../Core/Inc\oled.h(16): note: 'OLED_ShowString' declared here void OLED_ShowString(uint8_t x,uint8_t y, char *chr,uint8_t size); ^ 7 warnings and 9 errors generated. compiling main.c... "OLED\OLED.axf" - 20 Error(s), 10 Warning(s). Target not created. Build Time Elapsed: 00:00:00分析一下错误
07-21
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "dma.h" #include "i2c.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "oled.h" #include "key.h" #include <math.h> #include <stdarg.h> #include <stdio.h> #include <string.h> #define Threshold 2.5f //阈值 /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ //显示标志位 char OLED_Flage = 0; //位置数据标志位 char time_Data_Flage = 0; int time_Data_Filtering[3]; //A---B---C 一个点内只能触发一次 uint32_t time_Data[3]; //A---B---C float Vref; //参考电压 float VA,VB,VC; //A---B---C 电压 /* 存放ADC存入的值 4个通道10个数据 */ uint16_t adc_dma_buf[4]; //A —— B —— C —— 基准电压 //存储点的ADC数据 typedef struct { float V_Last; float V_Change; }ADC_Data; typedef struct { ADC_Data A; ADC_Data B; ADC_Data C; }Point_Data; Point_Data ABC_V; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ static void UART_Printf(const char *format, ...) { char tmp[128]; va_list argptr; va_start(argptr, format); vsprintf((char* )tmp, format, argptr); va_end(argptr); HAL_UART_Transmit(&huart1, (const uint8_t *)&tmp, strlen(tmp), HAL_MAX_DELAY); } //0:开启,1:关 void LED_Switch(char Led_Num,char Led_State); /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_USART1_UART_Init(); MX_I2C1_Init(); MX_ADC1_Init(); MX_TIM1_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT (&htim1); HAL_TIM_Base_Start (&htim3 ); HAL_TIM_Base_Start_IT (&htim4); //启动ADC HAL_ADC_Start_DMA (&hadc1, (uint32_t*) adc_dma_buf,sizeof(adc_dma_buf)/sizeof(uint16_t)); HAL_ADC_PollForConversion(&hadc1,HAL_MAX_DELAY); HAL_Delay(20); OLED_Init(); char masage1[22] = ""; char masage2[22] = ""; char masage3[22] = ""; char masage4[22] = ""; //当前以打点数 int Point_number = 0; //键码 unsigned char key_number = 0; //显示初始数据 sprintf(masage1,"当前点数: %-2d",Point_number); sprintf(masage2,"A点: %-5d %d ",time_Data[0],time_Data_Filtering[0]); sprintf(masage3,"B点: %-5d %d",time_Data[1],time_Data_Filtering[1]); sprintf(masage4,"C点: %-5d %d",time_Data[2],time_Data_Filtering[2]); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { key_number = Key(); switch (key_number){ case 1: HAL_GPIO_WritePin(A1_GPIO_Port,A1_Pin,GPIO_PIN_SET); // HAL_GPIO_WritePin(A1_GPIO_Port,A1_Pin,GPIO_PIN_RESET); //UART_Printf("1\r\n"); LED_Switch(1,0); break; case 2: HAL_GPIO_WritePin(B1_GPIO_Port,B1_Pin,GPIO_PIN_SET); // HAL_GPIO_WritePin(B1_GPIO_Port,B1_Pin,GPIO_PIN_RESET); // UART_Printf("2\r\n"); LED_Switch(2,0); break; case 3: HAL_GPIO_WritePin(C1_GPIO_Port,C1_Pin,GPIO_PIN_SET); // HAL_GPIO_WritePin(C1_GPIO_Port,C1_Pin,GPIO_PIN_RESET); // UART_Printf("3\r\n"); LED_Switch(2,1); break; default: break; } if(time_Data_Flage == 1){ Point_number++; sprintf(masage1,"当前点数: %-2d",Point_number); sprintf(masage2,"A点: %-5d %d ",time_Data[0],time_Data_Filtering[0]); sprintf(masage3,"B点: %-5d %d",time_Data[1],time_Data_Filtering[1]); sprintf(masage4,"C点: %-5d %d",time_Data[2],time_Data_Filtering[2]); UART_Printf("A: %d B: %d C: %d\r\n",time_Data[0],time_Data[1],time_Data[2]); time_Data_Flage = 0; HAL_Delay(20); //延时防止振动造成影响,错误开启第二个点 memset(time_Data_Filtering, 0, sizeof(time_Data_Filtering)); // 清零数组,允许触发 } if(OLED_Flage == 1){ OLED_NewFrame(); OLED_PrintString(0,0,masage1,&font16x16,OLED_COLOR_NORMAL); OLED_PrintString(0,16,masage2,&font16x16,OLED_COLOR_NORMAL); OLED_PrintString(0,32,masage3,&font16x16,OLED_COLOR_NORMAL); OLED_PrintString(0,48,masage4,&font16x16,OLED_COLOR_NORMAL); OLED_ShowFrame(); UART_Printf("V_A:%.2f V_B:%.2f V_C:%.2f\r\n",ABC_V.A.V_Change,ABC_V.B.V_Change,ABC_V.C.V_Change); //UART_Printf("V_A:%d V_B:%d V_C:%d\r\n",time_Data_Filtering[0],time_Data_Filtering[1],time_Data_Filtering[2]); OLED_Flage = 0; } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 168; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ //外部中断回调 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ static int point_number = 0; //A点 if(GPIO_Pin == point_A_Pin && time_Data_Filtering[0] == 0){ //UART_Printf("A点\r\n"); time_Data_Filtering[0] = 1; switch (point_number) { case 0: //第一 __HAL_TIM_SET_COUNTER (&htim3 ,0); //计为最近点 time_Data[0] = 0; break; case 1: //第二 time_Data[0] = __HAL_TIM_GET_COUNTER(&htim3); break; case 2: //第三 time_Data[0] = __HAL_TIM_GET_COUNTER(&htim3); time_Data_Flage = 1; //激活一次数据显示 break; default: break; } point_number = (point_number + 1) % 3; //当前点进度+1(3结束当前点) } else if(GPIO_Pin == point_B_Pin && time_Data_Filtering[1] == 0){ //UART_Printf("B点\r\n"); time_Data_Filtering[1] = 1; switch (point_number) { case 0: //第一 __HAL_TIM_SET_COUNTER (&htim3 ,0); //计为最近点(0时刻) time_Data[1] = 0; break; case 1: //第二 time_Data[1] = __HAL_TIM_GET_COUNTER(&htim3); break; case 2: //第三 time_Data[1] = __HAL_TIM_GET_COUNTER(&htim3); time_Data_Flage = 1; //激活一次数据显示 break; default: break; } point_number = (point_number + 1) % 3; //当前点进度+1(3结束当前点) } else if(GPIO_Pin == point_C_Pin && time_Data_Filtering[2] == 0){ //UART_Printf("C点\r\n"); time_Data_Filtering[2] = 1; switch (point_number) { case 0: //第一 __HAL_TIM_SET_COUNTER (&htim3 ,0); //计为最近点 time_Data[2] = 0; break; case 1: //第二 time_Data[2] = __HAL_TIM_GET_COUNTER(&htim3); break; case 2: //第三 time_Data[2] = __HAL_TIM_GET_COUNTER(&htim3); time_Data_Flage = 1; //激活一次数据显示 break; default: break; } point_number = (point_number + 1) % 3; //当前点进度+1(3结束当前点) } } //定时器回调 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){ static char time = 0; if(htim == &htim1){ //6us Vref = 1.2f * (4095.0f / (float)adc_dma_buf[3]); VA = Vref * ((float)adc_dma_buf[0] / 4095.0f); VB = Vref * ((float)adc_dma_buf[1] / 4095.0f); VC = Vref * ((float)adc_dma_buf[2] / 4095.0f); ABC_V.A.V_Change = fabsf(VA - ABC_V.A.V_Last); ABC_V.B.V_Change = fabsf(VB - ABC_V.B.V_Last); ABC_V.C.V_Change = fabsf(VC - ABC_V.C.V_Last); ABC_V.A.V_Last = VA; ABC_V.B.V_Last = VB; ABC_V.C.V_Last = VC; if(ABC_V.A.V_Change > Threshold){ HAL_GPIO_WritePin(A_GPIO_Port,A_Pin,GPIO_PIN_SET); HAL_GPIO_WritePin(A_GPIO_Port,A_Pin,GPIO_PIN_RESET); } if(ABC_V.B.V_Change > Threshold){ HAL_GPIO_WritePin(B_GPIO_Port,B_Pin,GPIO_PIN_SET); HAL_GPIO_WritePin(B_GPIO_Port,B_Pin,GPIO_PIN_RESET); } if(ABC_V.C.V_Change > Threshold){ HAL_GPIO_WritePin(C_GPIO_Port,C_Pin,GPIO_PIN_SET); HAL_GPIO_WritePin(C_GPIO_Port,C_Pin,GPIO_PIN_RESET); } //0.6~1.5 微秒 } if(htim == &htim4){ //10ms time = (time + 1) % 3; if(time == 0 ) //30ms OLED_Flage = 1; } } //0:开启,1:关 void LED_Switch(char Led_Num,char Led_State){ switch (Led_Num) { case 1: if (Led_State == 1) { HAL_GPIO_WritePin(led1_GPIO_Port,led1_Pin,GPIO_PIN_SET); } else if(Led_State == 0) { HAL_GPIO_WritePin(led1_GPIO_Port,led1_Pin,GPIO_PIN_RESET); } break; case 2: if (Led_State == 1) { HAL_GPIO_WritePin(led2_GPIO_Port,led2_Pin,GPIO_PIN_SET); } else if(Led_State == 0) { HAL_GPIO_WritePin(led2_GPIO_Port,led2_Pin,GPIO_PIN_RESET); } break; case 3: if (Led_State == 1) { HAL_GPIO_WritePin(led3_GPIO_Port,led3_Pin,GPIO_PIN_SET); } else if(Led_State == 0) { HAL_GPIO_WritePin(led3_GPIO_Port,led3_Pin,GPIO_PIN_RESET); } break; case 4: if (Led_State == 1) { HAL_GPIO_WritePin(led4_GPIO_Port,led4_Pin,GPIO_PIN_SET); } else if(Led_State == 0) { HAL_GPIO_WritePin(led4_GPIO_Port,led4_Pin,GPIO_PIN_RESET); } break; default: break; } } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ 为什么我的AD采集模拟量超过阈值触发,所得到的三个点时间不是1就是32768,但不经过AD,直接中断就没问题
10-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值