论坛元老
- 积分
- 6661
- 金钱
- 6661
- 注册时间
- 2016-5-29
- 在线时间
- 909 小时
|
include HT68F002.inc
;直接寻址 只能操作BANK0
;IAR0,MP0 只能操作BANK0
;snz z XOR 相等
;snz c SUB有借位,<
ifeq equ snz Z
ifneq equ sz Z
iflt equ snz C
ifgte equ sz C
ds .section 'data'
FLAG DB ?
mystate db ?
mystateN db ?
mystateChangeN db ?
keyState db ?
lkState db ?
TICK EQU FLAG.0
cs .section at 000h 'code'
org 0
jmp reset
org 8
CLR TB0F
SET TICK
RETI
org 12
CLR TB1F
RETI
reset:
clr wdt
call init
call read_eeprom
mov mystate,A
call open_led
call init_timer
mov a,250
mov mystateChangeN,A
mov mystateN,A
set EMI
main:
clr WDT
SNZ TICK
JMP main
clr TICK
call sweep
jmp main
open_led:
CLR PA
mov a,mystate ; if(mystate>3)mystate = 0;
sub a,3h
iflt
clr mystate
mov a,L1
ADD A,mystate
MOV PCL,A
L1:
JMP LEDALLON
JMP LED1ON
JMP LED2ON
RET
LEDALLON:
set PA1
set PA2
ret
LED1ON:
set PA1
RET
LED2ON:
set PA2
RET
init_timer:
MOV A,0C2H
MOV TBC,A
SET TB0E
ret
init:
mov a,0e0h
mov SMOD,A
CLR PA
MOV A,0F9H
MOV PAC,A
MOV A,01H
MOV PAPU,A
ret
read_eeprom:
CLR EEA
MOV A, 040H
MOV MP1, A
MOV A, 01H
MOV BP, A
SET IAR1.1
SET IAR1.0
SZ IAR1.0
JMP $-1
CLR IAR1
CLR BP
MOV A, EED
ret
write_eeprom:
CLR EMI
CLR EEA
MOV A,mystate
MOV EED,A
MOV A,040H
MOV MP1,A
MOV A,1H
MOV BP,A
SET IAR1.3
SET IAR1.2
SZ IAR1.2
JMP $-1
CLR IAR1
CLR BP
SET EMI
ret
sweep:
mov a,PA
and a,01h
mov keyState,A
xor a,lkState
ifneq
jmp Same
mov a,keyState
mov lkState,a
clr mystateN
siza mystateChangeN
jmp $+2
ret
inc mystateChangeN
MOV A,mystateChangeN
XOR A,200
ifeq
JMP N1
CALL write_eeprom
ret
N1:
MOV A,mystateChangeN
xor a,3
ifeq
ret
CALL open_led
ret
Same:
siza mystateN
jmp $+2
ret
inc mystateN
MOV a,mystateN
XOR A,60
ifeq
ret
CLR mystateChangeN
INC mystate
mov a,mystate ; if(mystate>3)mystate = 0;
sub a,3h
SNZ C
clr mystate
ret
|
|