STC15W204S

Show PNG


參考資訊:
1. png-to-lcd
2. SSD1306.pdf
3. Adafruit_SSD1306
4. STC15F2K60S2-en.pdf

PNG轉LCD

$ sudo apt-get install nodejs npm -y
$ npm install tape
$ cd
$ git clone https://github.com/noopkat/png-to-lcd
$ cd png-to-lcd/test
$ vim mytest.js
  var pngtolcd = require('../png-to-lcd');
  pngtolcd('cat2.png', true, function(err, buffer) {
    console.log(buffer.toString('hex'));
  });

$ vim run.py
  #!/usr/bin/python
  import os
  import sys 
  import commands

  r = commands.getoutput('node mytest.js')

  c = 'db '
  cnt = 0 
  col = 0 
  for x in r:
    cnt = cnt + 1 
    if cnt == 1:
      c = c + '0x'
    c = c + str(x)

    if cnt >= 2:
      cnt = 0 
      col = col + 1 
      if col >= 32: 
        col = 0 
        print c
        c = 'db '
      else:
        c = c + ','  
$ chmod a+x ./run.py
$ ./run.py

P.S. 輸出的字串就是DB

main.s

  i2c_sda         set 0xcc
  i2c_scl         set 0xcd

  i2c_addr        equ 0x78
  lcd_width       equ 128
  lcd_height      equ 64

  cmd_contrast    equ 0x81
  cmd_disp_resume equ 0xa4
  cmd_normal_disp equ 0xa6
  cmd_invert_disp equ 0xa7
  cmd_disp_off    equ 0xae
  cmd_disp_on     equ 0xaf
  cmd_disp_offset equ 0xd3
  cmd_com_pins    equ 0xda
  cmd_vcom_detect equ 0xdb
  cmd_clock_div   equ 0xd5
  cmd_pre_charge  equ 0xd9
  cmd_multiplex   equ 0xa8
  cmd_start_line  equ 0x40
  cmd_memory_mode equ 0x20
  cmd_column_addr equ 0x21
  cmd_page_addr   equ 0x22
  cmd_scan_dec    equ 0xc8
  cmd_seg_remap   equ 0xa0
  cmd_charge_pump equ 0x8d

  .org 0h
  jmp _start

  .org 100h
_start:
  call ssd1306_init
  call ssd1306_set_col_addr
  call ssd1306_set_page_addr
  
  mov dptr, #png
  mov r4, #64
m0:
  call i2c_start
  mov a, #i2c_addr
  call i2c_write
  mov a, #40h
  call i2c_write
  mov r5, #16
m1:
  clr a
  movc a, @a+dptr
  inc dptr
  call i2c_write
  djnz r5, m1
  djnz r4, m0
  call i2c_stop
  jmp $

delay:
  mov r0, #10
  djnz r0, $
  ret

i2c_start:
  setb i2c_sda
  setb i2c_scl
  call delay
  clr i2c_sda
  call delay
  clr i2c_scl
  ret

i2c_stop:
  call delay
  clr i2c_sda
  call delay
  setb i2c_scl
  call delay
  setb i2c_sda
  ret

i2c_write:
  push 4
  push 5
  mov r4, #8
  mov r5, a
i0:
  mov a, r5
  rlc a
  mov r5, a
  jc i1
  clr i2c_sda
  sjmp i2
i1:
  setb i2c_sda
i2:
  call delay
  setb i2c_scl
  call delay
  clr i2c_scl
  djnz r4, i0
  
  call delay
  setb i2c_sda
  call delay
  setb i2c_scl
  call delay
  mov c, i2c_sda
  call delay
  clr i2c_scl
  pop acc
  mov r5, a
  pop acc
  mov r4, a
  ret

send_cmd:
  push 4
  mov r4, a
  call i2c_start
  mov a, #i2c_addr
  call i2c_write
  mov a, #0
  call i2c_write
  mov a, r4
  call i2c_write
  call i2c_stop
  pop acc
  mov r4, a
  ret

send_data:
  push 4
  mov r4, a
  call i2c_start
  mov a, #i2c_addr
  call i2c_write
  mov a, #40h
  call i2c_write
  mov a, r4
  call i2c_write
  call i2c_stop
  pop acc
  mov r4, a
  ret

