;===============================================================================
; Key-LED
; AT89C2051,12Mhz,1 Key,1 LED
;===============================================================================
KeyPort Bit P3.0 ;0:Pressed
LEDPort EQU P1
;===============================================================================
;===============================================================================
;===============================================================================
Org 0000H
AJmp Main
;===============================================================================
Delay: Mov R6,#0
Delay1: Mov R7,#0
Djnz R7,$
Djnz R6,Delay1
Ret
;-------------------------------------------------------------------------------
FlashLED:
mov LedPort,B
;Clr LEDPort ;Light up
ACall Delay
Mov A,B
Cpl A
mov LedPort,A
;Setb LEDPort ;Dark
ACall Delay
Ret
;===============================================================================
Main: Mov Sp,#07H
Mov A,#1
; Mov LedPort,#00000001b
; Mov A,LedPort
;-------------------------------------------------------------------------------
MainLoop: Jb KeyPort,loop
Acall Delay
Inc A ;add the number of lighting
Acall Delay
;Acall Delay
;Acall Delay
CJNE A,#15,Mainloop
; Acall Delay
clr A
sjmp Mainloop
loop: ;Jb KeyPort,MainLoop ;No Key, Wait
Mov R5,A
Mov B,A
Mov A,LedPort
Clr A
L: ACall FlashLED
Djnz R5,L
Jb KeyPort,$
SJmp MainLoop
;===============================================================================
End