This repository has been archived on 2026-07-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
il-clock/src/clockinator.S
T
2026-01-09 11:42:02 +01:00

88 lines
3.0 KiB
ArmAsm

; Registers TODO: use .def for these!!!!
; r16: ISR setup (vct) -> timer0_set (main) -> START_BLINK (loop)
; r17: timer1_set (main) -> timer1_cnt low byte (loop)
; r18: timer1_set (main) -> timer1_cnt high byte (loop)
; r19:
; r20:
.org 0x0000 ; RESET Vector
rjmp main
.org 0x0002 ; INT0 button interrupt (tap tempo)
;rjump tap_tempo --> should have timer0_start --> if timer0_overflow_count=0 start timer (?)
.org 0x0004 ; TIMER0 overflow
rjump timer0_isr
.org 0x0006 ; TIMER1_COMPA
rjmp timer1_isr
.org 0x0012 ; TIMER0_COMPA
rjmp stop_blink
.dseg
timer0_overflow_count: .byte 1
.cseg
clr r0
sts timer0_overflow_count, r0
#define __SFR_OFFSET 0
#include <avr/io.h>
#include "led.inc"
#include "timer.inc"
;#include "bpm.inc"
;#include "midi.inc"
.global main
main:
ldi r16, lo8(RAMEND)
out SPL, r0 ; Setup stack pointer LOW
ldi r16, hi8(RAMEND)
out SPH, r0 ; Setup stack pointer HIGH
sei ; Global interrupt flag
;cbi DDRB, PB1 ; Set EC11 clockwise on PB5 as input
;cbi DDRB, PB2 ; Set EC11 counter-clockwise on PB3 as input
;cbi DDRB, PB5 ; Set EC11 button (555 square wave) on PB4 as input
sbi DDRB, PB0 ; Set led on PB0 as output
;ldi r26, 60 ; Default BPM //TODO: save to eeprom not register, on runtime also ldi on r24 register
rcall timer0_set
;rcall timer1_set
; loop: calculate tempo (high priority!) and save, led blinking, segment led writing
loop:
;ldi r24, 30 ; Load current BPM to register //NOTE: hardcoded temporary
; TODO: compare two registers (current bpm and previous bpm)
;rcall tempo_calc ; CHANGE: if BPM changed then rcall BPM calculation function else skip because ticks tempo is the value already in [OCR1C]
; if this BPM != previous BPM then load this to another register (will be used as the 'previous register')
; final result stored in OCR1C as ticks
; TODO: look if there are alternatives to rcall
;rcall midi_send ; Send MIDI ping
; if midi clock then after do:
; SOME CPI HERE
brne segment_led
START_BLINK ; Macro for inlining blink start logic
rjmp segment_led ; Output current BPM to 3-digit 7-segment LED [r24]
; sleep when BPM is stabilized (whenever BPM calculation are not being done) and outside of midi send
; to do this explore MCUCR register, it can do a lot of stuff
rjmp loop
; TODO: move to separate file
; keep as subroutine as it's called in two parts in the code
; or it can create issues with compiler
segment_led:
rjmp loop