[LOOK] LOOK+红杏头文件 学习第一帖:1个KEY控制4个LED闪烁

[复制链接]
 楼主| Swallow_0322 发表于 2011-5-15 16:56 | 显示全部楼层 |阅读模式
本帖最后由 hotpower 于 2011-6-19 01:25 编辑

     LOOK实现两个小任务:
     ①  助学板上四个LED小灯轮流点亮,有两种显示模式,方式 1为LED1--->LED2--->LED3--->LED4--->LED1循环,方式2为LED4--->LED3--->LED2--->LED1--->LED4循环,初始化为方式1;
     ②  助学板上KEY2按下调整LED的循环方式。


     虽然Lee老师一直普及CPP,但是看到CPP的程序依旧是云里雾里。此贴仅是根据老师0510的群课多加个任务,完全是照猫画虎,望多多指教!
     关于大叔的红杏头文件,暂时还无法自如运用,首先因为一直用新唐的库熟悉NUC120,对其寄存器不是很熟悉,其次对大叔的红杏头文件了解不深,最后是暂时无法智能感知。
     初次接触LOOK,初次使用红杏,望各位高手不要见笑!

部分源程序:
LED.CPP            (20110515 17:25更正)
  1. #include "NUC1xx.h"
  2. #include "NUC1xxM051Seriescfg.h"
  3. #include "led.h"

  4. uint8_t **_FlashMode = TRUE;

  5. // 任务类 task_led_t 的例程
  6. void task_led_t::routine()
  7. {
  8. // TODO: 在此编写 task_led_t 例程的内容
  9. GPIOAs.DMASK.Regs = ~0b111100;
  10. GPIOAs.DOUT.Regs = ~0b100;
  11. while (true) {
  12. // TODO: 在此编写 task_led_t 例程的内容
  13. uint32_t data = GPIOAs.DOUT.Regs & 0b111100;
  14. if (**_FlashMode)
  15. {
  16. data <<= 1;
  17. data += data >> 4;

  18. }
  19. else
  20. {
  21. data >>= 1;
  22. data += data << 4;
  23. }
  24. GPIOAs.DOUT.Regs = data;
  25. delay(LOOK_TICKS_PER_SEC);
  26. }
  27. }

  28. // 任务类 task_key_t 的例程
  29. void task_key_t::routine()
  30. {
  31. // TODO: 在此编写 task_led_t 例程的内容

  32. while (true) {
  33. // TODO: 在此编写 task_led_t 例程的内容
  34. if (key_read())
  35. **_FlashMode = !**_FlashMode;
  36. delay(LOOK_TICKS_PER_SEC/10);
  37. }
  38. }

  39. // 任务类 task_key_t 的成员函数
  40. __OPT_INLINE__ int8_t task_key_t::key_read()
  41. {
  42. uint32_t Key_Tmp = TRUE;
  43. static uint32_t Key_Record = TRUE; //按键记录

  44. Key_Tmp = GPIOBs.PIN.Bits.Pin14;
  45. if(Key_Tmp==TRUE) //无有效按键按下
  46. {
  47. Key_Record = TRUE; //清除按键记录
  48. return FALSE; //程序退出
  49. }
  50. if(Key_Record!=Key_Tmp) //为新按键
  51. {
  52. Key_Record=Key_Tmp; //保存本次结果
  53. delay(LOOK_TICKS_PER_SEC/100); //延时去抖动
  54. Key_Tmp = GPIOBs.PIN.Bits.Pin14;
  55. if(Key_Tmp==Key_Record)
  56. return TRUE;
  57. }
  58. return FALSE;
  59. }


  60. #ifdef LOOK_SCHEDULING_PRIORITY
  61. instantiate::task<task_led_t, LOOK_STACK_SIZE> task_led(0);
  62. #else
  63. instantiate::task<task_led_t, LOOK_STACK_SIZE> task_led;
  64. #endif

  65. #ifdef LOOK_SCHEDULING_PRIORITY
  66. instantiate::task<task_key_t, LOOK_STACK_SIZE> task_key(0);
  67. #else
  68. instantiate::task<task_key_t, LOOK_STACK_SIZE> task_key;
  69. #endif


LED.h
  1. #include "look_config.h"
  2. #include <look.h>
  3. #include <instantiate>

  4. // 任务类 task_led_t 的定义
  5. class task_led_t : public task_t {
  6. public:
  7. task_led_t() __OPT_ATTR__; // 构造函数

  8. protected:
  9. void routine(); // 任务例程

  10. };

  11. // 任务类 task_led_t 的构造函数
  12. __OPT_INLINE__ task_led_t::task_led_t()
  13. {
  14. // TODO: 在此初始化 task_led_t 的类成员
  15. }

  16. // 任务类 task_key_t 的定义
  17. class task_key_t : public task_t {
  18. public:
  19. task_key_t() __OPT_ATTR__; // 构造函数
  20. int8_t key_read() __OPT_ATTR__;

  21. protected:
  22. void routine(); // 任务例程

  23. };


  24. // 任务类 task_key_t 的构造函数
  25. __OPT_INLINE__ task_key_t::task_key_t()
  26. {
  27. // TODO: 在此初始化 task_led_t 的类成员
  28. }


  29. extern instantiate::task<task_led_t, LOOK_STACK_SIZE> task_led;
  30. extern instantiate::task<task_key_t, LOOK_STACK_SIZE> task_key;


工程结构:


工程包:

本帖子中包含更多资源

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

×
john_lee 发表于 2011-5-15 17:01 | 显示全部楼层
本帖最后由 john_lee 于 2011-5-15 17:07 编辑

沙发。顶三心二意!正好以此例子深入。
murex 发表于 2011-5-15 17:20 | 显示全部楼层
写的蛮好的,比只是点灯多点可操作了
 楼主| Swallow_0322 发表于 2011-5-15 17:27 | 显示全部楼层
2# john_lee

谢谢老师光临指导!(*^__^*) 嘻嘻!
 楼主| Swallow_0322 发表于 2011-5-15 17:28 | 显示全部楼层
3# murex

多谢!其实俺是迷糊中完成的!:lol
xuyaosong 发表于 2011-5-15 22:19 | 显示全部楼层
多谢分享,不过我完全复制你的代码,放到之前的led例程里面,编译不能通过
而下载你的压缩包后编译没有问题,对照了头文件、include path、代码内容都一样,就是不知道为啥

编译错误为:
compiling led.cpp...
led.cpp(8): error: 'task_led_t' has not been declared
led.cpp(33): error: 'task_key_t' has not been declared
led.cpp: In function 'void routine()':
led.cpp(33): error: redefinition of 'void routine()'
led.cpp(8): error: 'void routine()' previously defined here
led.cpp(39): error: 'key_read' was not declared in this scope
led.cpp: At global scope:
led.cpp(46): error: 'task_key_t' has not been declared
led.cpp(72): error: 'task_led_t' was not declared in this scope
led.cpp(72): error: template argument 1 is invalid
led.cpp(72): error: invalid type in declaration before ';' token
led.cpp(78): error: 'task_key_t' was not declared in this scope
led.cpp(78): error: template argument 1 is invalid
led.cpp(78): error: invalid type in declaration before ';' token
xuyaosong 发表于 2011-5-15 22:27 | 显示全部楼层
OK了,不知道为啥复制到led.h的头文件没有被包含进去,原来的led.h头文件没有被更新
 楼主| Swallow_0322 发表于 2011-5-16 07:39 | 显示全部楼层
7# xuyaosong

呵呵!OK就好!
一定要按照Lee老师0510的群课步骤去做,注意配置时钟及GPIO功能
hotpower 发表于 2011-5-16 09:16 | 显示全部楼层
老师做的脚本很方便了
weshiluwei6 发表于 2011-5-17 23:31 | 显示全部楼层
你也太牛了吧
 楼主| Swallow_0322 发表于 2011-5-18 07:38 | 显示全部楼层
10# weshiluwei6

:$  呵呵 这都是老师讲的内容哦!
lixupengarm 发表于 2011-6-1 11:15 | 显示全部楼层
学习!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:播种一种行为,收获一种习惯;播种一种习惯,收获一种性格;播种一种性格,收获一种人生!

121

主题

1393

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:播种一种行为,收获一种习惯;播种一种习惯,收获一种性格;播种一种性格,收获一种人生!

121

主题

1393

帖子

4

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