Twitter Follow Me

“This is just a random piece of text which can be replaced by a welcome message.

2009年9月20日日曜日

MPLABについて

Published by Unknown at 22:50



『目次』
・インストールする
・MPLABについてざっと
・アセンブルする
・シュミレートする


■インストールする



MPLABインストール手順

インストール中に違うのがインストールされそうになったので調べてみたら、そのままインストールしてOK
”Hitech PICC LiteがバンドルされているバージョンのMPLABであれば、インストールが始まります。OKをクリックしてインストールを行います。”



■MPLABについてざっと



MPLAB Integrated Development Environment
本家サイト MPLABのソフトがある

MPLAB - Wikipedia
MPLABとは
”主な内部構成
  • エディタ
ソースファイルを書くためのエディタ。
  • アセンブラ(MPASM)
書いたソースファイルをアセンブルしてオブジェクトファイルとアセンブルリストを生成する。
  • シミュレータ(MPSIM)
プログラムをデバッグするためのシミュレータ。パソコンでPICの動作をシミュレーションする。

MPLABにさわる
”特にまごつく点として

1.Projectというモノ

  会社や役所で何かというと作りたがるあのプロジェクトと同じようなモンみたいですかね。プログラム一括管理するらしいです。
  とりあえずこれから始まると思えばいいらしいです。***.pjt というファイル名にします。


2.フォルダ

  pjt も含めソースや生成したファイルをぶち込んでおくフォルダをあらかじめ用意しておきます。
  projectというフォルダを作りました。
  ファイルには他に自分で作るソースファイル(.asm)、生成したHEXファイル(.hex)、エラーファイル(.err)、リストファイル(.lst),
  シンボル・デバッグファイル(.cod)などがあるようです。
  生成ファイルは勝手にできちゃうからまあほっておいていいんですけど。


3.初期設定

  まず何はともあれ開発モード環境設定。
  [Option -> DevelopmentMode]
     [ Tool]設定で [MPLAB-SIM Simulator] をチェック
              [Processor]でPIC16F84選択。
     [Clock] で所定の20MHz設定。
  次に プロジェクト作製環境設定。
  [Project -> EditProject]
     Hexファイルを選んでから [Nodeproject] でHexFormatをINHX8M にチェック。
     他にデフォルトから変更したい項目にチェックを入れます。
     Default radix の設定はよく覚えておかないとプログラム書くときに10進数、16進数の混乱をします。”





■アセンブルする


MPLABの使い方 (ver.6.60) - プログラムのアセンブル
”画像付で詳しく解説してある”

アセンブル
”エラー処理の仕方”

●注)アセンブルできなかったのはなぜ?

1.本『わかるPICマイコン制御』のコードでアセンブルを実行すると 多数のエラーに

【コード】
;***p6_2.asm***
;8個のLEDを1個おきに、互い違いに点灯させる

include 16f84.h
.osc hs
.wdt off
org 0ch
tim0 ds 1
tim1 ds 1      ;tim1tim2を変数として使うことを宣言する
tim2 ds 1
org 0
goto start

start       ;ここからプログラムがスタートする
clr rb       ;ポートBをクリア
mov !rb,#0   ;ポートBを全ビット出力用に設定する

main
mov w,#01010101b ;wに「01010101」を代入
mov rb,w        ;ポートBにwの値「01010101」を出力
call wait         ;サブルーチンの「wait」を呼び出す
mov w,#10101010b
mov rb,w
call wait   
goto main       ;7桁上の「main」に行く

wait
mov tim0,#10      ;「時間待ち」のサブルーチン
wa0 clr tim1     ;tim1=0,「mov tim1,#0」と同じ
wa1 clr tim2      ;tim2=0,「mov tim2,#0」と同じ
wa2 nop       ;nop:何もしない
djnz tim2,wa2      ;tim2-1が0でなければwa1へ
djnz tim1,wa1      ;tim1-1が0でなければwa0へ
djnz tim0,wa0      ;tim0-1=0まで10回繰り返す
ret           ;サブルーチンを終わって元の場所へ

【これまでの実行結果エラーと対策】

エラーその1
Cannot open file (Include File "16f84.h" not found)

対策
同フォルダ内に 16f84.h(秋月PICプログラマー付属CDに入ってた)ファイルを入れ
MPLABで「Header Files」にAdd Filesした


【実行結果】

