LoginSignup
0
0

PICAXE奮闘記03 I2CタイプのLCDでキャラクタ登録とカタカナ表示に挑戦

Posted at

今回は前回に引き続きLCD表示を深めます。
オリジナルキャラクタ登録とカタカナ表示ができるかやってみます。
マクロを取り入れて繰り返し記述の簡素化も取り入れました。

結果出来ました。パチパチ

'**************************************
'     I2C LCD test Display test 
'	AE-AQM1602A(KIT)
'     *3.1V to 3.5V!! Not use AA battry*3=4.5V
'     (I2C LCD 16 x 2 lines)
'	 for PICAXE 08M2
'**************************************
'	Information of Connection
'		pin1 VCC
'		pin2 serial in
'		pin3 analog in
'		pin4 n.c
'	----
'		pin8 GND
'		pin7 serial out
'		pin6 SCL(10kohm pull up by lcdkit)
'		pin5 SDA(10kohm pull up by lcdkit)
'**************************************
'04 液晶表示に成功
'05 キャラクター登録とカタカナ表示に挑戦


#PICAXE 08M2
#NO_DATA

#macro CaractorSet(Command,Byte0,Byte1,Byte2,Byte3,Byte4,Byte5,Byte6,Byte7)
	hi2cout ($00,Command)
	pause 50
	hi2cout ($40,Byte0,Byte1,Byte2,Byte3,Byte4,Byte5,Byte6,Byte7)
	pause 50
#endmacro

'I2C initialize
hi2csetup i2cmaster,$7C, i2cfast, i2cbyte 'AKIDUKI LCD
hi2cout ($00,$01)	'Clear display
pause 50
hi2cout ($00,$38)	'拡張コマンドOFF
pause 50		'Wait
hi2cout ($00,$0C)	'ディスプレイON カーソルOFF
pause 50		'Wait
hi2cout ($00,$06)	'エントリーモードセット
pause 300		'Wait
hi2cout ($00,$39)	'コントラスト設定を行うため拡張命令ON
pause 50		'Wait
symbol Contrast = 30	'0 - 32 - 63 $00 - $3f 液晶のコントラスト設定値
'定数同士の計算は予め計算されるため、プログラムサイズに影響無し。
symbol ContrastL1 = Contrast // 16
symbol ContrastL2 = ContrastL1 or $70
hi2cout 0,(ContrastL2)	'液晶コントラスト下位指定
pause 50
symbol ContrastH1 = Contrast / 16
symbol ContrastH2 = ContrastH1 or $54
hi2cout 0,(ContrastH2)	'液晶コントラスト上位指定
pause 50
hi2cout ($00,$6C)	'フォロワー制御設定
pause 50
hi2cout ($00,$38)	'拡張命令OFF
pause 50
hi2cout ($00,$01)	'Clear display
pause 50

'Command,Byte0,Byte1,Byte2,Byte3,Byte4,Byte5,Byte6,Byte7
'Command = Set CGRam Address $40,$48
CaractorSet($40,$00,$0A,$00,$04,$00,$11,$0E,$00)'キャラクタ0 スマイル
CaractorSet($48,$04,$0E,$0e,$0e,$1f,$00,$04,$00)'キャラクタ1 ベル

'Displaying Hello world
hi2cout ($00,$80)	'Set DDR Address
pause 50		'Wait
hi2cout ($40,"Volt デンアツ",$00,$01)

main:
	READADC10  C.4,w0
	'スケーリング $3ff(1023)が3500となるようにスケーリング
	let w0 = w0 * 16	'4bit shift(max $3ff0)
	'スケーリング後の値をhigh word で取得するので 3500($dac) が $dac00000 を $3ff0 で割ってスケーリング定数を得る。
	'1word(16bit) * 1word(16bit)=2word(32bit)
	'** 演算子は計算結果のhigh wordが帰ってくる。
	' $dac0000 = $3ff0 * x
	' x = $dac0000/$3ff0 = $36bd
	let w0 = w0 ** $36BD	'high word return
	'これで$3ffの時に$dac(3500)となる。正確には3499
	bintoascii w0,b6,b5,b4,b3,b2	' convert to ascii
	hi2cout ($00,$c5)	'Set DDR Address
	debug			' debug values for testing
	'最上位桁のゼロサプレス処理
	if b6 = "0" then
		b6 = " "
'		if b5 = "0" then
'			b5 = " "
'		endif
	endif
	hi2cout ($40,b6,b5,".",b4,b3,b2,"V")
	pause 200		'wait 0.2sec
	goto main
end

IMG_0143.JPG

スマイルとベルのマークはソフトから登録したものです。
カタカナはプログラム上にカタカナ記述するだけで表示出来ました。
IMG_0144.JPG

IMG_0145.JPG

SDA,SCLのプリアップ抵抗を有効にするため、2カ所はんだブリッジが必要です。

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