2013/08/11からのアクセス回数 5561 PinNamesの設定 †mbedライクなクラスライブラリlbedのLPC1343版を作ってみることにしました。 ピンの配置は、秋月で購入できる LPC1343評価キット に合わせました。 Wait APIの実装 †移植ではまったのが、LPC1114と互換性のあると思っていたタイマー機能が、 LPC1343では異なることでした。 また、wait_usで使っているビジーウェイトがオプティマイズによって変な動きを することで、1週間ほど悩みました。 *1 wait_api.cは、以下の様になりました。 #include <LPC13xx.h> #include "wait_api.h" volatile uint32_t msTicks; /* counts 1ms timeTicks */ /*---------------------------------------------------------------------------- SysTick_Handler *----------------------------------------------------------------------------*/ void SysTick_Handler(void) { msTicks++; /* increment counter necessary in Delay() */ } void wait_init() { if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts */ while (1); /* Capture error */ } } void wait_ms(int ms) { uint32_t curTicks; curTicks = msTicks; while ((msTicks - curTicks) < ms); } void wait_us(int us) { volatile long i = 8*us; while (i-- > 0) continue; } TestLEDのLED点滅で動作確認 †手持ちのLPC1343評価キットで、TestLED.cppを動かしてみました。 *2 #include <cr_section_macros.h> #include <NXP/crp.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP extern const unsigned int CRP_WORD = CRP_NO_CRP ; #include "lbed.h" int main(void) { wait_init(); DigitalOut myled(LED2); while(1) { myled = ! myled; wait_ms(1000); } } TestLCDで文字を表示 †LCDに文字を出力しようとしたら、LPC1343評価キットに付けたUSBコネクターの障害で電圧が低くて 動きませんでした。 代わりに手持ちの LPC1343 QuickStart Board を使ってLCDに出力することにしました。 *3 OrangeボードのCNとの接続は、 LPC1343 QuickStart BoardのDIL30の16-20, 22を使いました。
プログラムは、以下の様にピン設定しました。 #include<cr_section_macros.h> #include<NXP/crp.h> __CRP extern const unsigned int CRP_WORD = CRP_NO_CRP ; #include "lbed.h" #include "TextLCD.h" int main(void) { int count = 0; wait_init(); DigitalOut myled(LED2); TextLCD lcd(P1_5, P1_6, P1_7, P0_1, P2_0, P1_8); // rs, e, d4-7 lcd.print("Hello World!"); while(1) { lcd.locate(0, 1); lcd.print("Count="); lcd.print(count++); myled = ! myled; wait_ms(1000); } } 最新のソース †LPC1343版のソースは、Githubの以下のURLにあります。 コメント †Tweet |