----------------------------------------------------------------------
Debug build of project `C:\PIC\test2.mcp' started.
Language tool versions: MPASMWIN.exe v5.33, mplink.exe v4.33
Preprocessor symbol `__DEBUG' is defined.
Mon Sep 21 18:14:10 2009
----------------------------------------------------------------------
Make: The target "C:\PIC\SAMPLE.o" is up to date.
Make: The target "C:\PIC\p6_2.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F84 "p6_2.asm" /l"p6_2.lst" /e"p6_2.err" /o"p6_2.o" /d__DEBUG=1
Warning[207] C:\PIC\16F84.H 1 : Found label after column 1. (.nlist)
Error[150] C:\PIC\16F84.H 1 : Labels must be defined in a code or data section when making an object file
Warning[207] C:\PIC\16F84.H 8 : Found label after column 1. (.16f84)
Error[150] C:\PIC\16F84.H 8 : Labels must be defined in a code or data section when making an object file
Warning[203] C:\PIC\16F84.H 13 : Found opcode in column 1. (option)
Warning[211] C:\PIC\16F84.H 13 : Extraneous arguments on the line.
Warning[224] C:\PIC\16F84.H 13 : Use of this instruction is not recommended.
Error[152] C:\PIC\16F84.H 13 : Executable code and data must be defined in an appropriate section
Error[112] C:\PIC\16F84.H 15 : Missing operator
Error[112] C:\PIC\16F84.H 16 : Missing operator
Error[112] C:\PIC\16F84.H 17 : Missing operator
Error[112] C:\PIC\16F84.H 18 : Missing operator
Error[112] C:\PIC\16F84.H 19 : Missing operator
Error[112] C:\PIC\16F84.H 20 : Missing operator
Error[112] C:\PIC\16F84.H 21 : Missing operator
Error[112] C:\PIC\16F84.H 22 : Missing operator
Error[112] C:\PIC\16F84.H 28 : Missing operator
Error[112] C:\PIC\16F84.H 29 : Missing operator
Error[112] C:\PIC\16F84.H 30 : Missing operator
Error[112] C:\PIC\16F84.H 31 : Missing operator
Error[112] C:\PIC\16F84.H 32 : Missing operator
Error[112] C:\PIC\16F84.H 33 : Missing operator
Error[112] C:\PIC\16F84.H 34 : Missing operator
Error[112] C:\PIC\16F84.H 35 : Missing operator
Error[112] C:\PIC\16F84.H 49 : Missing operator
Error[112] C:\PIC\16F84.H 50 : Missing operator
Error[112] C:\PIC\16F84.H 51 : Missing operator
Error[112] C:\PIC\16F84.H 52 : Missing operator
Error[112] C:\PIC\16F84.H 53 : Missing operator
Error[112] C:\PIC\16F84.H 54 : Missing operator
Error[112] C:\PIC\16F84.H 55 : Missing operator
Error[112] C:\PIC\16F84.H 56 : Missing operator
Error[112] C:\PIC\16F84.H 59 : Missing operator
Error[112] C:\PIC\16F84.H 60 : Missing operator
Error[112] C:\PIC\16F84.H 61 : Missing operator
Error[112] C:\PIC\16F84.H 62 : Missing operator
Error[112] C:\PIC\16F84.H 63 : Missing operator
Warning[207] C:\PIC\16F84.H 66 : Found label after column 1. (.list)
Error[150] C:\PIC\16F84.H 66 : Labels must be defined in a code or data section when making an object file
Warning[207] C:\PIC\P6_2.ASM 5 : Found label after column 1. (.osc)
Error[122] C:\PIC\P6_2.ASM 5 : Illegal opcode (hs)
Warning[207] C:\PIC\P6_2.ASM 6 : Found label after column 1. (.wdt)
Error[122] C:\PIC\P6_2.ASM 6 : Illegal opcode (off)
Error[122] C:\PIC\P6_2.ASM 8 : Illegal opcode (ds)
Error[122] C:\PIC\P6_2.ASM 9 : Illegal opcode (ds)
Error[122] C:\PIC\P6_2.ASM 10 : Illegal opcode (ds)
Warning[207] C:\PIC\P6_2.ASM 15 : Found label after column 1. (clr)
Error[122] C:\PIC\P6_2.ASM 15 : Illegal opcode (rb)
Warning[207] C:\PIC\P6_2.ASM 16 : Found label after column 1. (mov)
Error[108] C:\PIC\P6_2.ASM 16 : Illegal character (!)
Warning[207] C:\PIC\P6_2.ASM 19 : Found label after column 1. (mov)
Error[122] C:\PIC\P6_2.ASM 19 : Illegal opcode (w)
Warning[207] C:\PIC\P6_2.ASM 20 : Found label after column 1. (mov)
Error[122] C:\PIC\P6_2.ASM 20 : Illegal opcode (rb)
Warning[207] C:\PIC\P6_2.ASM 22 : Found label after column 1. (mov)
Error[122] C:\PIC\P6_2.ASM 22 : Illegal opcode (w)
Warning[207] C:\PIC\P6_2.ASM 23 : Found label after column 1. (mov)
Error[122] C:\PIC\P6_2.ASM 23 : Illegal opcode (rb)
Warning[207] C:\PIC\P6_2.ASM 28 : Found label after column 1. (mov)
Error[122] C:\PIC\P6_2.ASM 28 : Illegal opcode (tim0)
Error[122] C:\PIC\P6_2.ASM 29 : Illegal opcode (clr)
Error[122] C:\PIC\P6_2.ASM 30 : Illegal opcode (clr)
Warning[207] C:\PIC\P6_2.ASM 32 : Found label after column 1. (djnz)
Error[122] C:\PIC\P6_2.ASM 32 : Illegal opcode (tim2)
Warning[207] C:\PIC\P6_2.ASM 33 : Found label after column 1. (djnz)
Error[122] C:\PIC\P6_2.ASM 33 : Illegal opcode (tim1)
Warning[207] C:\PIC\P6_2.ASM 34 : Found label after column 1. (djnz)
Error[122] C:\PIC\P6_2.ASM 34 : Illegal opcode (tim0)
Warning[207] C:\PIC\P6_2.ASM 35 : Found label after column 1. (ret)
Error[129] C:\PIC\P6_2.ASM 37 : Expected (END)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\PIC\test2.mcp' failed.
Language tool versions: MPASMWIN.exe v5.33, mplink.exe v4.33
Preprocessor symbol `__DEBUG' is defined.
Mon Sep 21 18:14:11 2009
----------------------------------------------------------------------
BUILD FAILED




2.MPLABを使って見よう!
のサンプルプログラム(sample.asm)を使用したら
アセンブル可能だった

【コード】

;*******************************************************************
; SAMPLE.ASM
; 8x8 Software Multiplier for 16Cxxx Family
;*******************************************************************
;
; The 16 bit result is stored in 2 bytes
;
; Before calling the subroutine " mpy ", the multiplier should
; be loaded in location " mulplr ", and the multiplicand in
; " mulcnd " . The 16 bit result is stored in locations
; H_byte & L_byte.
;
;*******************************************************************
;
LIST p=16F84 ; PIC16F844 is the target processor

#include "P16F84.INC" ; Include header file

cblock 0x10 ; Temporary storage
mulcnd ; 8 bit multiplicand
mulplr ; 8 bit multiplier, this register will be set to zero after multiply
H_byte ; High byte of the 16 bit result
L_byte ; Low byte of the 16 bit result
count ; loop counter
endc
;
org 0

goto start
;
; ***************************** Begin Multiplier Routine
mpy_S clrf H_byte
clrf L_byte
movlw 8
movwf count
movf mulcnd,w
bcf STATUS,C ; Clear the carry bit in the status Reg.
loop rrf mulplr,F
btfsc STATUS,C
addwf H_byte,F
rrf H_byte,F
rrf L_byte,F
decfsz count,F
goto loop
;
retlw 0
;
;********************************************************************
; Test Program
;*********************************************************************
start clrw

main movlw 0x35
movwf mulplr ; test 0x35 times 0x2D
movlw 0x2D
movwf mulcnd
;
call_m call mpy_S ; The result is in file registers
; H_byte & L_byte and should equal 0x0951
;
goto main
;
;
END


【実行結果】
----------------------------------------------------------------------
Debug build of project `C:\PIC\test2.mcp' started.
Language tool versions: MPASMWIN.exe v5.33, mplink.exe v4.33
Preprocessor symbol `__DEBUG' is defined.
Mon Sep 21 17:45:23 2009
----------------------------------------------------------------------
Make: The target "C:\PIC\SAMPLE.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F84 "SAMPLE.ASM" /l"SAMPLE.lst" /e"SAMPLE.err" /d__DEBUG=1
Make: The target "C:\PIC\SAMPLE.cof" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" /p16F84 "SAMPLE.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"SAMPLE.cof" /M"SAMPLE.map" /W /x
MPLINK 4.33, Linker
Copyright (c) 2009 Microchip Technology Inc.
Errors : 0

Loaded C:\PIC\SAMPLE.cof.
----------------------------------------------------------------------
Debug build of project `C:\PIC\test2.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.33, mplink.exe v4.33
Preprocessor symbol `__DEBUG' is defined.
Mon Sep 21 17:45:26 2009
----------------------------------------------------------------------
BUILD SUCCEEDED



3-a.仮説)文法が違うかもしれない
□アセンブルの文法を調べてみる

3-b.仮説)インクルード がおかしい



■シュミレートの仕方


MPLab with HI TECHC Liteの使用方法
”シュミレートの仕方”



■参考


電子工作室
”MPLABについて一通りがある”

MPLABにさわる
”実体験がわかる”

オレンジ電子工作 MPLAB SIM の使い方
”同期、非同期など時間から見た内容”

0 コメント:

コメントを投稿