\ oled96.frt - управление OLED индикатором (96*96) на базе
\ драйвера SSD1327
\ 07.07.2012 ~ilya
\ #include twi.frt
marker =oled96=
$78 constant twi.oled96 \ device address on i2c bus
$80 constant OLED_Command_Mode
$40 constant OLED_Data_Mode
$a4 constant OLED_Normal_Display_Cmd
$a7 constant OLED_Inverse_Display_Cmd
$81 constant OLED_Set_ContrastLevel_Cmd
$ae constant OLED_Display_Off_Cmd
$af constant OLED_Display_On_Cmd
variable oled96col \ Текущий столбец
variable oled96row \ Текущая строка
variable grayH
variable grayL
create BasicFont
$00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 ,
$00 , $00 , $5F , $00 , $00 , $00 , $00 , $00 ,
$00 , $00 , $07 , $00 , $07 , $00 , $00 , $00 ,
$00 , $14 , $7F , $14 , $7F , $14 , $00 , $00 ,
$00 , $24 , $2A , $7F , $2A , $12 , $00 , $00 ,
$00 , $23 , $13 , $08 , $64 , $62 , $00 , $00 ,
$00 , $36 , $49 , $55 , $22 , $50 , $00 , $00 ,
$00 , $00 , $05 , $03 , $00 , $00 , $00 , $00 ,
$00 , $1C , $22 , $41 , $00 , $00 , $00 , $00 ,
$00 , $41 , $22 , $1C , $00 , $00 , $00 , $00 ,
$00 , $08 , $2A , $1C , $2A , $08 , $00 , $00 ,
$00 , $08 , $08 , $3E , $08 , $08 , $00 , $00 ,
$00 , $A0 , $60 , $00 , $00 , $00 , $00 , $00 ,
$00 , $08 , $08 , $08 , $08 , $08 , $00 , $00 ,
$00 , $60 , $60 , $00 , $00 , $00 , $00 , $00 ,
$00 , $20 , $10 , $08 , $04 , $02 , $00 , $00 ,
$00 , $3E , $51 , $49 , $45 , $3E , $00 , $00 ,
$00 , $00 , $42 , $7F , $40 , $00 , $00 , $00 ,
$00 , $62 , $51 , $49 , $49 , $46 , $00 , $00 ,
$00 , $22 , $41 , $49 , $49 , $36 , $00 , $00 ,
$00 , $18 , $14 , $12 , $7F , $10 , $00 , $00 ,
$00 , $27 , $45 , $45 , $45 , $39 , $00 , $00 ,
$00 , $3C , $4A , $49 , $49 , $30 , $00 , $00 ,
$00 , $01 , $71 , $09 , $05 , $03 , $00 , $00 ,
$00 , $36 , $49 , $49 , $49 , $36 , $00 , $00 ,
$00 , $06 , $49 , $49 , $29 , $1E , $00 , $00 ,
$00 , $00 , $36 , $36 , $00 , $00 , $00 , $00 ,
$00 , $00 , $AC , $6C , $00 , $00 , $00 , $00 ,
$00 , $08 , $14 , $22 , $41 , $00 , $00 , $00 ,
$00 , $14 , $14 , $14 , $14 , $14 , $00 , $00 ,
$00 , $41 , $22 , $14 , $08 , $00 , $00 , $00 ,
$00 , $02 , $01 , $51 , $09 , $06 , $00 , $00 ,
$00 , $32 , $49 , $79 , $41 , $3E , $00 , $00 ,
$00 , $7E , $09 , $09 , $09 , $7E , $00 , $00 ,
$00 , $7F , $49 , $49 , $49 , $36 , $00 , $00 ,
$00 , $3E , $41 , $41 , $41 , $22 , $00 , $00 ,
$00 , $7F , $41 , $41 , $22 , $1C , $00 , $00 ,
$00 , $7F , $49 , $49 , $49 , $41 , $00 , $00 ,
$00 , $7F , $09 , $09 , $09 , $01 , $00 , $00 ,
$00 , $3E , $41 , $41 , $51 , $72 , $00 , $00 ,
$00 , $7F , $08 , $08 , $08 , $7F , $00 , $00 ,
$00 , $41 , $7F , $41 , $00 , $00 , $00 , $00 ,
$00 , $20 , $40 , $41 , $3F , $01 , $00 , $00 ,
$00 , $7F , $08 , $14 , $22 , $41 , $00 , $00 ,
$00 , $7F , $40 , $40 , $40 , $40 , $00 , $00 ,
$00 , $7F , $02 , $0C , $02 , $7F , $00 , $00 ,
$00 , $7F , $04 , $08 , $10 , $7F , $00 , $00 ,
$00 , $3E , $41 , $41 , $41 , $3E , $00 , $00 ,
$00 , $7F , $09 , $09 , $09 , $06 , $00 , $00 ,
$00 , $3E , $41 , $51 , $21 , $5E , $00 , $00 ,
$00 , $7F , $09 , $19 , $29 , $46 , $00 , $00 ,
$00 , $26 , $49 , $49 , $49 , $32 , $00 , $00 ,
$00 , $01 , $01 , $7F , $01 , $01 , $00 , $00 ,
$00 , $3F , $40 , $40 , $40 , $3F , $00 , $00 ,
$00 , $1F , $20 , $40 , $20 , $1F , $00 , $00 ,
$00 , $3F , $40 , $38 , $40 , $3F , $00 , $00 ,
$00 , $63 , $14 , $08 , $14 , $63 , $00 , $00 ,
$00 , $03 , $04 , $78 , $04 , $03 , $00 , $00 ,
$00 , $61 , $51 , $49 , $45 , $43 , $00 , $00 ,
$00 , $7F , $41 , $41 , $00 , $00 , $00 , $00 ,
$00 , $02 , $04 , $08 , $10 , $20 , $00 , $00 ,
$00 , $41 , $41 , $7F , $00 , $00 , $00 , $00 ,
$00 , $04 , $02 , $01 , $02 , $04 , $00 , $00 ,
$00 , $80 , $80 , $80 , $80 , $80 , $00 , $00 ,
$00 , $01 , $02 , $04 , $00 , $00 , $00 , $00 ,
$00 , $20 , $54 , $54 , $54 , $78 , $00 , $00 ,
$00 , $7F , $48 , $44 , $44 , $38 , $00 , $00 ,
$00 , $38 , $44 , $44 , $28 , $00 , $00 , $00 ,
$00 , $38 , $44 , $44 , $48 , $7F , $00 , $00 ,
$00 , $38 , $54 , $54 , $54 , $18 , $00 , $00 ,
$00 , $08 , $7E , $09 , $02 , $00 , $00 , $00 ,
$00 , $18 , $A4 , $A4 , $A4 , $7C , $00 , $00 ,
$00 , $7F , $08 , $04 , $04 , $78 , $00 , $00 ,
$00 , $00 , $7D , $00 , $00 , $00 , $00 , $00 ,
$00 , $80 , $84 , $7D , $00 , $00 , $00 , $00 ,
$00 , $7F , $10 , $28 , $44 , $00 , $00 , $00 ,
$00 , $41 , $7F , $40 , $00 , $00 , $00 , $00 ,
$00 , $7C , $04 , $18 , $04 , $78 , $00 , $00 ,
$00 , $7C , $08 , $04 , $7C , $00 , $00 , $00 ,
$00 , $38 , $44 , $44 , $38 , $00 , $00 , $00 ,
$00 , $FC , $24 , $24 , $18 , $00 , $00 , $00 ,
$00 , $18 , $24 , $24 , $FC , $00 , $00 , $00 ,
$00 , $00 , $7C , $08 , $04 , $00 , $00 , $00 ,
$00 , $48 , $54 , $54 , $24 , $00 , $00 , $00 ,
$00 , $04 , $7F , $44 , $00 , $00 , $00 , $00 ,
$00 , $3C , $40 , $40 , $7C , $00 , $00 , $00 ,
$00 , $1C , $20 , $40 , $20 , $1C , $00 , $00 ,
$00 , $3C , $40 , $30 , $40 , $3C , $00 , $00 ,
$00 , $44 , $28 , $10 , $28 , $44 , $00 , $00 ,
$00 , $1C , $A0 , $A0 , $7C , $00 , $00 , $00 ,
$00 , $44 , $64 , $54 , $4C , $44 , $00 , $00 ,
$00 , $08 , $36 , $41 , $00 , $00 , $00 , $00 ,
$00 , $00 , $7F , $00 , $00 , $00 , $00 , $00 ,
$00 , $41 , $36 , $08 , $00 , $00 , $00 , $00 ,
$00 , $02 , $01 , $01 , $02 , $01 , $00 , $00 ,
$00 , $02 , $05 , $05 , $02 , $00 , $00 , $00 ,
: oled96.send ( d c -- )
twi.oled96
twi.start
twi.tx $18 twi.status?
twi.tx $28 twi.status?
twi.tx $28 twi.status?
twi.stop
;
\ Посылаем комманду
: oled96.sc ( c -- )
OLED_Command_Mode oled96.send
;
\ Посылаем данные
: oled96.sd ( c -- )
OLED_Data_Mode oled96.send
;
: oled96.init
$fd oled96.sc
$12 oled96.sc
$ae oled96.sc
$a8 oled96.sc
$5f oled96.sc
$a1 oled96.sc
$00 oled96.sc
$a2 oled96.sc
$60 oled96.sc
$a0 oled96.sc \ set remap
$46 oled96.sc
$ab oled96.sc
$01 oled96.sc
$81 oled96.sc
$53 oled96.sc
$b1 oled96.sc
$51 oled96.sc
$b3 oled96.sc
$01 oled96.sc
$b9 oled96.sc
$bc oled96.sc
$08 oled96.sc
$be oled96.sc
$07 oled96.sc
$b6 oled96.sc
$01 oled96.sc
$d5 oled96.sc
$62 oled96.sc
$a4 oled96.sc
$2e oled96.sc
$af oled96.sc
100 ms
$75 oled96.sc
$00 oled96.sc
$5f oled96.sc
$15 oled96.sc
$08 oled96.sc
$37 oled96.sc
$f0 grayH !
$0f grayL !
0 oled96col !
0 oled96row !
;
: oled96.rowaddr ( n -- )
\ Row Address
$75 oled96.sc
oled96.sc
$5f oled96.sc
;
: oled96.coladdr ( n -- )
\ Column Address
$15 oled96.sc
8 + oled96.sc \ Start from 8th Column of driver IC. This is 0th Column for OLED
$37 oled96.sc \ End at (8 + 47)th column. Each Column has 2 pixels(or segments)
;
: oled96.clear
0 oled96.rowaddr 0 oled96.coladdr
4608 0 do 0 oled96.sd loop
;
: oled96.setgraylevel ( n -- )
dup 4 lshift $f0 and grayH !
$0f and grayL !
;
: oled96.hormode
$a0 oled96.sc
$42 oled96.sc
0 oled96.rowaddr
0 oled96.coladdr
;
: oled96.vertmode
$a0 oled96.sc
$46 oled96.sc
;
\ *********** Вывод текста ***********
: oled96.settextxy ( n1 n -- )
oled96row !
oled96col !
;
: oled96.putchar ( c -- )
dup 32 127 within 0= if drop 32 then
32 - 8 *
4 0 do
i oled96col @ 4 * + oled96.coladdr
oled96row @ 8 * oled96.rowaddr
8 0 do
dup BasicFont + j 2 * + @i i rshift 1 and
if grayH @ else 0 then
over BasicFont + j 2 * + 1+ @i i rshift 1 and
if grayL @ else 0 then
or
oled96.sd
loop
loop
drop
;
: oled96.putstring ( adr n -- )
over + swap ?do i c@ oled96.putchar oled96col @ 1+ oled96col ! loop
;
: oled96.setnormalmode ( -- )
OLED_Normal_Display_Cmd oled96.sc
;
: oled96.setinversemode ( -- )
OLED_Normal_Inverse_Cmd oled96.sc
;
: oled96.setcontrastlevel ( n -- )
\ n от 0 до 256
OLED_Set_ContrastLevel_Cmd oled96.sc
oled96.sc
;