Gaviar (小志掌機) >> Assembly

LCD


參考資訊:
1. ws2812c
2. Delay_slot
3. FlatHeadBro

LCD電路



main.s

    .global _start

    .equ GPIO_BASE,  0x02000000
    .equ PD_CFG0,    0x0090
    .equ PD_CFG1,    0x0094
    .equ PD_CFG2,    0x0098
    .equ PD_DAT,     0x00a0

    .equ LCD_RST,    (1 << 0)
    .equ LCD_WR,     (1 << 18)
    .equ LCD_RS,     (1 << 19)
    .equ LCD_RD,     (1 << 20)
    .equ LCD_CS,     (1 << 21)
    .equ LCD_BL,     (1 << 22)

    .equ _250MS,     50000000
    .equ _500MS,     100000000
    .equ _1S,        200000000

    .text
    .long 0x4000006f
    .byte 'e','G','O','N','.','B','T','0'
    .long 0x5F0A6C39
    .long 0x8000
    .long 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
  
    .org 0x0400
_start:
    li t0, 0x11111111
    li a0, GPIO_BASE + PD_CFG0
    sw t0, 0(a0)
    li a0, GPIO_BASE + PD_CFG1
    sw t0, 0(a0)
    li a0, GPIO_BASE + PD_CFG2
    sw t0, 0(a0)

    li t0, 0xffffffff
    li a0, GPIO_BASE + PD_DAT
    sw t0, 0(a0)

    jal lcd_rst

    li t0, 0xb2
    jal lcd_cmd
    li t0, 0x5c
    jal lcd_dat
    li t0, 0x5c
    jal lcd_dat
    li t0, 0x00
    jal lcd_dat
    li t0, 0x33
    jal lcd_dat
    li t0, 0x33
    jal lcd_dat
    
    li t0, 0xb7
    jal lcd_cmd
    li t0, 0x35
    jal lcd_dat
    
    li t0, 0x21
    jal lcd_cmd
    
    li t0, 0x11
    jal lcd_cmd

    li t0, _250MS
    jal delay

    li t0, 0xe0
    jal lcd_cmd
    li t0, 0xd0
    jal lcd_dat
    li t0, 0x06
    jal lcd_dat
    li t0, 0x0b
    jal lcd_dat
    li t0, 0x07
    jal lcd_dat
    li t0, 0x07
    jal lcd_dat
    li t0, 0x24
    jal lcd_dat
    li t0, 0x2e
    jal lcd_dat
    li t0, 0x32
    jal lcd_dat
    li t0, 0x46
    jal lcd_dat
    li t0, 0x37
    jal lcd_dat
    li t0, 0x13
    jal lcd_dat
    li t0, 0x13
    jal lcd_dat
    li t0, 0x2d
    jal lcd_dat
    li t0, 0x33
    jal lcd_dat
    
    li t0, 0xe1
    jal lcd_cmd
    li t0, 0xd0
    jal lcd_dat
    li t0, 0x02
    jal lcd_dat
    li t0, 0x06
    jal lcd_dat
    li t0, 0x09
    jal lcd_dat
    li t0, 0x08
    jal lcd_dat
    li t0, 0x05
    jal lcd_dat
    li t0, 0x29
    jal lcd_dat
    li t0, 0x44
    jal lcd_dat
    li t0, 0x42
    jal lcd_dat
    li t0, 0x38
    jal lcd_dat
    li t0, 0x14
    jal lcd_dat
    li t0, 0x14
    jal lcd_dat
    li t0, 0x2a
    jal lcd_dat
    li t0, 0x30
    jal lcd_dat
    
    li t0, 0x36
    jal lcd_cmd
    li t0, 0xb0
    jal lcd_dat
    
    li t0, 0x2a
    jal lcd_cmd
    li t0, 0x00
    jal lcd_dat
    li t0, 0x00
    jal lcd_dat
    li t0, 0x01
    jal lcd_dat
    li t0, 0x3f
    jal lcd_dat
    
    li t0, 0x2b
    jal lcd_cmd
    li t0, 0x00
    jal lcd_dat
    li t0, 0x00
    jal lcd_dat
    li t0, 0x00
    jal lcd_dat
    li t0, 0xef
    jal lcd_dat
    
    li t0, 0x3a
    jal lcd_cmd
    li t0, 0x55
    jal lcd_dat

    li t0, 0x29
    jal lcd_cmd
    
    li t0, 0x2c
    jal lcd_cmd

    li t6, 320 * 80
red:
    li t0, 0xf800
    jal lcd_dat
    addi t6, t6, -1
    bgtz t6, red
    
    li t6, 320 * 80
green:
    li t0, 0x7e0
    jal lcd_dat
    addi t6, t6, -1
    bgtz t6, green
    
    li t6, 320 * 80
blue:
    li t0, 0x1f
    jal lcd_dat
    addi t6, t6, -1
    bgtz t6, blue
1:
    j 1b

lcd_wr:
    li a0, GPIO_BASE + PD_DAT

    li t4, 0x00ff
    and t2, t0, t4
    li t4, 0xff00
    and t3, t0, t4
    sll t2, t2, 1
    sll t3, t3, 2

    move t5, t1
    or t5, t5, t2
    or t5, t5, t3
    sw t5, 0(a0)

    li t0, LCD_WR
    or t5, t5, t0
    sw t5, 0(a0)
    jr ra

lcd_dat:
    move a1, ra
    li t1, LCD_RS | LCD_RD | LCD_BL | LCD_RST
    jal lcd_wr
    jr a1

lcd_cmd:
    move a1, ra
    li t1, LCD_RD | LCD_BL | LCD_RST
    jal lcd_wr
    jr a1

lcd_rst:
    move a1, ra
    li t0, 0x00000000
    li a0, GPIO_BASE + PD_DAT
    sw t0, 0(a0)

    li t0, _250MS
    jal delay

    li t0, 0xffffffff
    li a0, GPIO_BASE + PD_DAT
    sw t0, 0(a0)

    li t0, _250MS
    jal delay
    jr a1

delay:
    addi t0, t0, -1
    bgtz t0, delay
    jr ra
    .end

完成


返回上一頁