ssd1306_init:
  mov a, #cmd_disp_off
  call send_cmd
  mov a, #cmd_clock_div
  call send_cmd
  mov a, #80h
  call send_cmd
  mov a, #cmd_multiplex
  call send_cmd
  mov a, #3fh
  call send_cmd
  mov a, #cmd_disp_offset
  call send_cmd
  mov a, #0
  call send_cmd
  mov a, #cmd_start_line
  call send_cmd
  mov a, #cmd_charge_pump
  call send_cmd
  mov a, #14h
  call send_cmd
  mov a, #cmd_memory_mode
  call send_cmd
  mov a, #0
  call send_cmd
  mov a, #cmd_seg_remap | 1
  call send_cmd
  mov a, #cmd_scan_dec
  call send_cmd
  mov a, #cmd_com_pins
  call send_cmd
  mov a, #12h
  call send_cmd
  mov a, #cmd_contrast
  call send_cmd
  mov a, #0cfh
  call send_cmd
  mov a, #cmd_pre_charge
  call send_cmd
  mov a, #0f1h
  call send_cmd
  mov a, #cmd_vcom_detect
  call send_cmd
  mov a, #40h
  call send_cmd
  mov a, #cmd_disp_resume
  call send_cmd
  mov a, #cmd_normal_disp
  call send_cmd
  mov a, #cmd_disp_on
  call send_cmd
  ret

ssd1306_set_col_addr:
  mov a, #cmd_column_addr
  call send_cmd
  mov a, #0
  call send_cmd
  mov a, #lcd_width - 1
  call send_cmd
  ret
 
ssd1306_set_page_addr:
  mov a, #cmd_page_addr
  call send_cmd
  mov a, #0
  call send_cmd
  mov a, #(lcd_height / 8) - 1
  call send_cmd
  ret

