📄 esoua.asm
字号:
LIST P=PIC16C73
#include <P16C73.inc>
;iButton 端口
OW_PORT equ h'0005'
;状态标志字
Flag equ h'0020'
;状态标志位
sendbit equ h'0001'
result equ h'0002'
scl equ h'0003'
sda equ h'0004'
portnum equ h'0021'
deal_cont equ h'0022'
owTouchReset_portnum equ h'0030
owTouchBit_portnum equ h'0031'
owTouchByte_sendbyte equ h'0032'
owTouchByte_i equ h'0033'
owTouchByte_result equ h'0034'
owTouchByte_portnum equ h'0035'
save_kx0 equ h'0040'
save_kx1 equ h'0041'
save_kx2 equ h'0042'
save_kx3 equ h'0043'
save_kx4 equ h'0044'
e2_rd24_buff equ h'0050'
e2_w24_buff equ h'0051'
e2_addrh equ h'0052'
e2_addrl equ h'0053'
e2_rd_buff equ h'0054'
e2_wr_buff equ h'0055'
k_x0 equ h'0000'
k_x1 equ h'0001'
k_x2 equ h'0002'
k_x3 equ h'0003'
k_x4 equ h'0004'
k_y0 equ h'0004'
k_y1 equ h'0005'
k_y2 equ h'0006'
k_y3 equ h'0007'
org 000h
Strat: goto begin
org 0010h
begin: bsf STATUS,RP0 ;设置当前页面为BANK1
movlw 0xff
movwf ADCON1
bcf OPTION_REG,7
bcf STATUS,RP0 ;设置当前页面为BANK0
movlw 0xff
movwf PORTA
movwf PORTC
movlw 0xfc
movwf PORTB
bsf STATUS,RP0 ;设置当前页面为BANK1
movlw 0x00
movwf TRISA
movwf TRISC
movlw 0xf0
movwf TRISB
bcf STATUS,RP0 ;设置当前页面为BANK0
call e2_int
movlw 0xa0
movwf e2_w24_buff
call e2_s24
call e2_w24
bcf PORTC,scl
clrf e2_w24_buff
call e2_w24
movlw 0x41
movwf e2_w24_buff
call e2_w24
bcf PORTC,scl
call e2_s24
movlw 0xa1
movwf e2_w24_buff
call e2_w24
clrf e2_w24_buff
call e2_w24
bcf PORTC,scl
call e2_rd24
call e2_p24
call stop_door
;1
get_key: bcf STATUS,RP0 ;设置当前页面为BANK0
bcf PORTA,k_x3 ;扫描K_X3,open,pw,chk,on
nop
nop
btfsc PORTB,k_y3
;开门键没有按下
goto not_open
;开门键按下
down_open_k: btfss PORTB,k_y3
goto down_open_k ;等待按键抬起
;按键抬起,确定门锁处于位置
bcf PORTC,0
bsf PORTA,k_x3
bcf PORTC,5
bcf PORTA,k_x4
nop
nop
btfsc PORTB,k_y1
;门锁处于关闭状态,执行开锁程序
goto open_now
;门锁处于开启或中间状态,执行闩锁程序
close_now: call close_door ;打开电机,执行关门程序
close_ed: btfss PORTB,k_y1
goto close_ed ;等待门锁到位
call stop_door ;关闭电机
bsf PORTC,5
bsf PORTA,k_x4
bsf PORTC,0
goto get_key
open_now: call open_door ;打开电机,执行开门程序
open_ed: btfss PORTB,k_y2
goto open_ed
call stop_door
bsf PORTC,5
bsf PORTA,k_x4
bsf PORTC,0
goto get_key
;2
not_open: btfsc PORTB,k_y0
;门铃没有按下
goto not_clock
;门铃被按下
down_clock: btfss PORTB,k_y0
goto down_clock ;等待按键抬起
call dool_clock ;执行门铃子程序
goto get_key
;3
not_clock: btfsc PORTB,k_y1
;换钥匙键没有按下
goto not_change_key
;换钥匙键被按下
down_change_key: btfss PORTB,k_y1
goto down_change_key ;等待按键抬起
change_key_now: call rd_ibutton_chanekey ;读取iButton为新钥匙
btfsc PORTB,k_y1 ;按换钥匙键完成换钥匙
goto change_key_now
wait_up_chk: btfss PORTB,k_y1
goto wait_up_chk
goto get_key
not_change_key: goto get_key
open_dool: nop
;开锁子程序
bsf PORTC,0
call open_door
goto get_key
close_dool: nop
;闭锁子程序
bcf PORTC,0
return
dool_clock: nop
;门铃子程序
return
rd_ibutton_chanekey: nop
;读取新钥匙子程序
return
e2_int: bsf STATUS,RP0 ;设置当前页面为BANK1
bcf TRISC,3
bcf TRISC,4
bcf STATUS,RP0 ;设置当前页面为BANK1
bsf PORTC,scl
bsf PORTC,sda
return
e2_s24: bcf PORTC,scl
bsf PORTC,sda
bsf PORTC,scl
nop
nop
bcf PORTC,sda
nop
nop
bcf PORTC,scl
return
e2_p24: bcf PORTC,sda
bsf PORTC,scl
nop
nop
bsf PORTC,sda
return
e2_rd24: bsf PORTC,sda
bsf STATUS,RP0 ;设置当前页面为BANK1
bsf TRISC,sda
bcf STATUS,RP0 ;设置当前页面为BANK1
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop1
bsf e2_rd24_buff,7
goto e2_loop2
e2_loop1: bcf e2_rd24_buff,7
e2_loop2: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop3
bsf e2_rd24_buff,6
goto e2_loop4
e2_loop3: bcf e2_rd24_buff,6
e2_loop4: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop5
bsf e2_rd24_buff,5
goto e2_loop6
e2_loop5: bcf e2_rd24_buff,5
e2_loop6: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop7
bsf e2_rd24_buff,4
goto e2_loop8
e2_loop7: bcf e2_rd24_buff,4
e2_loop8: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop9
bsf e2_rd24_buff,3
goto e2_loop10
e2_loop9: bcf e2_rd24_buff,3
e2_loop10: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop11
bsf e2_rd24_buff,2
goto e2_loop12
e2_loop11: bcf e2_rd24_buff,2
e2_loop12: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop13
bsf e2_rd24_buff,1
goto e2_loop14
e2_loop13: bcf e2_rd24_buff,1
e2_loop14: bcf PORTC,scl
nop
bcf PORTC,scl
btfsc PORTC,sda
goto e2_loop15
bsf e2_rd24_buff,0
goto e2_loop16
e2_loop15: bcf e2_rd24_buff,0
e2_loop16: bcf PORTC,scl
nop
return
e2_w24: btfsc e2_w24_buff,7
goto e2_loop17
bsf PORTC,sda
goto e2_loop18
e2_loop17: bcf PORTC,sda
e2_loop18: bsf STATUS,RP0 ;设置当前页面为BANK1
bsf TRISC,sda
bcf STATUS,RP0 ;设置当前页面为BANK1
bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,6
goto e2_loop19
bsf PORTC,sda
goto e2_loop20
e2_loop19: bcf PORTC,sda
e2_loop20: bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,5
goto e2_loop21
bsf PORTC,sda
goto e2_loop22
e2_loop21: bcf PORTC,sda
e2_loop22: bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,4
goto e2_loop23
bsf PORTC,sda
goto e2_loop24
e2_loop23: bcf PORTC,sda
e2_loop24: bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,3
goto e2_loop25
bsf PORTC,sda
goto e2_loop26
e2_loop25: bcf PORTC,sda
e2_loop26: bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,2
goto e2_loop27
bsf PORTC,sda
goto e2_loop28
e2_loop27: bcf PORTC,sda
e2_loop28: bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,1
goto e2_loop29
bsf PORTC,sda
goto e2_loop30
e2_loop29: bcf PORTC,sda
e2_loop30: bsf PORTC,scl
bcf PORTC,scl
btfsc e2_w24_buff,0
goto e2_loop31
bsf PORTC,sda
goto e2_loop32
e2_loop31: bcf PORTC,sda
e2_loop32: bsf PORTC,scl
bcf PORTC,scl
nop
bsf PORTC,sda
bsf PORTC,scl
return
open_door: bcf STATUS,RP0
bsf PORTB,1
bsf PORTB,3
bcf PORTB,0
bcf PORTB,2
return
close_door:bcf STATUS,RP0
bsf PORTB,0
bsf PORTB,2
bcf PORTB,1
bcf PORTB,3
return
stop_door: bcf STATUS,RP0
bcf PORTB,2
bcf PORTB,3
bsf PORTB,0
bsf PORTB,1
return
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -