查看: 4001|回复: 1

Linker LED bar on pcDuino

[复制链接]
  • TA的每日心情
    郁闷
    2013-6-3 09:22
  • 签到天数: 29 天

    连续签到: 1 天

    [LV.4]偶尔看看III

    发表于 2013-4-1 12:19:09 | 显示全部楼层 |阅读模式
    分享到:
    这个教程介绍pcDuino连接Linker LED bar

    48C23107863A494E9D66DF024A3BD7AB.png

    Linker Kit 所有的示例代码可以在 这里下载。
    这里需要用到的代码如下:
    1. /*
    2. * LED bar test program for a10
    3. */
    4. #include

    5. #define DATA_Pin 0 //DATA IN
    6. #define CLK_Pin 1 //CLK IN

    7. #define CmdMode 0x0000 //Work on 8-bit mode
    8. #define ON 0x00ff //8-bit 1 data
    9. #define SHUT 0x0000 //8-bit 0 data

    10. static int s_clk_flag = 0;

    11. void send16bitData(unsigned int data)
    12. {
    13. for(unsigned char i=0;i<16;i++){
    14. if(data & 0x8000){
    15. digitalWrite(DATA_Pin, HIGH);
    16. }else{
    17. digitalWrite(DATA_Pin, LOW);
    18. }

    19. if(s_clk_flag){
    20. digitalWrite(CLK_Pin, LOW);
    21. s_clk_flag = 0;
    22. }else{
    23. digitalWrite(CLK_Pin, HIGH);
    24. s_clk_flag = 1;
    25. }

    26. data <<= 1;
    27. }
    28. }

    29. //latch routine for MY9221 data exchange
    30. void latchData(void)
    31. {
    32. int latch_flag = 0;
    33. digitalWrite(DATA_Pin, LOW);
    34. delayMicroseconds(200);
    35. for(unsigned char i=0;i<8;i++){
    36. if(latch_flag){
    37. digitalWrite(DATA_Pin, LOW);
    38. latch_flag = 0;
    39. }else{
    40. digitalWrite(DATA_Pin, HIGH);
    41. latch_flag = 1;
    42. }
    43. }
    44. delayMicroseconds(200);
    45. }

    46. void sendLED(unsigned int LEDstate)
    47. {
    48. unsigned char i;
    49. for(i=0;i<12;i++) { if(LEDstate&0x0001) send16bitData(ON); else send16bitData(SHUT); LEDstate=LEDstate>>1;
    50. }
    51. }

    52. void setup()
    53. {
    54. printf("LED bar test code!\n");
    55. printf("Using I/O_0=DATA, I/O_1=CLK.\n");

    56. pinMode(DATA_Pin,OUTPUT); //Data pin
    57. pinMode(CLK_Pin,OUTPUT); //CLK pin
    58. digitalWrite(DATA_Pin, LOW);
    59. digitalWrite(CLK_Pin, LOW);
    60. s_clk_flag = 0;
    61. }

    62. void loop()
    63. {

    64. /*
    65. send16bitData(CmdMode); //set LED Bar mode
    66. sendLED(0x0155); //send LED Bar data
    67. latchData(); //make it come into effect
    68. delay(2000);

    69. send16bitData(CmdMode); //set LED Bar mode
    70. sendLED(0x02aa); //send LED Bar data
    71. latchData(); //make it come into effect

    72. delay(2000);
    73. */

    74. unsigned int i = 0x0000;
    75. unsigned int loop = 0x0;

    76. while(i<=0x03ff)
    77. {
    78. send16bitData(CmdMode); //set LED Bar mode
    79. sendLED(i); //send LED Bar data
    80. latchData(); //make it come into effect
    81. i=i*2+1;
    82. delay(100);
    83. }

    84. }
    复制代码
    在编译之前还需要修改位于“myworkingdirectory/arduino/sample”路径的“Makefile”。
    1. DIR=$(shell pwd)/../

    2. INCS = -I.\
    3. -I$(DIR) \
    4. -I$(DIR)/hardware \
    5. -I$(DIR)/hardware/arduino \
    6. -I$(DIR)/hardware/arduino/cores \
    7. -I$(DIR)/hardware/arduino/cores/arduino \
    8. -I$(DIR)/hardware/arduino/variants \
    9. -I$(DIR)/hardware/arduino/variants/sunxi \
    10. -I$(DIR)/libraries \
    11. -I$(DIR)/libraries/Serial \
    12. -I$(DIR)/libraries/SPI \
    13. -I$(DIR)/libraries/Wire \
    14. -I$(DIR)/libraries/LiquidCrystal \
    15. -I$(DIR)/libraries/ADXL345 \
    16. -I$(DIR)/libraries/TFTtouch

    17. LIBS=../libarduino.a
    18. TARGET=../output/test

    19. OBJS = paint Motor_shield xbee_relay xbee_shield relay_shield nfc_test drawCircle test sim900 smg \
    20. io_test adc_test pwm_test spi_test adxl345_test serial_test liquidcrystal_i2c liquidcrystal_spi \
    21. linker_led_bar_test

    22. all:
    23. @mkdir -p $(TARGET)
    24. for i in $(OBJS); do echo "$(CXX) $(INCS) $$i.c -o $(TARGET)/$$i $(LIBS)"; done
    25. @for i in $(OBJS); do $(CXX) $(INCS) $$i.c -o $(TARGET)/$$i $(LIBS); done

    26. clean:
    27. @for i in $(OBJS); do rm -f $(TARGET)/$$i; done
    复制代码
    接着需要添加 “linker_led_bar_test”路径到 OBJS
    找到 “sample”目录,输入“make”进行编译。
    然后连接Linker LED bar,引脚连接方法:
    l GND of LED bar -> GND of pcDuino
    l VCC of LED bar -> 3.3V of pcDuino
    l DCKI of LED bar ->D1 of pcDuino(TX)
    l DI of LED bar -> D0 of pcDuino(RX)
    C338FC64BCB04406BE37392BA22C8ACD.png

    5AC6B97A2CA245DF9F3108CDB5BC43A7.png

    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2015-8-5 08:38
  • 签到天数: 12 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    发表于 2013-7-2 13:26:04 | 显示全部楼层
    顶一个!
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /5 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-12-20 22:14 , Processed in 0.124659 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.