所以我正在使用LPC824,这是一个皮质-m0 +。我试图保持代码与arduino的相似性,我目前卡在串行类。现在我有一个扩展打印类的序列类,如下所示。
Printer.h中
class Printer
{
public:
Printer();
unsigned int print(char c);
virtual unsigned int write(char c) = 0;
}
Printer.cpp
#include "Printer.h"
Printer::Printer()
{
//Nothing to do yet
}
unsigned int Printer::print(char c)
{
return write(c);
}
Serial.h
#include "Printer.h"
class Serial : public Printer
{
public:
Serial();
static Serial& Serial0();
unsigned int begin(/*eventually options*/);
unsigned int write(char c);
}
Serial.cpp
#include "Serial.h"
#include "uart.h"
Serial::Serial()
{
//Nothing to do yet
}
Serial& Serial::Serial0()
{
static Serial inst;
return inst;
}
unsigned int Serial::begin(/*eventually options*/)
{
uart0init(115200, 0x04, 0x00);
}
unsigned int Serial::write(char c)
{
uart0send(c);
}
的main.cpp
#include "Serial.h"
void main()
{
Serial::Serial0().begin();
while(1)
{
Serial::Serial0().write('a');
Serial::Serial0().print('b');
}
}
调用write函数将打印出'a'。当我打电话给打印功能时,我的程序挂起。为什么我不能在我的单例上调用print函数,但我可以调用write函数?