[LOOK] LOOK菜鸟idle应用例程

[复制链接]
 楼主| hotpower 发表于 2011-5-25 00:08 | 显示全部楼层 |阅读模式
点击下载LOOK_IDLE


1.LOOK_IDLE.H
  1. #ifndef __LOOK_IDLE_H
  2. #define __LOOK_IDLE_H

  3. #include "look_config.h"
  4. #include <look.h>
  5. #include <instantiate>

  6. // 空闲任务类 task_LOOK_IDLE_t 的定义
  7. class task_LOOK_IDLE_t : public idle_task_t {
  8. public:
  9. task_LOOK_IDLE_t() __OPT_ATTR__; // 构造函数
  10. void on_signal(void* addr, uintptr_t signal); // 定义on_signal()
  11. protected:
  12. void routine() __attribute__((naked, noreturn)); // 任务例程
  13. private:
  14. timer_t timer1, timer2;
  15. int interval1, interval2;
  16. int count1, count2;
  17. };

  18. // 空闲任务类 LOOK_IDLE 的构造函数

  19. __OPT_INLINE__ task_LOOK_IDLE_t::task_LOOK_IDLE_t()
  20. : timer1(*this) // 初始化定时器实例,并指定触发对象。
  21. , timer2(*this) // 初始化定时器实例,并指定触发对象。
  22. , interval1(50) //初始化显示间隔
  23. , interval2(50) //初始化显示间隔
  24. , count1(0)
  25. , count2(0)
  26. {
  27. // TODO: 在此初始化 task_LOOK_IDLE_t 的类成员
  28. }

  29. extern instantiate::idle<task_LOOK_IDLE_t, 2 * LOOK_STACK_SIZE> idle_task
  30. ;

  31. #endif // __LOOK_IDLE_H

2.LOOK_IDLE.CPP
  1. #include "LOOK_IDLE.h"
  2. #include "NUC1xx.h"
  3. #include "NUC1xxM051Seriescfg.h"

  4. #define BEEP Pin10//BEEP在PB.10

  5. // 空闲任务类 task_LOOK_IDLE_t 的例程
  6. void task_LOOK_IDLE_t::routine()
  7. {
  8. // TODO: 在此编写 task_LOOK_IDLE_t 例程的内容
  9. volatile unsigned int key;
  10. timer1.start(interval1);//启动定时器1
  11. while (true) {
  12. // TODO: 在此编写 task_LOOK_IDLE_t 例程的内容
  13. key = GPIOBs.PIN.Regs;//取键盘值
  14. for (unsigned int i = 0; i < 0x8888; i++) asm volatile("nop");
  15. if (key == GPIOBs.PIN.Regs) {//等待抖动过去
  16. if ((key & (1 << 14)) == 0) {//Key2
  17. while (key == GPIOBs.PIN.Regs);//等待键释放
  18. if (interval1 <= 500) {
  19. interval1 += 50;
  20. count2 = 2;//响一声
  21. timer2.start(interval2);//启动定时器2
  22. }
  23. }
  24. else if ((key & (1 << 15)) == 0) {//Key1
  25. while (key == GPIOBs.PIN.Regs);//等待键释放
  26. if (interval1 > 50) {
  27. interval1 -= 50;
  28. count2 = 6;//响三声
  29. timer2.start(interval2);//启动定时器2
  30. }
  31. }
  32. }
  33. }
  34. __builtin_unreachable();
  35. }


  36. void task_LOOK_IDLE_t::on_signal(void* addr, uintptr_t signal)
  37. {
  38. if (addr == &timer1) {
  39. //处理定时器事务
  40. timer1.do_start(interval1);//重置定时器
  41. GPIOAs.DMASK.Regs = ~0b111100;
  42. GPIOAs.DOUT.Regs = (count1 << 2) ^ 0b111100;
  43. count1 ++;
  44. }
  45. else if (addr == &timer2) {
  46. //处理定时器事务
  47. GPIOBs.DMASK.Bits.BEEP = 0;
  48. if (count2 > 0) {
  49. GPIOBs.DOUT.Bits.BEEP ^= 1;
  50. timer2.do_start(interval2);//重置定时器
  51. count2 --;
  52. }
  53. else {
  54. GPIOBs.DOUT.Bits.BEEP = 0;
  55. timer2.do_kill();//清除定时器
  56. }
  57. }
  58. else {
  59. idle_task_t::on_signal(addr, signal);
  60. }

  61. }

  62. namespace look{//必须写!!!
  63. instantiate::idle<task_LOOK_IDLE_t, 2* LOOK_STACK_SIZE> idle_task(false);
  64. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
lzlz70707 发表于 2011-5-25 00:10 | 显示全部楼层
沙发
 楼主| hotpower 发表于 2011-5-25 01:13 | 显示全部楼层
这实际上是个裸奔的思想编写的LOOK程序
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

508

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

508

粉丝
快速回复 在线客服 返回列表 返回顶部