好像不能按楼上的说法做。出现如下编译错误:Build target 'Release'
compiling led.cpp...
led.cpp: In member function 'void task_led1_t::routine()':
led.cpp(57): error: 'class instantiate::task' has no member named 'get_count'
compiling Timer.cpp...
Timer.cpp: In member function 'void task_LOOK_TIMER_t::routine()':
Timer.cpp(23): warning: unused variable 'msg'
Timer.cpp: At global scope:
Timer.cpp(71): error: no 'long unsigned int task_LOOK_TIMER_t::get_count()' member function declared in class 'task_LOOK_TIMER_t'
Target not created
主要代码如下:
led.cpp#include "led.h"
#define LOOK_H 1
#if LOOK_H == 0
#include "NUC1xx.h"
#include "NUC1xxM051Seriescfg.h"
#else
#define __HAVE_GPIO
#include <nuc120re3an.h>
using namespace nuvoton;
#endif
#include "tft.h"
#include "Timer.h"
task_tft_t tftObj; //创建tft对象
//-------------------------------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------------------------------
// 任务类 task_led_t 的例程
void task_led1_t::routine()
{
// TODO: 在此编写 task_led_t 例程的内容
#define X_DIS 9 //显示信息的位置
#define Y_DIS 7
#define FONT_HEIGHT 19 //行高
#define REFRESH_TIMES 16 //每秒的刷新次数
unsigned char cnt_i = 0; //次数计数器,一定次数后cnt加1
uint32_t cnt = 0; //时间计数器,延时方式,每1s延时后加一
unsigned long count = 0; //时间计数器,定时方式,
unsigned char str[6] = {0};
tftObj.LCD_Init();
// test_lcd_mon();
tftObj.LCD_CLEAR(0,0,240,320);
while (true) {
// TODO: 在此编写 task_led_t 例程的内容
tftObj.LCD_Display();
cnt_i++;
if(cnt_i > (REFRESH_TIMES-1))
{
cnt_i = 0;
cnt++;
}
str[0] = (unsigned char)(cnt / 10000) + 0x30;
str[1] = cnt % 10000 / 1000 + 0x30;
str[2] = cnt % 1000 / 100 + 0x30;
str[3] = cnt % 100 / 10 + 0x30;
str[4] = (unsigned char)(cnt % 10) + 0x30;
tftObj.LCD_ShowString(X_DIS,Y_DIS,"Running Time:");
tftObj.LCD_ShowNumStr(X_DIS+81,Y_DIS-2,str);
count = task_LOOK_TIMER.get_count();
str[0] = (unsigned char)(count / 10000) + 0x30;
str[1] = count % 10000 / 1000 + 0x30;
str[2] = count % 1000 / 100 + 0x30;
str[3] = count % 100 / 10 + 0x30;
str[4] = (unsigned char)(count % 10) + 0x30;
tftObj.LCD_ShowString(X_DIS,Y_DIS+FONT_HEIGHT,"Timer Time:");
tftObj.LCD_ShowNumStr(X_DIS+81,Y_DIS-2+FONT_HEIGHT,str);
delay(LOOK_TICKS_PER_SEC / REFRESH_TIMES); //每秒刷新屏幕10次
}
}
#ifdef LOOK_SCHEDULING_PRIORITY
instantiate::task<task_led1_t, LOOK_STACK_SIZE> task_led1(0);
instantiate::task<task_LOOK_TIMER_t, LOOK_STACK_SIZE> task_LOOK_TIMER(0);
#else
instantiate::task<task_led1_t, LOOK_STACK_SIZE> task_led1;
instantiate::task<task_LOOK_TIMER_t, LOOK_STACK_SIZE> task_LOOK_TIMER;
#endif
2.Timer.h#ifndef __LOOK_TIMER_H
#define __LOOK_TIMER_H
#include "look_config.h"
#include <look.h>
//#include <instantiate>
//extern unsigned int count;
// 任务类 task_LOOK_TIMER_t 的定义
class task_LOOK_TIMER_t : public task_t {
public:
__INLINE__ task_LOOK_TIMER_t(); // 构造函数
void on_signal(void* addr, uintptr_t signal); // 定义on_signal()
bool send_message(int msg);
unsigned long get_count(void);
protected:
void routine(); // 任务例程
private:
timer_t timer;
int interval;
mbox_t<int> mbox;
unsigned long count;
};
// 任务类 LOOK_TIMER 的构造函数
__INLINE__ task_LOOK_TIMER_t::task_LOOK_TIMER_t()
: timer(*this) // 初始化定时器实例,并指定触发对象。
, interval(1000) //初始化显示间隔
, mbox(0)
{
// TODO: 在此初始化 task_LOOK_TIMER_t 的类成员
}
extern instantiate::task<task_LOOK_TIMER_t, LOOK_STACK_SIZE> task_LOOK_TIMER;
#endif // __LOOK_TIMER_H
3.Timer.cpp#include "Timer.h"
#define LOOK_H 1
#if LOOK_H == 0
#include "NUC1xx.h"
#include "NUC1xxM051Seriescfg.h"
#else
#define __HAVE_GPIO
#include <nuc120re3an.h>
using namespace nuvoton;
#endif
// 任务类 task_LOOK_TIMER_t 的例程
void task_LOOK_TIMER_t::routine()
{
// TODO: 在此编写 task_LOOK_TIMER_t 例程的内容
timer.start(interval); //定时器
while (true) {
// TODO: 在此编写 task_LOOK_TIMER_t 例程的内容
int msg = mbox.get(); // 等待邮箱消息
// if (msg != 0)
// {
// if ((msg + interval) > 0) {//间隔为0非法,不响
// interval += msg;
//#if LOOK_H == 0
// GPIOBs.DMASK.Bits.Pin10 = 0;
//#else
// GPIOB.DMASK().DMASK10(0);
//#endif
// msg = (msg > 0) ? 1 : 2;//+ 响1声,- 响2声
// for (int i = 0; i < (msg * 2); i ++){
//#if LOOK_H == 0
// GPIOBs.DOUT.Bits.Pin10 ^= 1;//蜂鸣器响PB10=1,不响PB10=0
//#else
// GPIOB.DOUT().DOUT10 ^= 1;
//#endif
// delay(LOOK_TICKS_PER_SEC / 20);
// }
//#if LOOK_H == 0
// GPIOBs.DOUT.Bits.Pin10 = 0;
//#else
// GPIOB.DOUT().DOUT10(0);
//#endif
// }
// }
}
}
void task_LOOK_TIMER_t:n_signal(void* addr, uintptr_t signal)
{
if (addr == &timer) {
timer.do_start(interval); // 重置定时器
// 处理定时器事务
count ++;
}
else {
task_t:n_signal(addr, signal);
}
}
bool task_LOOK_TIMER_t::send_message(int msg)
{
return mbox.do_tryput(msg); //发送消息
}
unsigned long task_LOOK_TIMER_t::get_count(void)
{
return count;
}
还望大家指导。 |