x mbed2リビジョン144
x リビジョンを変更できる人むけ
目的
GPIOのテスト
WS2812のテスト
LPC812
説明
WS2812Bの接続ピンは、P0_6です。
//WS2812_LED8_TABLE_812_1
#include "mbed.h"
//点灯テーブル
const char train_x[16][3*8] =
{//G0,R0,B0 G1,R1,B1 G2,R2,B2 G3,R3,B3 G4,R4,B4 G5,R5,B5 G6,R6,B6 G7,R7,B7
{ 2,32,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
{ 0, 0, 0, 32, 2,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1
{ 0, 0, 0, 0, 0, 0, 32,32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,32,32, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,32,32, 0, 0, 0, 0, 0, 0}, //5
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 2,32, 0, 0, 0}, //6
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,32, 2}, //7
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 2,32, 0, 0, 0}, //8
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,32,32, 0, 0, 0, 0, 0, 0}, //9
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,32,32, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //10
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //11
{ 0, 0, 0, 0, 0, 0, 32,32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //12
{ 0, 0, 0, 32, 2,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //13
{ 2,32,32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //14
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //15
};
//GPIOの宣言
DigitalOut myled(P0_6);
//ビットパターン
// 654321009876543210
#define on1 0b0000000001000000
#define off1 0b0000000000000000
//LEDの配列
int l[90]; //max30 led
//プロトタイプ宣言
void bit_on1();
void bit_off1();
// 12345678 12345678 12345678 12345678
int b8[8] = {0b10000000,0b01000000,0b00100000,0b00010000,
0b00001000,0b00000100,0b00000010,0b00000001,
};
//WS2812Bに転送する バイト単位
int ws_led(int num1)
{
int on_off;
__disable_irq(); // disable interrupt
//__enable_irq(); // enable interrupt
for(int ii=0; ii<num1; ii++) {
//8ビット分送る
for(int jj=0; jj<8; jj++) {
on_off = l[ii] & b8[jj];
if( on_off == 0 ) {
//ビットが0
bit_off1();
} else {
//ビットが1
bit_on1();
}//endif
}//for 8bit
}//for max30byt
//__disable_irq(); // disable interrupt
__enable_irq(); // enable interrupt
return(0);
}
//メイン関数
int main()
{
//無限ループ
while(1){
for(int jj=0;jj<16;jj++){
for(int ii=0;ii<(3*8);ii++){
l[ii] = train_x[jj][ii];
}//for ii
//ws2812bへデータを送る
ws_led(3*8);
//0.2秒待つ
wait_ms(200);
}//for jj
} //while
} //main
// 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
void bit_off1()
{
//0.3us 800khz
LPC_GPIO_PORT->PIN0 = on1;
__NOP();
__NOP();
__NOP();
LPC_GPIO_PORT->PIN0 = off1;
__NOP();
__NOP();
//LPC_GPIO_PORT->PIN0 = off1;
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
}//bit_off1
// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
void bit_on1()
{
//1us 800khz
LPC_GPIO_PORT->PIN0 = on1;
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
LPC_GPIO_PORT->PIN0 = off1;
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
}//bit_on1
-28-