点击下载LOOK_IDLE
1.LOOK_IDLE.H
- #ifndef __LOOK_IDLE_H
- #define __LOOK_IDLE_H
- #include "look_config.h"
- #include <look.h>
- #include <instantiate>
- // 空闲任务类 task_LOOK_IDLE_t 的定义
- class task_LOOK_IDLE_t : public idle_task_t {
- public:
- task_LOOK_IDLE_t() __OPT_ATTR__; // 构造函数
- void on_signal(void* addr, uintptr_t signal); // 定义on_signal()
- protected:
- void routine() __attribute__((naked, noreturn)); // 任务例程
- private:
- timer_t timer1, timer2;
- int interval1, interval2;
- int count1, count2;
- };
- // 空闲任务类 LOOK_IDLE 的构造函数
- __OPT_INLINE__ task_LOOK_IDLE_t::task_LOOK_IDLE_t()
- : timer1(*this) // 初始化定时器实例,并指定触发对象。
- , timer2(*this) // 初始化定时器实例,并指定触发对象。
- , interval1(50) //初始化显示间隔
- , interval2(50) //初始化显示间隔
- , count1(0)
- , count2(0)
- {
- // TODO: 在此初始化 task_LOOK_IDLE_t 的类成员
- }
- extern instantiate::idle<task_LOOK_IDLE_t, 2 * LOOK_STACK_SIZE> idle_task
- ;
- #endif // __LOOK_IDLE_H
2.LOOK_IDLE.CPP
- #include "LOOK_IDLE.h"
- #include "NUC1xx.h"
- #include "NUC1xxM051Seriescfg.h"
- #define BEEP Pin10//BEEP在PB.10
- // 空闲任务类 task_LOOK_IDLE_t 的例程
- void task_LOOK_IDLE_t::routine()
- {
- // TODO: 在此编写 task_LOOK_IDLE_t 例程的内容
- volatile unsigned int key;
- timer1.start(interval1);//启动定时器1
- while (true) {
- // TODO: 在此编写 task_LOOK_IDLE_t 例程的内容
- key = GPIOBs.PIN.Regs;//取键盘值
- for (unsigned int i = 0; i < 0x8888; i++) asm volatile("nop");
- if (key == GPIOBs.PIN.Regs) {//等待抖动过去
- if ((key & (1 << 14)) == 0) {//Key2
- while (key == GPIOBs.PIN.Regs);//等待键释放
- if (interval1 <= 500) {
- interval1 += 50;
- count2 = 2;//响一声
- timer2.start(interval2);//启动定时器2
- }
- }
- else if ((key & (1 << 15)) == 0) {//Key1
- while (key == GPIOBs.PIN.Regs);//等待键释放
- if (interval1 > 50) {
- interval1 -= 50;
- count2 = 6;//响三声
- timer2.start(interval2);//启动定时器2
- }
- }
- }
- }
- __builtin_unreachable();
- }
- void task_LOOK_IDLE_t::on_signal(void* addr, uintptr_t signal)
- {
- if (addr == &timer1) {
- //处理定时器事务
- timer1.do_start(interval1);//重置定时器
- GPIOAs.DMASK.Regs = ~0b111100;
- GPIOAs.DOUT.Regs = (count1 << 2) ^ 0b111100;
- count1 ++;
- }
- else if (addr == &timer2) {
- //处理定时器事务
- GPIOBs.DMASK.Bits.BEEP = 0;
- if (count2 > 0) {
- GPIOBs.DOUT.Bits.BEEP ^= 1;
- timer2.do_start(interval2);//重置定时器
- count2 --;
- }
- else {
- GPIOBs.DOUT.Bits.BEEP = 0;
- timer2.do_kill();//清除定时器
- }
- }
- else {
- idle_task_t::on_signal(addr, signal);
- }
- }
- namespace look{//必须写!!!
- instantiate::idle<task_LOOK_IDLE_t, 2* LOOK_STACK_SIZE> idle_task(false);
- }
|