-1
它告訴我,當在PIT0_IRQHandler中使用「accelerometer」和「lcd」時,它們未在此範圍內聲明。我在網上找到的解決方案都沒有工作,所以我想我只是把它發佈。我是很新,這也可以隨意地指出任何與包括每個錯誤'accelerometer'和'lcd'未在此範圍內聲明
#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;
}
任何有關如何編寫這樣的命名空間的建議? 對於我正在編寫的內容,以及據我可以判斷,在頭文件中包含名稱空間是最佳解決方案,但我一直在嘗試並且無法編譯它 – Davies
用變量聲明一個名稱空間(如'lcd'和'accelerometer')。更好的方法是創建一個包含所有這些變量的類,並且可能還有一個全局變量(指針或變量),即PIT0_IRQHandler可以訪問的類。 – 1201ProgramAlarm