png:
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x20,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x04,0x40,0x00
  db 0x14,0x00,0x42,0x10,0xa4,0x00,0x12,0x00,0x00,0x00,0x00,0x90,0x00,0x00,0x14,0x40,0x88,0x20,0x80,0x28,0x00,0x50,0x00,0xa0,0x00,0x48,0x00,0x00,0x40,0x00,0x40,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x08,0x40,0x12,0xa4,0x59,0xa6,0x28,0x40,0x14,0x00,0x40,0x10,0x84,0x00,0x10,0x80,0x00,0x00,0x10,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x40,0x80,0x00,0x80,0x40,0x00,0x00,0x00,0x00,0x40,0x08,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00
  db 0x8a,0x10,0x02,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x22,0x00,0x12,0x00,0x15,0x00,0x40,0x14,0x80,0x2a,0x40,0x82,0x14,0x40,0x02,0x90
  db 0x00,0x10,0x02,0x20,0x00,0x20,0x08,0x80,0x20,0x88,0x20,0xca,0x35,0xc8,0x12,0xe5,0x1a,0xed,0x10,0x85,0x20,0x02,0x48,0x00,0x12,0x40,0x08,0x00,0x00,0x20,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0xf8,0x44,0xb8,0x42,0xa8,0x50,0x00,0x04,0x08,0x01,0xc8,0x28,0xd0,0x20,0xe0,0x00,0x40,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x00,0xa0,0x00,0x90,0x00,0x82,0x90,0x49,0xf0,0x42,0x90,0x6a,0xe0,0x69,0x80,0x08,0x02,0x10,0x09,0x22,0x08,0x00,0x2a,0x00,0x42
  db 0x00,0x44,0x01,0x52,0x00,0xaa,0x40,0x98,0x64,0xd1,0xae,0x51,0xaf,0x58,0xb7,0x68,0x97,0x28,0x93,0x04,0x00,0xa9,0x00,0x45,0x10,0x80,0x25,0x00,0x10,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x01,0x44,0x00,0x90,0x00,0x41,0x83,0x09,0x06,0x1d,0x1f,0x2c,0x38,0x16,0x3c,0x2b,0x16,0x1d,0x0b,0x04,0x03,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x02,0x00,0x10,0x44,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x80,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x20,0x40,0x00,0x50,0x00
  db 0xa0,0x08,0x02,0x00,0x0e,0x78,0xf7,0xac,0xfb,0xd6,0x68,0xc0,0xc1,0xa1,0xfc,0xab,0xff,0x6a,0xff,0x2d,0x1b,0x06,0x04,0x00,0x20,0x40,0x1a,0x44,0x11,0x24,0x00,0x10
  db 0x00,0x04,0x00,0x28,0xc2,0x08,0x42,0x08,0xb2,0x04,0xeb,0x14,0xeb,0x55,0xbb,0x44,0x12,0x80,0x04,0x20,0x02,0x10,0x44,0x01,0x14,0x40,0x02,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x09,0x82,0x00,0x15,0x40,0x14,0x80,0x24,0x90,0x04,0x28,0x00,0x48,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x01,0x24,0x01,0x0a,0x21,0x04,0x08,0x11,0x42,0x08,0x20,0x10,0x40,0x80,0x2a,0x40,0x95,0x20,0x44,0xa8,0x10,0xa0,0x01,0x24,0x00,0x05,0x00
  db 0x00,0x80,0x10,0x00,0x20,0xd0,0x20,0x81,0x21,0x83,0x23,0x43,0x22,0x49,0xa3,0x01,0xa1,0x50,0x00,0x28,0x50,0x04,0x20,0x0d,0x40,0x0b,0x00,0x25,0x80,0x00,0x00,0x00
  db 0x84,0x00,0x42,0x90,0x0a,0xa4,0x51,0x8a,0x24,0xd9,0xa6,0x59,0xa6,0x09,0x42,0x10,0x04,0x80,0x02,0x20,0x81,0x04,0x10,0x41,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x02,0x00,0x00,0x09,0x00,0x00,0x44,0x00,0x01,0x10,0x04,0x20,0x02,0x08,0x01,0x00,0x20,0x04,0x00
  db 0x02,0x10,0x01,0x00,0x00,0x00,0x12,0x44,0x08,0x40,0x14,0x00,0x74,0x81,0x54,0xa9,0x56,0xe9,0x96,0xe9,0xb7,0xde,0xb9,0x6e,0xd8,0x22,0x90,0x00,0x02,0x00,0x40,0x14
  db 0x40,0x08,0x22,0x40,0x0a,0x00,0x2a,0x00,0x1a,0x20,0x81,0x0a,0x21,0x08,0x42,0x04,0x00,0x22,0x00,0x92,0x00,0x08,0x00,0x24,0x00,0x00,0x44,0x00,0x88,0x20,0x85,0x50
  db 0x0a,0x20,0x8a,0x04,0x92,0x28,0x42,0xac,0x51,0x06,0x59,0x02,0x00,0x14,0x40,0x01,0x20,0x00,0x08,0x80,0x04,0x20,0x00,0x89,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x10,0x00,0x42,0x00,0x08,0x20
  db 0x00,0x0a,0x20,0x00,0x00,0x00,0x00,0x10,0x28,0x00,0x29,0x12,0x24,0x08,0x04,0x2b,0x46,0x01,0x46,0x09,0x26,0x09,0x16,0x2d,0x13,0x7e,0x94,0x60,0x00,0x40,0x84,0x28
  db 0x53,0x24,0x49,0x10,0x21,0x48,0x02,0x50,0x01,0x20,0x04,0x00,0x01,0x08,0x10,0x00,0x29,0x40,0x02,0x20,0x00,0x04,0x01,0x28,0x41,0x00,0x2a,0x00,0x0a,0x00,0x02,0x00
  db 0x80,0x20,0x84,0x20,0x4a,0x10,0x8a,0x05,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  db 0x00,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x40,0x01,0x08,0x20,0x00,0x02,0x00
  db 0x00,0x01,0x04,0x01,0x14,0x01,0x04,0x10,0x01,0x00,0x01,0x04,0x80,0x00,0x00,0x00,0x00,0xa2,0x00,0x08,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x80,0x00,0x20,0x4a,0x00
  db 0x2a,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  .end

編譯程式:

$ mcu8051ide --compile main.s

燒錄程式:

$ sudo stcgal -P stc15 main.hex

完成


返回上一頁