0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PICAXE(ピカクス)のポート設定

Last updated at Posted at 2024-01-20

はじめに

PICAXEのIN/OUT機能を使用してLEDを点灯させたいとプログラムを作ったがコマンド送っているのに点灯しない事がありました。IN/OUTについて詳しい使い方の説明が少ないと感じましたのでまとめてみました。

結論

dirsコマンドを使用して使用するポートを IN で使うのか、OUTで使うかをあらかじめ宣言する。PICAXEによってINまたはOUTポートとして使用できないポートがあるので確認する。

PICAXEのピンアサインを表にしてみました

●PDFのマニュアルから
https://picaxe.com/docs/picaxe_manual1.pdf 
pin番号とPin Nameとpin番号に対する機能表を作ってみました。
(どのpinがInが無いのかを見たかったのもあります)

●入出力ポートを使用する時のお約束
入力で使用するか出力で使用するかをdirsコマンドで宣言する。
PICAXE-08M2は、dirsコマンド
PICAXE-14M2/18M2/20M2 は、dirsB,dirsCコマンド
出力ポート、入力ポートに割り当てができないポートがあります。
PICAXE-08M2は、C.3とC.5はinのみ。C.0はoutのみ。
PICAXE-14M2は、C.3とC.5はinのみ。C.0はoutのみ。
PICAXE-18M2は、C.4,C.5はinのみ。C.3はoutのみ。
PICAXE-20M2は、C.6はinのみ。

※サンプル
init:
      dirsB = %00001111 ' 下位4bitは出力、上位4bitは入力
main:
      portB = %00001010 ' 下位4bit に1010を出力
      b0 = portB               ' portBを読み込み、b0レジスタに格納する。
loop main

PICAXE-08M2

Pin Name PICAXE-08M2
pin番号
Pin Name
V+ 1 8 0V
C.5 2 7 C.0
C.4 3 6 C.1
C.3 4 5 C.2

pin Label 1 2 3 4 5 6 7 8
1 V+ - - - - - - - -
2 C.5 In - - Serial In - - - -
3 C.4 In Out ADC Touch - - - -
4 C.3 In - - - - - - -
5 C.2 In Out ADC Touch pwm tune SRQ hi2c sda
6 C.1 In Out ADC Touch hserin - SRI hi2c scl
7 C.0 - Out DAC Serial Out hserout - - -
8 0V - - - - - - - -

I/O用のコマンド

■ポートのin/outを設定します
pinsを使用する前にdirsでin/outの方向を設定します。
dirs = the data direction register (sets whether pins are inputs or outputs)

※サンプル
dirs = %00000111 ' dirs = 0x07  C.0〜C.2は out その他は in の設定。

08M2dirs.png
濃灰色は出力設定、薄灰色は入力設定になっていることがイメージでわかります。
薄灰色のピンはマウスでクリックするとON/OFFの入力ができます。

■pins ポートをbyte単位で出力と読み込みができます
pins = the input / output port   
※サンプル
C.3とC.5はOutに割り当てできないので、それ以外のポートはON/OFFを繰り返します。
上位の2bitはポートが無いため無視されます。

pins = %01010101 ' pins = 0x55
pins = %10101010 ' pins = 0xaa

b0 = pins ' portをbyte端子で読み込み、b0レジスタに代入します。

■low , high ポートを1ポート単位で制御します

※サンプル
high C.0 , C.2 ' C.0 と C.2ポートを HIGH に設定します(カンマで区切れば複数のポートをON可能)
low C.2        ' C.2 を LOW に設定します。

PICAXE-14M2

Pin Name PICAXE-14M2
pin番号
Pin Name
V+ 1 14 0V
C.5 2 13 B.0
C.4 3 12 B.1
C.3 4 11 B.2
C.2 5 10 B.3
C.1 6 9 B.4
C.0 7 8 B.5

pin Label 1 2 3 4 5 6 7 8
1 V+
2 C.5 In - Serial In - - - -
3 C.4 In Out ADC Touch - - - -
4 C.3 In - - - - - - -
5 C.2 In Out - - pwm hpwmA kb clk -
6 C.1 In Out - - - hpwmB kb data -
7 C.0 In Out ADC Touch pwm hpwmC - -
8 B.5 In Out ADC Touch - hpwmD - -
9 B.4 In Out ADC Touch pwm hi2c sda - -
10 B.3 In Out ADC Touch - hi2c scl - -
11 B.2 In Out ADC Touch pwm SRQ - -
12 B.1 In Out ADC Touch - SRI hserin -
13 B.0 - Out DAC Serial Out - - hserout -
14 0V - - - - - - - -

I/O用のコマンド

■ポートのin/outを設定します
pinsB、pinsC、outpinsB、outpinsC を使用する前にdirsB、dirsCでin/outの方向を設定します。
dirsB - the portB data direction register
dirsC - the portC data direction register

※サンプル
dirsB = %01010101 ' dirsB = 0x55 B.0,B.2,B.4を out その他は in。
dirsC = %00000111 ' dirsC = 0x07 C.0,C.1,C.2を out その他は in。

14M2dirs.png
濃灰色は出力設定、薄灰色は入力設定になっていることがイメージでわかります。
薄灰色のピンはマウスでクリックするとON/OFFの入力ができます。

■pinsB,pinsC ポートをbyte単位で出力と読み込みができます
pinsB - the portB input pins
pinsC - the portC input pins
※サンプル
C.3とC.5はOutに割り当てできないので、それ以外のポートはON/OFFを繰り返します。
上位の2bitはポートが無いため無視されます。

pinsC = %01010101 ' pins = 0x55
pinsC = %10101010 ' pins = 0xaa

b0 = pinsB ' portBをbyte端子で読み込み、b0レジスタに代入します。

■outpinsB,outpinsC ポートをbyte単位で出力します
outpinsB - the portB output pins
outpinsC - the portC output pins

PICAXE-18M2

Pin Name PICAXE-18M2
pin番号
Pin Name
C.2 1 18 C.1
C.3 2 17 C.0
C.4 3 16 C.7
C.5 4 15 C.6
0V 5 14 +V
B.0 6 13 B.7
B.1 7 12 B.6
B.2 8 11 B.5
B.3 9 10 B.4

pin Label 1 2 3 4 5 6 7 8
1 C.2 In Out ADC Touch DAC - - -
2 C.3 - Out - Serial Out - SRQ - -
3 C.4 In - - Serial In - - - -
4 C.5 In - - - - - - -
5 0V - - - - - - - -
6 B.0 In Out - - - SRI - -
7 B.1 In Out ADC Touch - i2c sda - -
8 B.2 In Out ADC Touch - - hserin -
9 B.3 In Out ADC Touch pwm - - -
10 B.4 In Out ADC Touch - i2c scl - -
11 B.5 In Out ADC Touch - - hserout -
12 B.6 In Out ADC Touch pwm - - -
13 B.7 In Out ADC Touch - - - -
14 +V - - - - - - - -
15 C.6 In Out - - - kb clock - -
16 C.7 In Out - - - kb data - -
17 C.0 In Out ADC Touch - - - -
18 C.1 In Out ADC Touch - - - -

PICAXE-20M2

Pin Name PICAXE-20M2
pin番号
Pin Name
+V 1 20 0V
Serial In 2 19 Serial Out
C.7 3 18 B.0
C.6 4 17 B.1
C.5 5 16 B.2
C.4 6 15 B.3
C.3 7 14 B.4
C.2 8 13 B.5
C.1 9 12 B.6
C.0 10 11 B.7

pin Pin Name 1 2 3 4 5 6 7 8
1 +V - - - - - - - -
2 - - - - Serial In - - - -
3 C.7 In Out ADC Touch - - - -
4 C.6 In - - - - - - -
5 C.5 In Out - - pwm hpwmA - -
6 C.4 In Out - - - hpwmB - -
7 C.3 In Out ADC Touch pwm hpwmC - -
8 C.2 In Out ADC Touch pwm - kb clk -
9 C.1 In Out ADC Touch - - kb data -
10 C.0 In Out - - - - hserout -
11 B.7 In Out - - - - hi2c scl -
12 B.6 In Out ADC Touch - - hserin -
13 B.5 In Out ADC Touch - - hi2c sda -
14 B.4 In Out ADC Touch - hpwmD - -
15 B.3 In Out ADC touch - - - -
16 B.2 In Out ADC Touch - - - -
17 B.1 In Out ADC Touch pwm SRQ - -
18 B.0 In Out ADC Touch - SRI - -
19 - - - - Serial Out - - - -
20 0V - - - - - - - -

PICAXE関連の投稿

PICAXE(ピカクス)でLチカ
https://qiita.com/masashi_214/items/5495503bf6bd82c1980b
PICAXE 最初に調べた事
https://qiita.com/masashi_214/items/d1acb1ecdc32de5a1698
PICAXEで鉄道模型の在線検出と信号機の制御
https://qiita.com/masashi_214/items/c728814df4f7a2453112
PICAXE(ピカクス)のポート設定
https://qiita.com/masashi_214/items/e5d5e1b9817aed754f52
PICAXE(ピカクス) リンク集
https://qiita.com/masashi_214/items/8b630b2c60ddb466b1ac
PICAXE(ピカクス)のpwm設定
https://qiita.com/masashi_214/items/f92e52837a9fa902879f
PICAXEでPWMを使用した調光機能を使って蛍を作る
https://qiita.com/masashi_214/items/0231a75ae0c77c2be206

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?