OLED initialization

A project log for 1 kB Arduino Roguelike

1 kB roguelike using an Arduino and 0.96" OLED

RadekRadek 12/03/2016 at 17:200 Comments

Having the peripherals set-up I looked at the adafruit library. More specificially the display() and begin() functions. The begin is the initialization routine in the adafruit 1306 library. Converting begin() function to assembly looks like the following:

	sbi PORTB, rst		; rst high

    ldi  r18, 21		; delay 1ms
    ldi  r19, 199
L1: dec  r19
    brne L1
    dec  r18
    brne L1

	cbi PORTB, rst		;rst low

    ldi  r18, 208		; delay 10ms
    ldi  r19, 202
L2: dec  r19
    brne L2
    dec  r18
    brne L2

	sbi PORTB, rst		; rst high

	mcommand 0xae
	mcommand 0xd5
	mcommand 0x80
	mcommand 0xa8
	mcommand 63
	mcommand 0xD3
	mcommand 0x0
	mcommand 0x40
	mcommand 0x8d
	mcommand 0x14
	mcommand 0x20
	mcommand 0x00
	mcommand (0xa8|0x1);
	mcommand 0xc8
	mcommand 0xDA
	mcommand 0x12
	mcommand 0x81
	mcommand 0xcf
	mcommand 0xd9
	mcommand 0xf1
	mcommand 0xdb
	mcommand 0x40
	mcommand 0xa4
	mcommand 0xa6
	mcommand 0x2e
	mcommand 0xaf

I used for the delay assembly code.

the mcommand is a macro:

.macro mcommand 
	ldi r20, @0
	rcall command

and the command subroutine looks like the following (recall to send spi data I put the data byte in r20):

	sbi		PORTB, cs ;cs high
	cbi		PORTB, dc ;dc low
	cbi		PORTB, cs ;cs low
	rcall	spi_send
	sbi		PORTB, cs; cs high