Gaviar (小志掌機) >> Assembly
Key Test
參考資訊:
1. ascii
2. ws2812c
3. Delay_slot
4. FlatHeadBro
按鍵電路
ASCII字型
對應按鍵
UP | PE0 |
---|---|
DOWN | PE7 |
LEFT | PE6 |
RIGHT | PE4 |
A | PE13 |
B | PE12 |
X | PE11 |
Y | PE2 |
L | PE1 |
R | PE10 |
SELECT | PE8 |
START | PE9 |
MENU | PE3 |
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 PE_CFG0, 0x00c0 .equ PE_CFG1, 0x00c4 .equ PE_DAT, 0x00d0 .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 .equ BG, 0x0000 .equ FG, 0xffff .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, 0x00000000 li a0, GPIO_BASE + PE_CFG0 sw t0, 0(a0) li a0, GPIO_BASE + PE_CFG1 sw t0, 0(a0) 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 loop: li a0, GPIO_BASE + PE_DAT lw t0, 0(a0) li t1, (1 << 0) and t1, t1, t0 bgtz t1, 0f li t0, 30 j draw 0: li t1, (1 << 7) and t1, t1, t0 bgtz t1, 1f li t0, 31 j draw 1: li t1, (1 << 4) and t1, t1, t0 bgtz t1, 2f li t0, 16 j draw 2: li t1, (1 << 6) and t1, t1, t0 bgtz t1, 3f li t0, 17 j draw 3: li t1, (1 << 12) and t1, t1, t0 bgtz t1, 4f li t0, 'B' j draw 4: li t1, (1 << 11) and t1, t1, t0 bgtz t1, 5f li t0, 'X' j draw 5: li t1, (1 << 1) and t1, t1, t0 bgtz t1, 6f li t0, 'L' j draw 6: li t1, (1 << 10) and t1, t1, t0 bgtz t1, 7f li t0, 'R' j draw 7: li t1, (1 << 2) and t1, t1, t0 bgtz t1, 8f li t0, 'Y' j draw 8: li t1, (1 << 9) and t1, t1, t0 bgtz t1, 9f li t0, 'T' j draw 9: li t1, (1 << 8) and t1, t1, t0 bgtz t1, 10f li t0, 'S' j draw 10: li t1, (1 << 3) and t1, t1, t0 bgtz t1, 11f li t0, 'M' j draw 11: li t1, (1 << 13) and t1, t1, t0 bgtz t1, 12f li t0, 'A' j draw 12: li x8, 0 li x9, 0 jal set_pos li t6, 320 * 240 bg: li t0, BG jal lcd_dat addi t6, t6, -1 bgtz t6, bg li t0, _250MS jal delay j loop draw: sll t0, t0, 3 la a3, font add a3, a3, t0 li t6, 8 li x8, 135 li x9, 100 nbyte: li t5, 8 lb a4, 0(a3) jal set_pos byte: li t1, 0x80 and t0, a4, t1 sll a4, a4, 1 beqz t0, w0 w1: li t0, FG jal lcd_dat li t0, FG jal lcd_dat li t0, FG jal lcd_dat li t0, FG jal lcd_dat j next w0: li t0, BG jal lcd_dat li t0, BG jal lcd_dat li t0, BG jal lcd_dat li t0, BG jal lcd_dat next: addi t5, t5, -1 bgtz t5, byte add a3, a3, 1 add x9, x9, 2 addi t6, t6, -1 bgtz t6, nbyte j loop set_pos: move a2, ra li t0, 0x2a jal lcd_cmd li t0, 0 jal lcd_dat move t0, x8 jal lcd_dat li t0, 0x2b jal lcd_cmd li t0, 0 jal lcd_dat move t0, x9 jal lcd_dat li t0, 0x2c jal lcd_cmd jr a2 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 t4, t1 or t4, t4, t2 or t4, t4, t3 sw t4, 0(a0) li t0, LCD_WR or t4, t4, t0 sw t4, 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 font: .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .byte 0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C .byte 0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00 .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00 .byte 0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00 .byte 0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00 .byte 0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00 .byte 0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40 .byte 0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00 .byte 0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00 .byte 0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00 .byte 0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00 .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00 .byte 0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00 .byte 0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00 .byte 0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00 .byte 0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00 .byte 0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00 .byte 0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00 .byte 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00 .byte 0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00 .byte 0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00 .byte 0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00 .byte 0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00 .byte 0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00 .byte 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30 .byte 0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00 .byte 0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00 .byte 0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00 .byte 0xFC,0xC6,0xC6,0xFC,0xC6,0xC6,0xFC,0x00,0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00 .byte 0xF8,0xCC,0xC6,0xC6,0xC6,0xCC,0xF8,0x00,0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xFE,0x00 .byte 0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xC0,0x00,0x3E,0x60,0xC0,0xCE,0xC6,0x66,0x3E,0x00 .byte 0xC6,0xC6,0xC6,0xFE,0xC6,0xC6,0xC6,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x7E,0x00 .byte 0x06,0x06,0x06,0x06,0xC6,0xC6,0x7C,0x00,0xC6,0xCC,0xD8,0xF0,0xF8,0xDC,0xCE,0x00 .byte 0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00 .byte 0xC6,0xE6,0xF6,0xFE,0xDE,0xCE,0xC6,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00 .byte 0xFC,0xC6,0xC6,0xC6,0xFC,0xC0,0xC0,0x00,0x7C,0xC6,0xC6,0xC6,0xDE,0xCC,0x7A,0x00 .byte 0xFC,0xC6,0xC6,0xCE,0xF8,0xDC,0xCE,0x00,0x78,0xCC,0xC0,0x7C,0x06,0xC6,0x7C,0x00 .byte 0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00 .byte 0xC6,0xC6,0xC6,0xEE,0x7C,0x38,0x10,0x00,0xC6,0xC6,0xD6,0xFE,0xFE,0xEE,0xC6,0x00 .byte 0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00 .byte 0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00 .byte 0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00 .byte 0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF .byte 0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00 .byte 0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00 .byte 0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00 .byte 0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C .byte 0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00 .byte 0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00 .byte 0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00 .byte 0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00 .byte 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06 .byte 0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00 .byte 0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00 .byte 0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00 .byte 0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C .byte 0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00 .byte 0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00 .byte 0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00 .end
完成