体重と今日食べたもの

k1segawa.exblog.jp

ダイエット

ブログトップ

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

(2016/9/1修正)
前記事の、ソースを修正して容量削減。コンパイルスイッチ追加。

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

$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
Declare Sub G_i2cwrite(byval D As Byte)
Dim A As String * 10 , I As Integer , Cmd As Byte , W As Byte
'--- Read EEPROM String ---
Const Eep = 0
'--- 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
I = 0
Do
'--- Read EEPROM ---
Readeeprom Cmd , I
'--- Output Command ---
Call G_i2cwrite(cmd)
If Cmd = &H6C Then Waitms 200
Incr I
Loop Until I = 8
'--- Clear Display Command ---
Call G_i2cwrite(ins_cleardsp)
#if Eep = 1
'--- Read EEPROM ---
Readeeprom A , 8
I2csend &H7C , A , 8
#else
'--- Output Data (String) ---
A = "@Hello"
I2csend &H7C , A , 6
#endif
'--- Output DDRAM Address ---
W = Ins_setddradr Or &H42
Call G_i2cwrite(w)
'--- Output Data (String) ---
A = "@World"
I2csend &H7C , A , 6
'--- Rotate number ---
I = &H30
Do
W = Ins_setddradr Or &H40
Call G_i2cwrite(w)
A = "@" + Chr(i)
I2csend &H7C , A , 2 : Waitms 300
Incr I
If I > &H39 Then I = &H30
Loop
End
'--- Sub routine : Output Command ---
Sub G_i2cwrite(byval D As Byte)
I2cstart
I2cwbyte &H7C
I2cwbyte &H80 (2016/9/1修正 0→&H80)
I2cwbyte D
I2cstop
Waitms 2
End Sub
'=== ATtiny13 EEPROM=64byte, rewrite 100,000 ===
$eeprom
'--- LCD Init Squence ---
Data &H38 , &H39 , &H14 , &H70 , &H52
Data &H6C , &H38 , &H0C
#if Eep = 1
'--- String ---
Data "@Welcome"
#endif
$data
' History
' [2016/09/01]
' For Next -> Do Loop Until
' #if Eep = 1 #endif append
' Readeeprom Wt, W -> If Cmd = &H6C Then
' I = 0 -> W = &H30 , I Mod 10 -> If I > &H39 Then
' Sub G_i2cwrite() : Waitms 2 append
' $eeprom : wait Data delete
' [2016/08/31]
' clock 9.6MHz
' $hwstack 32->24
' W As Integer -> Byte
' Mult Statement
' LCD Init Squence
' Power &H56(3.3V) -> &H52(5V)
' Follwer confrol wait=201ms
' remove Clear Display
ForループよりDo Untilの方が4バイト少ない。Until I > 8 より Until I = 8の方が2バイト少ない。Mod算術子よりIf文の方が数十バイト少ない。最終的に722バイト。まあ数字をぐるぐる回す処理はお遊びなので大して必要性は無い。
[PR]
by k1segawa | 2016-09-01 00:51 | arduino, AVR | Comments(0)