Created
June 29, 2015 15:22
-
-
Save ont/52c91e4ff090ee805e27 to your computer and use it in GitHub Desktop.
ili9327 mcufriend.com prototype code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import RPi.GPIO as g | |
g.setmode(g.BOARD) | |
pins = [ | |
7, # cs | |
11, # wr - clock (rising edge) | |
12, # rs - data/command | |
15, # d1 | |
16, # d2 | |
18, # d3 | |
19, # d4 (???) | |
21, # d6 (???) | |
22, # d5 (???) | |
23, # d7 | |
24, # d8 | |
26 # rst | |
] | |
CSX = 7 | |
DCX = 12 | |
WRX = 11 | |
RES = 26 | |
D = [ | |
15, # d1 | |
16, # d2 | |
18, # d3 | |
19, # d4 (???) | |
22, # d5 (???) | |
21, # d6 (???) | |
23, # d7 | |
24, # d8 | |
] | |
def init(): | |
# prepare raspberry pins for output | |
for x in pins: | |
print x | |
g.setup(x, g.OUT) | |
g.output(x, 1) | |
# hard reset sequence | |
g.output(RES, 1) | |
time.sleep(0.005) ## 5 ms | |
g.output(RES, 0) | |
time.sleep(0.015) ## 15 ms | |
g.output(RES, 1) | |
time.sleep(0.015) ## 15 ms | |
g.output(CSX, 1) | |
g.output(WRX, 1) | |
g.output(CSX, 0) | |
def send_data(cs, byte): | |
g.output(DCX, cs) | |
g.output(WRX, 0) | |
for i in xrange(8): | |
g.output( D[i], (byte >> i) & 1 ) | |
g.output(WRX, 1) | |
def cmd(byte): | |
send_data(0, byte) | |
def data(byte): | |
send_data(1, byte) | |
# | |
# Main part | |
# | |
init() | |
#cmd( 0xE9 ) | |
#data( 0x20 ) | |
cmd( 0x11 ) #Exit Sleep | |
time.sleep( 0.100 ) | |
cmd( 0xD1 ) # VCOM Control | |
data( 0x00 ) # SEL/VCM | |
data( 0x0C ) # VCM | |
data( 0x0F ) # VDV | |
cmd( 0xD0 ) # Power_Setting | |
data( 0x07 ) # VC | |
data( 0x04 ) # BT | |
data( 0x00 ) # VRH | |
cmd( 0x36 ) # Set_address_mode | |
data( 0x48 ) | |
# 0x48 = 0b01001000 | |
# 0 - top to bottom | |
# 1 - right to left | |
# 0 - normal mode of columns order | |
# 0 - refresh top to bottom | |
# 1 - RGB or BGR (here BGR order) | |
# 0 - <skip> | |
# 0 - no hflip | |
# 0 - no flip | |
cmd( 0x3A ) # Set pixel format | |
data( 0x05 ) | |
cmd( 0xC1 ) # Display timing setting for normal/partial mode | |
data( 0x10 ) | |
data( 0x10 ) | |
data( 0x02 ) | |
data( 0x02 ) | |
cmd( 0xC0 ) # Set Default Gamma | |
data( 0x00 ) | |
data( 0x35 ) | |
data( 0x00 ) | |
data( 0x00 ) | |
data( 0x01 ) | |
data( 0x02 ) | |
cmd( 0xC5 ) # Set frame rate | |
data( 0x04 ) | |
cmd( 0xD2 ) # Power setting | |
data( 0x01 ) | |
data( 0x44 ) | |
cmd( 0xC8 ) # Set Gamma | |
data( 0x04 ) | |
data( 0x67 ) | |
data( 0x35 ) | |
data( 0x04 ) | |
data( 0x08 ) | |
data( 0x06 ) | |
data( 0x24 ) | |
data( 0x01 ) | |
data( 0x37 ) | |
data( 0x40 ) | |
data( 0x03 ) | |
data( 0x10 ) | |
data( 0x08 ) | |
data( 0x80 ) | |
data( 0x00 ) | |
cmd( 0x2A ) | |
data( 0x00 ) | |
data( 0x00 ) | |
data( 0x00 ) | |
data( 0xeF ) | |
cmd( 0x2B ) | |
data( 0x00 ) | |
data( 0x00 ) | |
data( 0x01 ) | |
data( 0x8F ) | |
cmd( 0x29 ) #display on | |
cmd( 0x2C ) #display on | |
x1 = 100 | |
y1 = 100 | |
x2 = 200 | |
y2 = 200 | |
cmd(0x2a) # Set_column_address | |
data(x1>>8) | |
data(x1) | |
data(x2>>8) | |
data(x2) | |
cmd(0x2b) # Set_page_address | |
data(y1>>8) | |
data(y1) | |
data(y2>>8) | |
data(y2) | |
cmd(0x2c) # Write_memory_start | |
# write pixel by pixel | |
for x in xrange(100): | |
for y in xrange(100): | |
data(0xee) ## low part of word | |
data(0) ## hight part of word | |
g.output(CSX, 1) ## end command / data session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment