Twitter Follow Me

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

ラベル PIC の投稿を表示しています。 すべての投稿を表示
ラベル PIC の投稿を表示しています。 すべての投稿を表示

2009年9月21日月曜日

アセンブルについて

Published by Unknown at 18:21

ele-アセンブル-1
ele-アセンブル-1

■インクルード(アセンブルのための予備知識)



インクルードとは 【include】 - 意味/解説/説明/定義 : IT用語辞典
ソースファイルの先頭などで、別のソースファイルなどを読み込んで一つにまとめてくれる言語処理系の機能のこと
 C言語の場合はコンパイルの前にプリプロセッサがインクルード処理をしてくれる。スクリプト言語などは実行時に実行環境が処理してくれる場合が多い


アセンブラプログラミング
.INCLUDE・・・はアセンブル際に読み込むファイルを
それぞれ指定しています。
これらの命令は、アセンブラがソースファイルをアセンブルする際に
アセンブラに必要な情報を与える為に使われます。


■コンパイルについて(アセンブルのための予備知識)


コンパイルとは 【compile】 - 意味/解説/説明/定義 : IT用語辞典
人間がプログラミング言語を用いて作成したソフトウェアの設計図(ソースコード)を、コンピュータ上で実行可能な形式(オブジェクトコード)に変換すること。
変換のみを一括して行い、生成したオブジェクトコードの実行は行わない。


■プリプロセッサについて(アセンブルのための予備知識)


プリプロセッサとは 【preprocessor】 - 意味/解説/説明/定義 : IT用語辞典
ソフトウェア開発ツールの一つ。
ソースコードに一定の規則に従って処理を加える
C言語のソースコードでは#から始まる行がプリプロセッサへの指示となり、
別ファイルから取り込みを行なう「#include」や、
シンボルの置換やマクロの展開を行なう「#define」などが使える

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 の使い方
”同期、非同期など時間から見た内容”

2009年9月13日日曜日

PICとLEDについて

Published by Unknown at 0:52

【目的】


LEDを順次に点滅させる

in-out動作)
in:スイッチを押す
out:LEDが順次に点滅しだす

【準備】


1.情報収集:
本「わかるPICマイコン制御」

2.ROM)
 チャート
 プログラム書く
 マイコンに書き込み

3.ハード
  回路図
  電子パーツ
  ハンダする

2009年9月12日土曜日

マイコン(PIC)環境について

Published by Unknown at 22:22




■準備の仕方(パックを作る)



構成が複雑なので
準備しやすいようにパックを作る

入れる物】
□テンプレ (ひと目で準備できてるかどうか分かるチェックシート)
□資料 (ハードの説明、コードの説明)
□PIC (プログラムを書き込むIC)
□回路ボード、ハード (プログラムを動作させる装置)

■テンプレート


今現在どの段階まで進んでいるのか知るために
また、次何をやるか把握するために
テンプレートを作ることにします

【目的】
in-out動作

【準備】

□ROM
 チャート
 プログラム書く
 マイコンに書き込み

□ハード
  回路図
  電子パーツ
  ハンダする


*(チェックシートにする)


日付
済/未


具体例
-make: PICとLEDについて





■vistaで秋月PICプログラマーを使うには



USB・シリアル変換ケーブル: 電子工作便利商品 秋月電子通商 電子部品 ネット通販
USB接続で秋月PICプログラマーを使用する

また、
VISTA用ドライバーは同ページ内にある
秋月PICプログラマー(ver3.5)で動作した
(comポート4使用し、arduinoはcomポート3を使用していた)

■vistaでアセンブルするには


-make: MPLABについて

■参考


サイト)
PICで遊ぶ電子工作
”基礎、具体例が詳しく書いてある入門に”

PICな日曜日

電子工作の実験室

PICマイコンを楽しむ電子工作

PICを使用した電子回路集

本)
わかるPICマイコン制御―16F84プログラミングの世界へ
PICマイコンとその活用法
キットの組み立て
パソコンでの準備
プログラミングの第一歩
実験用ボードの製作
プログラミングに慣れる
プログラムで数値を扱う
プログラムにデータを書き込む
入力待ちのプログラム
電子工作に向けて
電子工作の実際とヒント
ちょっと進んだ話
実験用ねずみロボット


わかるPICマイコン製作集―16F84プログラミングの世界へ
第1章 PICマイコンの概要とその活用法―PICマイコンの基礎と扱い方
第2章 フィーバー電飾―ゲームの興奮度倍増!
第3章 踊るてんとう虫―落ちず・当たらず!動き回る
第4章 ライントレーサ―交差点やT字路、行き止まりにも対応!
第5章 メトロノーム―音と光でテンポはOK!
第6章 スロットマシン―損をしないで気軽に楽しめる
第7章 メロディクリエータ―奇跡を信じて名曲を!
第8章 おしゃべり小僧―センサが反応してしゃべる

■関連
各種 PIC プログラマー - ロボットのいる生活。

2009年9月7日月曜日

PICとPCの通信

Published by Unknown at 2:30

■アウトライン
0.【目的】

入力:

出力:


1.【要素】
pic
pc
シリアル通信


2.【仕組み】

□picとD-subと仲介の電子機器の役割は


3.【場合わけ】


4.【組み合わせ】


5.【準備】


6.【実験】

■参考
浅草ギ研 PICとPCとの通信(デバックモニタ)
”PICのチップから回路を作る場合はPCとの通信回路を自分で作らなければなりません。”
”PICで計算した結果をPCに表示するまでを説明します。”


PIC-パソコン間シリアル通信 PIC送信テスト(その1)

パソコンとPICの通信(USART) - PICとMikroC

シリアル通信接続端末
”IC16F84と液晶表示器を組み合わせた端末で
  パソコンとはRS232Cのシリアル通信で接続
  300bps~9600bpsの通信速度で送受信が可能”

16F877で遊ぶ

PIC16F648Aのシリアル通信機能

シリアルポートで通信してみよう

シリアル回線モニタ