在pcDuino上运行Linker LED Bar-Arduino中文社区 - Powered by Discuz! Archiver

Lily 发表于 2014-2-28 18:00

在pcDuino上运行Linker LED Bar

本帖最后由 Lily 于 2014-2-28 18:02 编辑

LED light bar 原理其实很简单,跟我们平常过的数码管一样,只是我们公司的这个模块用了一个LED驱动芯片MY9221来驱动,这样可以将很多个模块串联起来。MY9221是一个带有跟SPI十分相似的LED驱动芯片,可以驱动12个LED灯,每个LED灯的亮度都可以由串行接口送进来的数据进行PWM调制。
一、试验器材:1套pcduin套件、1块Linker LED Bar、连接线
二、试验连线图:电源(VCC)请接到pcduino v2上的3.3V上,电线(GND)请接在pcduino v2的GND上。数据时钟(DCLK),跟数据输入(DIN)可以随便接在两个数字接口上(D0至D13)都行,但一定要跟例程代码里面的定义相同
三、试验代码:/*


* LED bar test program


*/


#include <core.h>




#define DATA_Pin 4//DATA IN


#define CLK_Pin5//CLK IN


#define LED_pin 2


#define CmdMode 0x0000//Work on 8-bit mode


#define ON 0x0005               //8-bit 1 data


#define SHUT 0x0000         //8-bit 0 data




void send16bitData(unsigned int data)


{


unsigned char i;


boolean clk_pin_state;




clk_pin_state = digitalRead(CLK_Pin);


for(i=0;i<16;i++)


{


      if(data & 0x8000) digitalWrite(DATA_Pin, HIGH);


      else digitalWrite(DATA_Pin, LOW);


      clk_pin_state = !clk_pin_state;


      digitalWrite(CLK_Pin, clk_pin_state);


      data <<= 1;


      delayMicroseconds(1);


   }


}




//latch routine for MY9221 data exchange


void latchData(void)


{


   unsigned char i;


   boolean data_pin_state;




   digitalWrite(DATA_Pin, LOW);


   data_pin_state = LOW;


   delayMicroseconds(300);


   for(i=0;i<8;i++)


   {


   data_pin_state = !data_pin_state;


   digitalWrite(DATA_Pin, data_pin_state);


   delayMicroseconds(1);


   }


   delayMicroseconds(300);


}




void sendLED(unsigned int LEDstate)


{


unsigned char i;




for(i=0;i<12;i++)


{


    if(LEDstate&0x0001)send16bitData(ON);


    elsesend16bitData(SHUT);


    LEDstate >>= 1;


}


}




void setup()


{


    pinMode(DATA_Pin,OUTPUT);   //Data pin


    pinMode(CLK_Pin,OUTPUT);//CLK pin


    pinMode(LED_pin,OUTPUT);//LED_pin


    digitalWrite(DATA_Pin, LOW);


    digitalWrite(CLK_Pin, LOW);


}




void loop()


{


unsigned int tmpInt;




for(tmpInt=1;tmpInt < 0xFFF;tmpInt |= (tmpInt<<1))


{


    send16bitData(CmdMode); /file:///C:\Users\ADMINI~1.PC-\AppData\Local\Temp\V7(XMWRN]{G8~CI}BCCR3QC.gift LED Bar mode


    sendLED(tmpInt);      /file:///C:\Users\ADMINI~1.PC-\AppData\Local\Temp\V7(XMWRN]{G8~CI}BCCR3QC.gifnd LED Bar data


    latchData();//make it come into effect


    delay(100);


}


digitalWrite(LED_pin, LOW);


for(;tmpInt != 0;tmpInt >>=1)


{


    send16bitData(CmdMode); /file:///C:\Users\ADMINI~1.PC-\AppData\Local\Temp\V7(XMWRN]{G8~CI}BCCR3QC.gift LED Bar mode


    sendLED(tmpInt);      /file:///C:\Users\ADMINI~1.PC-\AppData\Local\Temp\V7(XMWRN]{G8~CI}BCCR3QC.gifnd LED Bar data


    latchData();//make it come into effect


    delay(100);


}


send16bitData(CmdMode); /file:///C:\Users\ADMINI~1.PC-\AppData\Local\Temp\V7(XMWRN]{G8~CI}BCCR3QC.gift LED Bar mode


sendLED(0);      /file:///C:\Users\ADMINI~1.PC-\AppData\Local\Temp\V7(XMWRN]{G8~CI}BCCR3QC.gifnd LED Bar data


latchData();//make it come into effect


delay(100);


digitalWrite(LED_pin, HIGH);




}
四、运行结果如图:http://linksprite.com/wiki/index.php5?title=Products-description#pcDuino



页: [1]
查看完整版本: 在pcDuino上运行Linker LED Bar