Gaviar (小志掌機) >> Assembly

Button


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

按鍵R連接到PE1


GPIO位址


PE_CFG0


PE_DAT


main.s

    .global _start
  
    .equ GPIO_BASE, 0x02000000
    .equ PE_CFG0,   0x00c0
    .equ PE_DAT,    0x00d0
    .equ PE_PULL0,  0x00e4
    .equ _50NS,     10
    .equ _100NS,    20
    .equ _200NS,    40
    .equ _300NS,    60
    .equ _400NS,    80
    .equ _450NS,    90
    .equ _800NS,    160
    .equ _850NS,    170
    .equ _1US,      200
    .equ _500US,    100000
    .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, 0x100000
    li a0, GPIO_BASE + PE_CFG0
    sw t0, 0(a0)
    
    li t0, 0x55555555
    li a0, GPIO_BASE + PE_PULL0
    sw t0, 0(a0)

    li a0, GPIO_BASE + PE_DAT
0:
    lw t0, 0(a0)
    not t0, t0
    and t0, t0, (1 << 1)
    sll t0, t0, 11
    jal b24

    li t0, _500US
    jal delay

    j 0b

b24:
    move t2, ra
    move t3, t0
    li t4, 24
0:
    and t0, t3, 1
    srl t3, t3, 1
    beqz t0, 1f
    jal b1
    j 2f
1:
    jal b0
2:
    addi t4, t4, -1
    bgtz t4, 0b
    jr t2

b0:
    move t1, ra
    li t0, (1 << 5)
    sw t0, 0(a0)

    li t0, _300NS
    jal delay

    li t0, (0 << 5)
    sw t0, 0(a0)

    li t0, _850NS
    jal delay
    jr t1

b1:
    move t1, ra
    li t0, (1 << 5)
    sw t0, 0(a0)

    li t0, _800NS
    jal delay

    li t0, (0 << 5)
    sw t0, 0(a0)

    li t0, _400NS
    jal delay
    jr t1

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

完成


返回上一頁