要約:このアプリケーションノートでは、DS8007デュアルスマートカードインタフェース用の評価(EV)キットをすぐに使用できるよう必要な手順について説明しています。この記事では、ソフトウェアのインストールと設定方法、ハードウェアの設定方法、およびオンボードDS5002FPマイクロコントローラで実行可能なアプリケーションの作成とロードの方法について説明します。また、オンボードLCDモジュールの使用を実証するため、単純な「Hello World (ハローワールド)」の例と、Cソースコードによるいくつかの関数を提供します。
「Select Device for Target (ターゲットデバイスの選択)」が表示されたら、Dallas Semiconductorフォルダを選択し、デバイス選択リストからDS5002FPを選択します。
「Copy Standard 8051 Startup Code to Project Folder and Add File to Project (8051標準開始コードをProjectフォルダにコピーし、ファイルをプロジェクトに追加します)」メッセージが表示されたら、「Yes」ボタンをクリックします。
// File DS8007-1.C
#include <REG5000.H> // special function register declarations
// // for the DS5000/5002
#include <stdio.h> // prototype declarations for I/O functions
// Main C function. Program execution starts here.
void main (void) {
// Set up the serial port for 38400 baud at 14.7MHz.
TMOD=0x21; // Timer 1: 8-bit auto-reload from TH1, Timer 0: 16-bit
TH1 = 0xFE; // Set timer reload value for 38,400 baud
PCON|=0x80; // Turn on baud rate doubler SMOD_0
TCON=0x50; // Enable timers 0 and 1
SCON=0x50; // 10-bit async, enabled
TI=1; // Set TI to send first character
TR1 = 1; // Start timer 1
// Start main program
printf ("\nHello DS8007 World!\n\n"); // Output message
while (1) ; // End program by looping here.
}
上記のテキストを入力した後、「File (ファイル)」→「Save As (名前を付けて保存)」をクリックし、ファイル名に「DS8007-1.c」を入力してファイルを保存します。
Project Workspace (プロジェクトワークスペース)ウィンドウのTarget 1 (ターゲット1)を右クリックして、「Options for Target 'Target 1 (ターゲットのオプション「ターゲット1」)」を選択し、プロジェクトオプションを設定します。Target (ターゲット)タブをクリックし、下の図3に示すようにXtalボックスに14.7と入力します。また、Memory Model (メモリモデル)に「Small: variables in DATA (小:データ内に変数あり)」を選択し、Code ROM Size (コードROMサイズ)に「Large: 64K program (大:64Kプログラム)」、Operating system (オペレーティングシステム)に「None (なし)」を選択します。このウィンドウでのその他の選択項目については、すべてデフォルト設定のままで変更する必要はありません。
Output (出力)タブで、「Create Executable (実行可能ファイルを作成)」にチェックマークが付いていない場合は、図4に示すようにチェックマークを付けます。また、「Create HEX File (HEXファイルを作成)」にチェックマークが付いていることを確認します。図4に示すように、HEX Format (HEXフォーマット)のドロップダウン選択ボックスからHEX-80を選択します。このウィンドウでのその他の選択項目については、すべてデフォルト設定のままで変更しないようにしてください。「OK」をクリックし、Options for Target 'Target 1' (ターゲットのオプション「ターゲット1」)ウィンドウを閉じます。
「File (ファイル)」→「Save All (すべて保存)」をクリックして、Projectファイルを保存します。
メインメニューで「Project (プロジェクト)」をクリックして、「Rebuild All Target Files (すべてのターゲットファイルを再構築)」を選択し、実行ファイルを作成します。画面下のビルドウィンドウに0 Error(s), 0 Warning(s) (エラー:0、警告:0)が表示される必要があります。エラーがある場合には、エラーを見つけて必要な修正を行います。エラーがなくなるまでこの手順を繰り返します。
「Options (オプション)」→「Configure Serial Port (シリアルポートを設定)」をクリックします。DS8007ボードが接続されているコンピュータのPort (ポート)を選択します(例:COM1)。次に、ドロップダウンメニューから「Speed 38400 (スピード38400)」を選択し、「OK」をクリックします。
「Target (ターゲット)」→「Open COM1 at 38400 baud (COM1を38400ボーで開く)」をクリックします。
ボードのシリアルポートがコンピュータに接続され、5Vの電源が供給されていることを確認します。「Target (ターゲット)」と「Connect to Loader (ローダへ接続)」をクリックします。接続が成功した場合には、図6に示すように、DS5002FPのブートローダバナーが表示されます。
プロンプト記号>の後に以下のコマンドを入力し、MCONおよびRPCTLレジスタを設定します。
> W MCON 0A
> W RPCTL 01
> R
MCON:0A RPCTL:81 MSL:01 Microcontroller's response to read register command
ロードが完了すれば、プロセッサは「Load complete (ロード完了)」を通知します。「Target (ターゲット)」→「Disconnect from Loader (ローダから切断)」をクリックすることで、プログラムを実行することができます。
ブートストラップローダが切断されると直ちに、プロセッサはプログラムの実行を開始します。MTK画面にプログラムの出力結果「Hello DS8007 World ! (ハロー、DS8007ワールド)」が表示されます。これが表示されたら作業は成功です !
図5. MTKデバイスの選択
図6. DS5002FPブートローダバナー
EVキットLCDモジュール
次に、DS8007EVキットの非常に有用な機能の1つを実証するため、2行20文字の液晶ディスプレイ(LCD)にメッセージを表示させるアプリケーションプログラムを作成します。ただしその前に、LCDコントラスト調整を設定し、プログラムの実行時にLCDにメッセージが適切に表示されるようにする必要があります。まず、ボードに電源を供給しますが、このときLCDには何も表示されていないことを確認してください。可変抵抗器R7をボード上に設置します(上図2を参照)。小型のねじ回しを使用して、ディスプレイの文字位置に各5 x 7ドットの四角が表示されるまで、レジスタを調整します。表示された四角がちょうど消えるまで、R7をゆっくりと調整します。これでLCDのコントラストは調整され、文字は表示されますが、スペースは表示されなくなります。
// file DS8007-2.c
//
#include <REG5000.H> // special function register declarations
// // for the DS5000/5002 #include <string.h>
#include "LCD_Funct.h"
int tmp = 0;
uint8_t LCD_Str[42];
void main(void)
{
// Initialize LCD Module, and display 2-line message.
LCD_Init();
strcpy(LCD_Str, "DS8007 Dual"); // Create first line of LCD text
tmp = LCD_Curpos(1,5); // Position cursor line 1 char 5
if (tmp == 0) LCD_WRStr(LCD_Str); // Write string to LCD
strcpy(LCD_Str, "Smart Card Interface"); // Create 2nd line of LCD text
tmp = LCD_Curpos(2,1); // Position cursor on line 2, char 1
if (tmp == 0) LCD_WRStr(LCD_Str); // Write string to LCD
tmp = LCD_Curpos(1,20); // Return cursor to line 1 char 20
while (1); // Loop here to end program
}
void LCD_Init()
{
LCD_Delay(); // Delay to ensure that LCD power-up is complete
LCD_WRCmd(FnctSet); // Write FnctSet instruction
LCD_WRCmd(DispCnt); // Write Display Control instruction
LCD_WRCmd(DispClear); // Write Display Clear instruction
LCD_WRCmd(EntryMode); // Write Entry Mode instruction
}
// Write a string to the 2 x 20 LCD module
void LCD_WRStr(uint8_t LCD_Str[])
{
int i = 0;
while ((LCD_Str[i] != '\0') && (i < 20))
{
LCD_WRChr(LCD_Str[i]) ; // Write first 20 characters
i++;
}
if (LCD_Str[i] != '\0')
LCD_WRCmd(Line2Ad); // Set CGRAM address to first char 2nd line
while ((LCD_Str[i] != '\0') && (i < 40))
{
LCD_WRChr(LCD_Str[i]) ;
i++;
}
}
// Write a single character to the 2 x 20 LCD module
void LCD_WRChr(uint8_t LCD_Chr)
{
LCD_Busy(); // Wait until the LCD is not busy
LCD_RS = 1; // Set RS high for character write
LCD_Dat = LCD_Chr; // Output character
LCD_EN = 1; // Set enable high
LCD_EN = 0; // Clear enable
LCD_RS = 0;
LCD_Dat = 0xFF; // Re-establish Port Pins as inputs
}
// Write a command to the 2 x 20 LCD module
void LCD_WRCmd(uint8_t LCD_Cmd)
{
LCD_EN = 0; // Make sure that the LCD enable is low
LCD_RS = 0; // Set LCD register select and R/W lines
LCD_RW = 0;
LCD_Busy(); // Make sure that the display is not busy
LCD_Dat = LCD_Cmd; // Output instruction
LCD_EN = 1; // Set enable high
LCD_EN = 0; // Clear enable
LCD_Dat = 0xFF; // Re-establish Port Pins as inputs
}
// Set the cursor position to a specific location
int LCD_Curpos(uint8_t VPos, uint8_t HPos)
{
int rtn;
uint8_t Addr, Cmd;
// Check input range 1..2 line, 1..20 characters per line
if (((VPos == 0) || (VPos > 2)) || ((HPos == 0) || (HPos > 20)))
rtn = -1;
else
{
if(VPos == 2) Addr = (0x40 + (HPos - 1));
else Addr = HPos - 1;
rtn = 0;
Cmd = Addr | 0x80;
LCD_WRCmd(Cmd);
}
return(rtn);
}
// Test the LCD Module to see if it is Busy (loop until
// not busy)
void LCD_Busy()
{
uint8_t LCD_Stat = LCD_Dat; // Get byte containing status
while (LCD_Stat & 0x80){ // Wait for busy flag to clear
LCD_RW = 1; // LCD RW needs to be high
LCD_EN = 1; // Strobe enable signal
LCD_Stat = LCD_Dat; // Read staus
LCD_EN = 0;
LCD_RW = 0;
}
}
// Time delay for 2 x 20 LCD module (approximately 50ms)
void LCD_Delay()
{
uint8_t i, j ;
for (i=0;i!=100;i++)
{
for (j=0;j!=153;j++);
}
}
µVisionはKeil, An ARM Companyの登録商標です。
WindowsはMicrosoft Corp.の登録商標です。