- 追加された行はこの色です。
- 削除された行はこの色です。
[[lbed]]
#contents
2013/08/11からのアクセス回数 &counter;
** PinNamesの設定 [#sdf857c2]
mbedライクなクラスライブラリlbedのLPC1343版を作ってみることにしました。
ピンの配置は、秋月で購入できる
[[LPC1343評価キット>http://akizukidenshi.com/catalog/g/gM-03598/]]
に合わせました。
&ref(LPC1343_pin_layout.png);
*** Wait APIの実装 [#hd508b6b]
移植ではまったのが、LPC1114と互換性のあると思っていたタイマー機能が、
LPC1343では異なることでした。
また、wait_usで使っているビジーウェイトがオプティマイズによって変な動きを
することで、1週間ほど悩みました。
((最後は、オシロスコープの波形をみて、何とか動くようになりました))
wait_api.cは、以下の様になりました。
#pre{{
#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; // 72MHzの4クロックでループを回ると仮定
volatile long i = 8*us;
while (i-- > 0)
continue;
}
}}
*** TestLEDのLED点滅で動作確認 [#oa4497bf]
手持ちのLPC1343評価キットで、[[TestLED.cpp>lbed/01-LEDチカチカ]]を動かしてみました。
((どうもデバッガで書き込むときに、一回目はエラーになります。))
&ref(LPC1343_board.png);
#pre{{
#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で文字を表示 [#h271a1df]
LCDに文字を出力しようとしたら、LPC1343評価キットに付けたUSBコネクターの障害で電圧が低くて
動きませんでした。
代わりに手持ちの
[[LPC1343 QuickStart Board>http://akizukidenshi.com/catalog/g/gM-06892/]]
を使ってLCDに出力することにしました。
((このボードは小型でブレッドボードで使うのに便利です))
((このボードは小型でブレッドボードで使うのに便利です。秋月で購入できます。))
OrangeボードのCNとの接続は、 LPC1343 QuickStart BoardのDIL30の16-20, 22を使いました。
- DIL_16:PIO1_5 CN:p24
- DIL_17:PIO1_6 CN:p26
- DIL_18:PIO1_7 CN:p27
- DIL_19:PIO0_1 CN:p28
- DIL_20:PIO2_0 CN:p29
- DIL_22:PIO1_8 CN:p30
&ref(QuickStartBoard.png);
プログラムは、以下の様にピン設定しました。
#pre{{
#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);
}
}
}}
** 最新のソース [#zeeb6339]
LPC1343版のソースは、Githubの以下のURLにあります。
- https://github.com/take-pwave/lbed
** コメント [#v65db5cc]
#comment_kcaptcha