体重と今日食べたもの

k1segawa.exblog.jp

ダイエット

ブログトップ

Japanino ArduinoISPで ATtiny13 で I2C 液晶(6) - コマンド発行 (5) (9/2)

この液晶で一番面白いコマンドを発行してみた。
CGRAMの定義だ。
こちらのサイト様を参考に。
電気の迷宮 PICAXEでLCDモジュールに任意キャラクタを表示する(CGRAM) 1

ソース:
'****************************************
' Copyright (c) 2016 k1segawa
' License : free
' Program : CGRAM Control
'****************************************

$regfile = "attiny13.dat"
$crystal = 9600000
$hwstack = 24
$swstack = 4
$framesize = 8
Config Scl = Portb. 1
Config Sda = Portb. 0
Config I2cdelay = 5
Config Clockdiv = 1
Dim A As String * 10 , I As Integer , W As Byte
'--- Instruction Description Command ---
Const Ins_cleardsp = &H01
Const Ins_returnhm = &H02
Const Ins_entrymd = &H04
Const Ins_dsponoff = &H08
Const Ins_curdspsft = &H10
Const Ins_funcset = &H20
Const Ins_setcgram = &H40
Const Ins_setddradr = &H80
'--- Instruction table 1 Command (IS=1) ---
Const Ins_intoscfreq = &H10
Const Ins_seticonadr = &H40
Const Ins_powericonctrst = &H50
Const Ins_flwctrl = &H60
Const Ins_contrstset = &H70
'--- I2C Init ---
I2cinit
'--- LCD Init ---
Waitms 40
I2cstart
I2cwbyte &H7C
I2cwbyte 0
I2cwbyte &H38
I2cwbyte &H39
I2cwbyte &H14
I2cwbyte &H70
I2cwbyte &H52 '56->52
I2cwbyte &H6C
Waitms 201
I2cwbyte &H38
I2cwbyte &H0C
I2cstop
W = 1 : Gosub G_i2cwrite
Waitms 2
'--- Set CGRAM No.0 Charactor Data ---
W = Ins_seticonadr Or &H00 : Gosub G_i2cwrite
I2cstart
I2cwbyte &H7C
I2cwbyte &H40
I2cwbyte &B00000
I2cwbyte &B00000
I2cwbyte &B00000
I2cwbyte &B00000
I2cwbyte &B00011
I2cwbyte &B00101
I2cwbyte &B01001
I2cwbyte &B10001
I2cstop
'--- Set DDRAM Address ---
'W = Ins_returnhm : Gosub G_i2cwrite
W = Ins_setddradr : Gosub G_i2cwrite
'--- Output Display 1-line=8Char Full by CG Char No.0 ---
I2cstart
I2cwbyte &H7C
I2cwbyte &H40
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cstop
'--- Output Display 2-line=8Char Full by CG Char No.0 ---
W = Ins_setddradr Or &H40 : Gosub G_i2cwrite
I2cstart
I2cwbyte &H7C
I2cwbyte &H40
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cwbyte &H00
I2cstop
'--- Anime : CGRAM Char No.0 Data Change ---
I = 0
Do
Waitms 200
W = Ins_seticonadr Or &H00 : Gosub G_i2cwrite
I2cstart
I2cwbyte &H7C
I2cwbyte &H40
I2cwbyte &B00000
I2cwbyte &B00000
I2cwbyte &B00000
I2cwbyte &B00000

If I = 0 Then
I2cwbyte &B00011
I2cwbyte &B00101
I2cwbyte &B01001
I2cwbyte &B10001
Elseif I = 1 Then
I2cwbyte &B00001
I2cwbyte &B00010
I2cwbyte &B00100
I2cwbyte &B01000
Elseif I = 2 Then
I2cwbyte &B10000
I2cwbyte &B10001
I2cwbyte &B10010
I2cwbyte &B10100
Elseif I = 3 Then
I2cwbyte &B11000
I2cwbyte &B01000
I2cwbyte &B01001
I2cwbyte &B01010
Elseif I = 4 Then
I2cwbyte &B01100
I2cwbyte &B10100
I2cwbyte &B00100
I2cwbyte &B00101
Elseif I = 5 Then
I2cwbyte &B00110
I2cwbyte &B01010
I2cwbyte &B10010
I2cwbyte &B00010
End If
I2cstop

'W = Ins_returnhm : Gosub G_i2cwrite
W = Ins_setddradr : Gosub G_i2cwrite

Incr I
If I > 5 Then I = 0
Loop

End
'--- Sub routine : Output Command ---
G_i2cwrite:
I2cstart
I2cwbyte &H7C
I2cwbyte &H80
I2cwbyte W
I2cstop
Return
' History
' [2016/09/02]
' Set CGRAM Data & Display
Character No.0に三角のノコギリ波を画面いっぱいに表示し、それがパラパラ漫画のように動く。806バイト。長いデータは直接I2cwbyteで書いた方が短い。単独のコマンドの時だけGosubを使う。
([Set CGRAM Char No.n]->[Char Data])*N->[Set DDRAM]->[Output Display 1,2行目8桁全てCGRAM Char No.0で埋める]->[anime Loop] みたいな感じ(今回n=0,N=1でChar No.0しか使ってない)。
絵が描ければもうちょっと楽しいのだろうな。6キャラで波形やカッコいい文字を表示していた作品を見たことがある。

[PR]
by k1segawa | 2016-09-02 18:45 | arduino, AVR | Comments(0)