0

我正在研究一个使用STM32F103C8T6HD44780 LCD (2x16)产生可变频率的项目PWM。我使用"4ilo HD44780 LCD library"并在 main.c 中创建了一个 LCD 实例,名为"&lcd".

问题是当尝试在中断例程中使用 print something to LCD 时,我收到了一些关于取消声明 &lcd 的错误,因为 LCD 的声明在main.c文件 notSTM32F1xx_it.h中。我试图放置中断处理程序main.c但没有成功。任何帮助,将不胜感激

这是STM32F1xx_it.h

void EXTI0_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */
if(EXTI->PR & EXTI_PR_PR0)
        {
            EXTI->PR |= EXTI_PR_PR0;
            if(GPIOA->IDR & 0x0002) //0000 0000 0000 0010 -> check A1 status
            {
                power+=IncDec_Power_value;
                if (power > maxpowerlimit) power = maxpowerlimit;
            }
            else
            {
                power-=IncDec_Power_value;
                if (power < minpowerlimit) power = minpowerlimit;
            }
        }
  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
  /* USER CODE BEGIN EXTI0_IRQn 1 */

  /* USER CODE END EXTI0_IRQn 1 */
}

和 main.c

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stm32f1xx.h"
#include "lcd.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define LCDD4Port GPIOB
#define LCDD4Pin GPIO_PIN_12
#define LCDD5Port GPIOB
#define LCDD5Pin GPIO_PIN_13
#define LCDD6Port GPIOB
#define LCDD6Pin GPIO_PIN_14
#define LCDD7Port GPIOB
#define LCDD7Pin GPIO_PIN_15
#define LCDRegisterSelectPort GPIOB
#define LCDRegisterSelectPin GPIO_PIN_5
#define LCDEnablePort GPIOB
#define LCDEnablePin GPIO_PIN_7
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
extern volatile float power;
extern volatile float time;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void Display(Lcd_HandleTypeDef lcd)
{
      Lcd_cursor(&lcd, 1, 2);
      Lcd_float(&lcd, power, sizeof(power)+1);
      Lcd_string(&lcd, " ");
      Lcd_cursor(&lcd, 1, 10);
      Lcd_float(&lcd, time, sizeof(time)+1);
      Lcd_string(&lcd, " ");
}

/* 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();
  /* USER CODE BEGIN 2 */

  Lcd_PortType ports[] ={LCDD4Port, LCDD5Port, LCDD6Port, LCDD7Port};
  Lcd_PinType pins[] = {LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin};
  Lcd_HandleTypeDef lcd;
  lcd = Lcd_create(ports, pins, LCDRegisterSelectPort, LCDRegisterSelectPin, LCDEnablePort, 
  LCDEnablePin, LCD_4_BIT_MODE);
  Lcd_clear_Display(&lcd);
  Lcd_cursor(&lcd, 0, 2);
  Lcd_string(&lcd, "POWER");
  Lcd_cursor(&lcd, 0, 10);
  Lcd_string(&lcd, "TIME");
  Lcd_cursor(&lcd, 1, 2);
  Lcd_float(&lcd, power, sizeof(power)+1);
  Lcd_string(&lcd, " ");
  Lcd_cursor(&lcd, 1, 10);
  Lcd_float(&lcd, time, sizeof(time)+1);
  Lcd_string(&lcd, " ");
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      Lcd_cursor(&lcd, 1, 2);
      Lcd_float(&lcd, power, sizeof(power)+1);
      Lcd_string(&lcd, " ");
      Lcd_cursor(&lcd, 1, 10);
      Lcd_float(&lcd, time, sizeof(time)+1);
      Lcd_string(&lcd, " ");
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
4

0 回答 0