📄 keyboard.asm
字号:
clc
subi temp,0x30
ldi temp1,10
mul temp,temp1
mov temp,R0
ld temp1,Z+ ;first high,0x00
ld temp1,Z ;second low
subi temp1,0x30
add temp,temp1
dec temp
ldi temp1,8 ;4word,8byte
mul temp,temp1
mov temp,R0
mov temp1,send_bit_delay
ldi ZH,high(unicode_table)
ldi ZL,low(unicode_table)
clc
add ZL,temp
adc ZH,temp1
ldi YL,folk_buffer_low
ldi YH,folk_buffer_high
ldi counter1,0x08
check_unicode_table:
lpm
st Y+,R0
adiw ZL, 1
dec counter1
brne check_unicode_table
ldi YL,folk_buffer_low
ldi YH,folk_buffer_high
ldi counter1,0x08
rcall send_key_common_hex
pop send_bit_delay
ret
;------------------------------------------------
send_key_birth:
wdr
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ldi temp,birth_addr_offset
clc
add YL,temp
adc YH,zero_register
ldi counter1,birth_length
rcall send_key_common_hex
ret
send_key_address:
wdr
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ldi temp,address_addr_offset
clc
add YL,temp
adc YH,zero_register
ldi counter1,address_length
rcall send_key_common_hex
ret
send_key_id:
wdr
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ldi temp,id_addr_offset
clc
add YL,temp
adc YH,zero_register
ldi counter1,id_length
rcall send_key_common_hex
ret
send_key_issue:
wdr
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ldi temp,issue_addr_offset
clc
add YL,temp
adc YH,zero_register
ldi counter1,issue_length
rcall send_key_common_hex
ret
send_key_exper:
wdr
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ldi temp,exper_addr_offset
clc
add YL,temp
adc YH,zero_register
ldi counter1,exper_length
rcall send_key_common_hex
ret
send_key_exper2:
wdr
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ldi temp,exper2_addr_offset
clc
add YL,temp
adc YH,zero_register
ldi counter1,exper2_length
rcall send_key_common_hex
ret
/* ************** flash operation *********************** */
flash_identification:
;[5555]=aa
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xaa
st Z,temp
;[2aaa] = 55
ldi ZH,0xaa
ldi ZL,0xaa
ldi temp,0x55
st Z,temp
;[5555] = 90
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0x90
st Z,temp
;out[00]
ldi ZH,0x80
ldi ZL,0x00
ld temp,Z
;out[01]
adiw ZL,0x01
ld temp,Z
;[5555]=aa
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xaa
st Z,temp
;[2aaa] = 55
ldi ZH,0xaa
ldi ZL,0xaa
ldi temp,0x55
st Z,temp
;[5555] = f0
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xf0
st Z,temp
ret
;============================================
;
flash_erase:
cli
;[5555]=aa
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xaa
st Z,temp
;[2aaa] = 55
ldi ZH,0xaa
ldi ZL,0xaa
ldi temp,0x55
st Z,temp
;[5555] = 80
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0x80
st Z,temp
;[5555]=aa
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xaa
st Z,temp
;[2aaa] = 55
ldi ZH,0xaa
ldi ZL,0xaa
ldi temp,0x55
st Z,temp
;[5555] = 10
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0x10
st Z,temp
rcall delay_200ms
sei
ret
;=======================================
flash_write_byte:
;input: YH = addr_high, YL = addr_low; temp1 = value
;[5555]=aa
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xaa
st Z,temp
;[2aaa] = 55
ldi ZH,0xaa
ldi ZL,0xaa
ldi temp,0x55
st Z,temp
;[5555] = a0
ldi ZH,0xd5
ldi ZL,0x55
ldi temp,0xa0
st Z,temp
;[addr] = value
st Y,temp1
; rcall delay_10uS
; rcall delay_10uS
; rcall delay_10uS
test_flash_busy:
ld temp,Y
cp temp1,temp
brne test_flash_busy
ret
;******************* TEST COMMAND **********************
get_ver:
ldi ZL,low(reader_version)
ldi ZH,high(reader_version)
ldi XL,card_rece_buffer_low
ldi XH,card_rece_buffer_high
ldi counter1,0x06
get_ver_loop:
lpm
st X+,R0
ld R0,Z+
dec counter1
brne get_ver_loop
ldi temp,cmd_ok
mov cmd_register,temp
ldi counter1,0x06
clr counter2
rcall form_data_to_pc
rjmp all_to_pc
;---------------------------------------------------
rf_card:
ldi ZL,usb_buffer_low
ldi ZH,usb_buffer_high
ldd counter1,Z+6 ;length_low
ldd counter2,Z+5 ;length_high
subi counter1,11 ;delete aa aa aa 96 69 len1 len2 cmd1 cmd2 cmd3 lrc
sbc counter2,zero_register
adiw ZL,10
rcall rw_rfcard
ldi temp,cmd_ok
cp cmd_register,temp
breq rf_card_ok
clr counter1
clr counter2
rf_card_ok:
rcall form_data_to_pc
rjmp all_to_pc
;----------------------------------------------------
download_dictionary:
ldi ZL,usb_buffer_low
ldi ZH,usb_buffer_high
;cmd_data: offset_high,offset_low,length,data
ldd YH,Z+10 ;offset_high
ldd YL,Z+11 ;offset_low
ldd counter1,Z+12 ;data_len
cpi YH, 0x80
brsh error_download_address
cpi counter1,201
brsh error_download_length
cpse YH,zero_register
rjmp write_to_dict
cpse YL,zero_register
rjmp write_to_dict
rcall flash_erase
write_to_dict:
ori YH, 0x80
ldi XL,usb_buffer_low
ldi XH,usb_buffer_high
adiw XL, 13 ;data start
write_data_to_dict:
wdr
ld temp1, X+
rcall flash_write_byte
adiw YL,0x01
dec counter1
brne write_data_to_dict
clr cmd_register
rcall form_data_to_pc
rjmp all_to_pc
error_download_address:
error_download_length:
ret
;---------------------------------------
uart_download_key_table:
ldi ZL,usb_buffer_low
ldi ZH,usb_buffer_high
;cmd_data: offset_high,offset_low,length,data
adiw ZL,10 ;DATA
clr eeprom_addrh
clr eeprom_addrl
ldi counter1,EEP_LONG
write_data_to_eeprom:
ld eeprom_data, Z+
rcall write_eeprom
inc eeprom_addrl
dec counter1
brne write_data_to_eeprom
clr cmd_register
rcall form_data_to_pc
rjmp all_to_pc
;--------------------------------------------
all_to_pc:
enable_uart
ldi ZL,usb_send_low
ldi ZH,usb_send_high
rcall comm_uart_send
cbi d12_rst_addr,d12_rst
ldi YL,usb_buffer_low
ldi YH,usb_buffer_high
ret ;return to uart_rec
;=============================================
check_unicode_gbk:
;input unicode_high,low
;use temp1,temp2,Z
;output unicode_high,low
;check step by step,use 10ms
;table end by 0x0000 0xa1f9
ldi ZH,high(FLASH_UNICODE_START)
ldi ZL,low(FLASH_UNICODE_START)
check_unicode_gbk_start:
wdr
ld temp1,Z+
ld temp,Z+
cpse temp1,unicode_high
rjmp goto_next_item
cpse temp,unicode_low
rjmp goto_next_item
rjmp get_result
goto_next_item:
cpse temp1,zero_register
rjmp goto_next_unicode
cpse temp,zero_register
rjmp goto_next_unicode
;check failure,no word match
;ldi unicode_high, 0x01 ;sendkey a1f9 '※'
;ldi unicode_low, 0x59
rjmp get_result
goto_next_unicode:
ld temp1,Z+
ld temp1,Z+
rjmp check_unicode_gbk_start
get_result:
ld unicode_high,Z+
ld unicode_low, Z+
; subi unicode_high,0xa0 ;for dec input
; subi unicode_low,0xa0
ret
mod_10:
;function:value/10,value%10
;input temp1=value
;use key_bit_counter
;output:key_bit_counter(val/10),temp1(val%10)
clr key_bit_count
sub_next10:
cpi temp,10
brlo goto_result
subi temp,10
inc key_bit_count
rjmp sub_next10
goto_result:
ret
;
/* ***************** code **************** *
turn_on_gbk:
ldi ZH,high(key_table_gbk)
ldi ZL,low(key_table_gbk)
lpm
mov key_value,R0
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ld temp,Z+
lpm
mov key_value,R0
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ld temp,Z+
lpm
mov key_value,R0
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ldi temp1,0xf0
mov key_value,temp1
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ld temp,Z
lpm
mov key_value,R0
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ldi temp1,0xf0
mov key_value,temp1
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ld temp,-Z
lpm
mov key_value,R0
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ldi temp1,0xf0
mov key_value,temp1
rcall send_key_to_pc
ldi temp1,1
rcall delay_mS
ld temp,-Z
lpm
mov key_value,R0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -