📄 keynew.s.bak
字号:
;初始化后COL1…COL4锁成0
;PIO中断时处理键的扫描、去抖、处理
;100X XXXX,读写键盘,防止对LCD操作
;LCD的操作中
;XXXX 1111,还可以禁止键盘
AREA BOOTROM, CODE, READONLY
;0x0000
AT91_MEM EQU 0xFFE00000 ; Memory controller
MEM_RCR EQU 0xFFE00020 ; remap control register
;3d00
ARM_MODE_SYS EQU 0x1F
ARM_MODE_IRQ EQU 0x12
Mode_USR EQU 0x10
Mode_IRQ EQU 0x12
Mode_SVC EQU 0x13
I_Bit EQU 0x80
F_Bit EQU 0x40
AIC_BASE EQU 0xFFFFF000
AIC_EOICR EQU 0x0130
;PIO IRQ
AIC_SMR8 EQU 0xFFFFF020
AIC_SVR8 EQU 0xFFFFF0A0
AIC_IECR EQU 0xFFFFF120
AIC_IDCR EQU 0xFFFFF124
PIO_ISR EQU 0xFFFF004C
PIO_PDSR EQU 0xFFFF003C
PIO_BASE EQU 0xFFFF0000
P0_P7MASK EQU 0xFFFFFF00
USART0 EQU 0xFFFD0000
USART1 EQU 0xFFFCC000
CS4_addr EQU 0x40000000
;LCD and keyboard
ONCHIP_RAM EQU 0x00300000 ; Onchip SRAM base address (REBOOT mode)
CODE_SRAM EQU 0X02000000;SRAM ON BORAD
ONCHIP_RAM_END EQU 0x00002000 ; Onchip SRAM END 8K
CODE_SRAM_END EQU 0X02080000;SRAM ON BORAD 512K
FlashROM_END EQU 0X01080000;ROM ON BORAD 512K
;ON Chip RAM
send_bufffer EQU 0x00001E00;
receive_bufffer EQU 0x00001D00;
addr_download EQU 0x00001F88;start address of download
secsize_download EQU 0x00001F8C;sector size of download
LCDparam EQU 0x00001F00;????????????????????
RAM_Limit EQU 0x02080000 ;SRAM end
IRQ_Stack EQU RAM_Limit ; 1K IRQ stack at top of memory
SVC_Stack EQU RAM_Limit-2048 ; followed by SVC stack 0x1F7FF
USR_Stack EQU SVC_Stack-2048 ; followed by USR stack 0x1EFFF
;XXXX 0000
;E(1),R/~W,RS(1 data,0 commmand)
LCD_CW_E EQU 0x80
;100 X
LCD_CR_E EQU 0xC0
;110 X
LCD_DW_E EQU 0xA0
;101 X
LCD_DR_E EQU 0xE0
;111 X
;write to cs4
LCD_CW EQU 0x00
;000 X
LCD_CR EQU 0x40
;010 X
LCD_DW EQU 0x20
;001 X
LCD_DR EQU 0x60
;011 X
;write to cs4
BOOTROMREG EQU 0x0100203E
;NCS0-Flash ROM
;0x0100203E
;0x0100
;%0010,0000
;%0011,1110
;0x01000000(0x-0 0000-0xF FFFF)use 0-7FFFF, 1MB (A0-A19),0 cycles added after transfer, 8 wait states 225ns ,8-bit,
CSR1DEF EQU 0x02003001
;NCS1-SRAM
;0x02000000(0x00000-3FFFF), NO TDF,1MB(A0-A19),0 cycles added after transfer, no wait states,16-bit,
;upper and lower byte with two select lines, and separate read write signals.
CSR2DEF EQU 0x20000086
;disable 0x20000000,NO TDF,4MB, 8-bit, 0 wait state
CSR3DEF EQU 0x30000082
;disable 0x30000000,NO TDF,4MB, 8-bit, 0 wait state
CSR4DEF EQU 0x40002002
;LCD and keyboard
;=>8-bit 1tdf 0 waitstate
;0x4000203E
;0x4000
;%0010,0000
;%0000,0010
;0x40000000(0x0000-0xFFFF), 1MB (A0-A19),0 cycles added after transfer, 0 wait states,8-bit,
CSR5DEF EQU 0x500000BD ;disable 0x50000000,NO TDF,4MB, 16-bit, 8 wait state
CSR6DEF EQU 0x60000000 ;disable 0x60000000,
CSR7DEF EQU 0x70000000 ;disable 0x70000000,
MCRDEF EQU 0x00000007 ;4 memory regions only, standard read
;%_ _ _ _,_ _ _ _
;%_ _ _ _,0 0 0 0(BA)
;%0 0 1(CSEN)0(BAT),_ _ _(TDF)_(PAGES)
;%_(PAGES)0 1(WSE)_,_ _(NWS)_ _(DBW)
TC_1_BASE EQU 0xFFFE0040
TC_2_BASE EQU 0xFFFE0080
TC_BCR EQU 0xFFFE00C0
TC_BMR EQU 0xFFFE00C4
;Time Counter 1 IRQ
AIC_SMR5 EQU 0xFFFFF014
AIC_SVR5 EQU 0xFFFFF094
addr_AIC_SVR5 EQU 0x000002b8;#########
addr_AIC_SVR8 EQU 0x01010000;#########in ROM
ENTRY
PIO_int
;- Adjust and save LR of current mode in current stack
sub r14, r14, #4
stmfd sp!, {r14}
;- Save SPSR and r0 in current stack
mrs r14, SPSR
stmfd sp!, {r0, r14}
;- Save used registers and LR_usr in the System/User Stack
stmfd sp!, {r0-r4, r14}
;-----------------------------------------------------------------------
LDR R2,=PIO_ISR
LDR R0,[R2]
BIC R0,R0,#0xFFF0FFFF
;row in r0
;1000 =>p19 0x80
;0100 =>p18 0x40
;0010 =>p17 0x20
;0001 =>p16 0x10
bl CPL_P0P7
ldr r3,=0x00000000;clr keydown
start_scan_COL
;scan col
ldr r1,=0xFFFFFFF7;1111 0111->COL4
bl delay20ms
bl CPL_P0P7
scan_nextCOL
LDR R2,=CS4_addr
bic r4,r1,#0xFFFFFFF0
strb r4,[r2]
nop
nop
nop
nop
nop
scan_thisCOL
LDR R2,=PIO_PDSR
LDR R4,[R2]
mvn r2,r4
BIC R2,R2,#0xFFF0FFFF
cmp r0,#0
beq end_of_keydown
; cmp r2,#0
; beq end_of_keydown
cmp r2,r0
beq keydown_is_curCOL
no_keydown_thiscol
mov r1,r1,ROR #1
cmp r1,#0x7FFFFFFF
beq this_scan_no_keydown
B scan_nextCOL
keydown_is_curCOL
;r1 0xFFFFFFF0
;r0 0x000F 0000->0x0000 00F0
MOV R2,R2,LSR #12
BIC R4,R1,#0xFFFFFFF0
add r3,r2,r4
; mov r3,r2
B scan_thisCOL;key in r3
;0x0000 0017:F3
;0x0000 001B:E
;0x0000 001D:0
;0x0000 001E:9
;0x0000 0027:1
;0x0000 002B:5
;0x0000 002D:7
;0x0000 002E:6
;0x0000 0047:FE
;0x0000 004B:F2
;0x0000 004D:F4
;0x0000 004E:8
;0x0000 0087:2
;0x0000 008B:3
;0x0000 008D:F1
;0x0000 008E:4
this_scan_no_keydown
;process key
cmp r3,#0x1E;9
bleq COM_download;download file to target
cmp r3,#0x2E;6
bleq init_USART0
cmp r3,#0x4D;F4
; bleq test_USART0
cmp r3,#0x27
bleq LIGHTLED
cmp r3,#0x87
bleq INITLCD
cmp r3,#0x8B
bleq lcd_main
cmp r3,#0x2B
bleq test_DISPLAY_R0
end_of_keydown
bl delay20ms
LDR R2,=PIO_ISR
LDR R0,[R2]
LDR R2,=CS4_addr
ldrb r1,=0x00
strb r1,[r2];re enable
;-----------------------------------------------------------------------
;- Restore used registers and LR_usr from the System/User Stack
ldmfd sp!, {r0-r4,r14}
;- Mark the End of Interrupt on the interrupt controller
ldr r0, = AIC_BASE
str r0, [r0, #AIC_EOICR]
;- Restore SPSR_irq and r0 from the IRQ stack
ldmfd sp!, {r0, r14}
msr SPSR, r14
;- Restore ajusted LR_irq from IRQ stack directly in the PC
ldmfd sp!, {pc}^
;-------------------------------------------------------------------
COM_download STMFD sp!,{R0-R2,R5,lr}
; BL on_p7;START TRANSFER
LDR R1,=send_bufffer;ADDR OF STRING
LDR R0,=0x434C4557;WELC
STR R0,[R1]
LDR R0,=0x21454D4F;OME!
STR R0,[R1,#4]
LDR R5,=0x00000008
BL sendstring
BL getbyte
CMP R5,#82;"R"
BNE COM_ERROR
LDR R5,=0x00000041;"A"
BL sendbyte
LDR R5,=0x00000004;get the start address of download
BL getstring
LDR R1,=receive_bufffer;save the start address
LDR R0,[R1]
LDR R2,=addr_download
STR R0,[R2]
; BL DISPLAY_R0
LDR R5,=0x00000053;"S"
BL sendbyte
LDR R5,=0x00000004;get the sector size of download,128 bytes/sector
BL getstring
LDR R0,[R1];save the sector size
LDR R2,=secsize_download
STR R0,[R2]
; BL DISPLAY_R0
SEC_WRI LDR R5,=0x00000047;"G"
BL sendbyte;start sector write
LDR R5,=0x00000080;get a sector(128 bytes)
BL getstring
ldr r5,=addr_download
ldr r0,[r5]
add r0,r0,#0x80
ldr r5,=cur_addr_download_end
str r0,[r5]
BL BUF2ROM
;=addr_download <>end __fail
ldr r5,=addr_download
ldr r0,[r5]
ldr r5,=cur_addr_download_end
ldr r2,[r5]
cmp r0,r2
bne fail_wri_byte
LDR R2,=secsize_download
LDR R0,[R2]
SUB R0,R0,#1
CMP R0,#0
BEQ END_FILE
STR R0,[R2]
B SEC_WRI
END_FILE
LDR R5,=0x00000045;"E"
BL sendbyte;END OF TRANSFER
BL TRANSFEROK
COM_downloadEND
LDMFD sp!,{R0-R2,R5,PC};Return
fail_wri_byte
LDR R5,=0x00000046;"F"
BL sendbyte;fail_wri_byte
BL getbyte
CMP R5,#82;"R"
BNE COM_ERROR
LDR R2,=send_bufffer;ADDR OF STRING
ldr r5,=addr_download
LDR R0,[r5]
STR R0,[R2]
LDR R5,=0x00000004
BL sendstring
B COM_downloadEND
COM_ERROR
; BL off_p7
B COM_downloadEND
;B COM_ERROR
TRANSFEROK STMFD sp!,{lr}
; BL on_p7
LDMFD sp!,{PC};Return
wri_byte_Am29F040B
STMFD sp!,{R0-R1,lr}
;R5,low 8-bit Value
;r6,addr of program
ldr r1,=FLASHROM_addr
ldrb r0,=0xaa
strb r0,[r1,#0x555]
ldrb r0,=0x55
strb r0,[r1,#0x2aa]
ldrb r0,=0xa0
strb r0,[r1,#0x555]
strb r5,[r6]
bl delay7us
;bl if_DQ7_end
ldrb r0,[r6]
cmp r0,r5
; bne fail_wribyte
;fail_wribyte
;set verify bit
LDMFD sp!,{r0-r1,PC};Return
if_DQ7_end
STMFD sp!,{R0-R1,lr}
DQ7_not_end
ldr r1,=FLASHROM_addr
DQ5_0
ldrb r0,[r1]
bic r2,r0,#0xFFFFFF7F
cmp r2,#0x80
beq DQ7_end
bic r2,r0,#0xFFFFFFDF
cmp r2,#0x20
bne DQ5_0
ldrb r0,[r1]
bic r2,r0,#0xFFFFFF7F
cmp r2,#0x80
bne DQ7_not_end
DQ7_end
LDMFD sp!,{r0-r1,PC};Return
COM_Display
STMFD sp!,{r5,lr}
;Display-R,(Register)
; M,(Memory)
LDR R5,=0x00000041;"A"
BL sendbyte
BL getbyte
CMP R5,#0x52;"R" File
bleq COM_Register
CMP R5,#0x4D;"M" Display
bleq COM_Memory
LDMFD sp!,{r5,PC};Return
COM_Register
STMFD sp!,{R0,R2,r5,lr}
;display R,(Register) 128-Byte
LDR R5,=0x00000041;"A"
BL sendbyte
BL getbyte
CMP R5,#0x52;"R" reply
LDR R2,=debug_SP_End
STR R0,[R2]
LDR R2,=s_addr_display
STR R0,[R2]
LDR R5,=0x00000118
BL send_MEM_UART0
;s_addr_display,280-byte(0x118)r0-r15
LDMFD sp!,{R0,r2,R5,PC};Return
COM_Memory
STMFD sp!,{R0-R2,r5,lr}
;display M,(Memory) 128-Byte
LDR R5,=0x00000041;"A"
BL sendbyte
LDR R5,=0x00000004;get the start address of download
BL getstring
LDR R5,=0x00000041;"A"
BL sendbyte
BL getbyte
CMP R5,#0x52;"R" File
LDR R1,=receive_bufffer;save the start address
LDR R0,[R1]
LDR R2,=s_addr_display
STR R0,[R2]
LDR R5,=0x00000100
BL send_MEM_UART0
;s_addr_display,256-byte(0x100)
LDMFD sp!,{R0-R2,r5,PC};Return
send_MEM_UART0
STMFD sp!,{R0-R4,lr}
;s_addr_display
;R5:COUNT OF TRANSMIT LOW 16-BIT
;SET R5,BEFORE CALL,256-byte(0x100)
LDR R0,=USART0
send_MEMwait2 LDR R1,[R0,#0x14];US_CSR
LDR R2,=0xFFFFFFEF
BIC R1,R1,R2;ENDTX
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -