avr: allow for adjustable timing in simple LED module.

This commit is contained in:
Martin Preuss
2024-10-28 23:44:08 +01:00
parent c5915b5583
commit d28e20b179

View File

@@ -15,6 +15,8 @@
.dseg
ledSimpleTimer: .byte 1
ledSimpleOnTime: .byte 1
ledSimpleOffTime: .byte 1
@@ -40,20 +42,15 @@ LED_SIMPLE_BEGIN:
LedSimple_Init:
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
ldi r16, LED_SIMPLE_ONTIME
sts ledSimpleTimer, r16
rcall LedSimple_SetDefaultTiming ; (R16)
sec
ret
; ---------------------------------------------------------------------------
; LedSimple_Every100ms
; @routine LedSimple_Every100ms @global
;
; IN:
; - nothing
; OUT:
; - nothing
; USED:
; @clobbers r16
LedSimple_Every100ms:
lds r16, ledSimpleTimer
@@ -65,14 +62,53 @@ LedSimple_Every100ms_zero:
rjmp LedSimple_Tick_isOff
; is on
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
ldi r16, LED_SIMPLE_OFFTIME
lds r16, ledSimpleOffTime
rjmp LedSimple_Every100ms_setTimer
LedSimple_Tick_isOff:
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
ldi r16, LED_SIMPLE_ONTIME
lds r16, ledSimpleOnTime
LedSimple_Every100ms_setTimer:
sts ledSimpleTimer, r16
ret
; @end
; ---------------------------------------------------------------------------
; @routine LedSimple_SetDefaultTiming @global
;
; Set default timing for LED.
; @clobbers r16
;
LedSimple_SetDefaultTiming:
ldi r16, LED_SIMPLE_ONTIME
sts ledSimpleOnTime, r16
sts ledSimpleTimer, r16
ldi r16, LED_SIMPLE_OFFTIME
sts ledSimpleOffTime, r16
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
ret
; @end
; ---------------------------------------------------------------------------
; @routine LedSimple_SetFastTiming @global
;
; Set fast blinking timing for LED. Switch LED on.
; @clobbers r16
;
LedSimple_SetFastTiming:
ldi r16, 5
sts ledSimpleOnTime, r16
sts ledSimpleTimer, r16
ldi r16, 3
sts ledSimpleOffTime, r16
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
ret
; @end