'accelerometer' 和 'lcd' 未在此范围内声明
'accelerometer' and 'lcd' not declared in this scope
它告诉我 "accelerometer" 和 "lcd" 在 PIT0_IRQHandler 中使用时未在此范围内声明。 None 我在网上找到的解决方案到目前为止都有效,所以我想我只是 post 就可以了。我对此也很陌生,所以请随时指出其中的任何错误
#include <stdio.h>
#include "system.h"
#include "derivative.h"
#include "hardware.h"
#include "delay.h"
#include "lcd.h"
#include "i2c.h"
#include "level.h"
#include "mma845x.h"
#include "tone.h"
#include "accel.h"
/// LCD dimensions and centerpoint
#define LCD_WIDTH (LCD_X_MAX-LCD_X_MIN)
#define LCD_HEIGHT (LCD_Y_MAX-LCD_Y_MIN)
#define CENTRE_X ((LCD_X_MAX-LCD_X_MIN)/2)
#define CENTRE_Y ((LCD_Y_MAX-LCD_Y_MIN)/2)
#define BACKGROUND_COLOUR (RED)
#define FOREGROUND_COLOUR (WHITE)
#define CIRCLE_RADIUS (20)
using namespace USBDM;
void initialisePIT(int channel, uint32_t interval) {
// Enable clock to PIT
SIM->SCGC6 |= SIM_SCGC6_PIT_MASK;
// Enable PIT module
PIT->MCR = PIT_MCR_FRZ_MASK;
// Set reload value
PIT->CHANNEL[channel].LDVAL = interval-1;
// Enable this channel with interrupts
PIT->CHANNEL[channel].TCTRL = PIT_TCTRL_TEN_MASK|PIT_TCTRL_TIE_MASK;
// Enable PITn interrupts in NVIC
NVIC_EnableIRQ((IRQn_Type)(PIT0_IRQn+channel));
// Set arbitrary priority level
NVIC_SetPriority((IRQn_Type)(PIT0_IRQn+channel), 8);
}
void initialiseLCD(){
// Instantiate SPI interface class
Spi *spi = new Spi0();
// Instantiate LCD interface class
Lcd *lcd = new Lcd(spi);
// Clear Background and set to a preset (Set above) colour
lcd->clear(BACKGROUND_COLOUR);
// Draw crosshairs and initial circle on the screen
lcd->drawLine(LCD_WIDTH/2,LCD_WIDTH/2,0,LCD_HEIGHT,BLACK);
lcd->drawLine(0,LCD_WIDTH,LCD_HEIGHT/2,LCD_HEIGHT/2,BLACK);
lcd->drawCircle(CENTRE_X, CENTRE_Y, 20, WHITE);
}
void initialiseAccel()
{
I2c *i2c = new I2c0();
MMA845x *accelerometer = new MMA845x(i2c, MMA845x::ACCEL_2Gmode);
}
void PIT0_IRQHandler(void) {
int accelStatus;
int16_t accelX,accelY,accelZ;
accelerometer->readAccelerometerXYZ(&accelStatus, &accelX, &accelY, &accelZ);
lcd->clear(BACKGROUND_COLOUR);
lcd->drawCircle(accelX,accelY,20,WHITE);
// Clear the interrupt request from PIT
PIT->CHANNEL[0].TFLG = PIT_TFLG_TIF_MASK;
}
accelerometer
在 initialiseAccel
中声明。它将在该函数结束时超出范围,并且在 PIT0_IRQHandler
中不是已知名称。您可能应该创建一个 class 来保存这些变量和函数,否则您将不得不使用全局变量(可能在命名空间中)来保存这些值。
它告诉我 "accelerometer" 和 "lcd" 在 PIT0_IRQHandler 中使用时未在此范围内声明。 None 我在网上找到的解决方案到目前为止都有效,所以我想我只是 post 就可以了。我对此也很陌生,所以请随时指出其中的任何错误
#include <stdio.h>
#include "system.h"
#include "derivative.h"
#include "hardware.h"
#include "delay.h"
#include "lcd.h"
#include "i2c.h"
#include "level.h"
#include "mma845x.h"
#include "tone.h"
#include "accel.h"
/// LCD dimensions and centerpoint
#define LCD_WIDTH (LCD_X_MAX-LCD_X_MIN)
#define LCD_HEIGHT (LCD_Y_MAX-LCD_Y_MIN)
#define CENTRE_X ((LCD_X_MAX-LCD_X_MIN)/2)
#define CENTRE_Y ((LCD_Y_MAX-LCD_Y_MIN)/2)
#define BACKGROUND_COLOUR (RED)
#define FOREGROUND_COLOUR (WHITE)
#define CIRCLE_RADIUS (20)
using namespace USBDM;
void initialisePIT(int channel, uint32_t interval) {
// Enable clock to PIT
SIM->SCGC6 |= SIM_SCGC6_PIT_MASK;
// Enable PIT module
PIT->MCR = PIT_MCR_FRZ_MASK;
// Set reload value
PIT->CHANNEL[channel].LDVAL = interval-1;
// Enable this channel with interrupts
PIT->CHANNEL[channel].TCTRL = PIT_TCTRL_TEN_MASK|PIT_TCTRL_TIE_MASK;
// Enable PITn interrupts in NVIC
NVIC_EnableIRQ((IRQn_Type)(PIT0_IRQn+channel));
// Set arbitrary priority level
NVIC_SetPriority((IRQn_Type)(PIT0_IRQn+channel), 8);
}
void initialiseLCD(){
// Instantiate SPI interface class
Spi *spi = new Spi0();
// Instantiate LCD interface class
Lcd *lcd = new Lcd(spi);
// Clear Background and set to a preset (Set above) colour
lcd->clear(BACKGROUND_COLOUR);
// Draw crosshairs and initial circle on the screen
lcd->drawLine(LCD_WIDTH/2,LCD_WIDTH/2,0,LCD_HEIGHT,BLACK);
lcd->drawLine(0,LCD_WIDTH,LCD_HEIGHT/2,LCD_HEIGHT/2,BLACK);
lcd->drawCircle(CENTRE_X, CENTRE_Y, 20, WHITE);
}
void initialiseAccel()
{
I2c *i2c = new I2c0();
MMA845x *accelerometer = new MMA845x(i2c, MMA845x::ACCEL_2Gmode);
}
void PIT0_IRQHandler(void) {
int accelStatus;
int16_t accelX,accelY,accelZ;
accelerometer->readAccelerometerXYZ(&accelStatus, &accelX, &accelY, &accelZ);
lcd->clear(BACKGROUND_COLOUR);
lcd->drawCircle(accelX,accelY,20,WHITE);
// Clear the interrupt request from PIT
PIT->CHANNEL[0].TFLG = PIT_TFLG_TIF_MASK;
}
accelerometer
在 initialiseAccel
中声明。它将在该函数结束时超出范围,并且在 PIT0_IRQHandler
中不是已知名称。您可能应该创建一个 class 来保存这些变量和函数,否则您将不得不使用全局变量(可能在命名空间中)来保存这些值。