From 90a4d4a1353dd7b514fe4ef10c1ed2c6f24cadbe Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Sun, 11 May 2025 22:21:06 +0300 Subject: temp commit --- Makefile | 23 +++++++++++++---------- def.s | 19 +++++++++++++++++++ i2c.s | 15 +++++++++++++++ timer.s | 23 +---------------------- 4 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 def.s create mode 100644 i2c.s diff --git a/Makefile b/Makefile index 6b8f6b4..9bba455 100644 --- a/Makefile +++ b/Makefile @@ -12,25 +12,28 @@ DUDEFLAGS += -c $(PROGRAMMER) -p $(MCU) -P $(MCUPATH) # timer.s file TARGET ?= timer -.PHONY: flash dump-timer clean all - all: $(TARGET).hex +.PHONY: flash dump clean all +.SUFFIXES: + +.PRECIOUS: $(TARGET).o $(TARGET).elf + flash: $(TARGET).hex test $(shell id -u) = 0 $(DUDE) $(DUDEFLAGS) -U flash:w:$< -%.hex: % - $(OBJ)copy -O ihex $< $@ +%.o: %.s + $(AS) -mmcu=$(MCU) -o $@ $< -%: %.o +%.elf: %.o $(LD) $(LDFLAGS) -o $@ $< -%.o: %.s - $(AS) -mmcu=$(MCU) -o $@ $< +%.hex: %.elf + $(OBJ)copy -O ihex $< $@ -dump-%: % - $(OBJ)dump -d timer +dump: $(TARGET).elf + $(OBJ)dump -d clean: - rm *.o *.hex *.elf *.bin timer + $(RM) *.o *.hex *.elf *.bin timer diff --git a/def.s b/def.s new file mode 100644 index 0000000..d4fdd44 --- /dev/null +++ b/def.s @@ -0,0 +1,19 @@ +.equ PINB, 0x03 +.equ DDRB, 0x04 +.equ PORTB, 0x05 +.equ PIND, 0x09 +.equ DDRD, 0x0A +.equ PORTD, 0x0B +.equ TIFR0, 0x15 +.equ ADDR, 0x256 +.equ SPL, 0x3D +.equ SPH, 0x3E +.equ SREG, 0x3F +.equ TCCR0A, 0x0024 +.equ TCCR0B, 0x0025 +.equ TCNT0, 0x0026 +.equ OCR0A, 0x0027 +.equ TIMSK0, 0x006E +.equ STOFL, 0xFF +.equ STOFH, 0x08 +.equ TOIE0, 1 diff --git a/i2c.s b/i2c.s new file mode 100644 index 0000000..83ef974 --- /dev/null +++ b/i2c.s @@ -0,0 +1,15 @@ +i2cwait: + in r17, TWCR + sbrs r17, TWINT + rjmp i2cwait +; r16 : addr +i2cstart: + ldi r17, (1 << TWSTA) | (1 << TWEN) | (1 << TWINT) + out TWCR, r17 + rcall i2cwait + out TWDR, r16 + andi r17, ~(1 << TWSTA) + out TWCR, r17 + rcall i2cwait +; r16: data +writebyte: diff --git a/timer.s b/timer.s index 94e97ae..c62b2b5 100644 --- a/timer.s +++ b/timer.s @@ -1,22 +1,4 @@ -.equ PINB, 0x03 -.equ DDRB, 0x04 -.equ PORTB, 0x05 -.equ PIND, 0x09 -.equ DDRD, 0x0A -.equ PORTD, 0x0B -.equ TIFR0, 0x15 -.equ ADDR, 0x256 -.equ SPL, 0x3D -.equ SPH, 0x3E -.equ SREG, 0x3F -.equ TCCR0A, 0x0024 -.equ TCCR0B, 0x0025 -.equ TCNT0, 0x0026 -.equ OCR0A, 0x0027 -.equ TIMSK0, 0x006E -.equ STOFL, 0xFF -.equ STOFH, 0x08 -.equ TOIE0, 1 +.include "def.s" .equ LOC, 0x128 .equ FREQ, 0x80 @@ -71,7 +53,6 @@ tmrint: eor r20, r20 .stt: sts LOC, r20 -.exit: pop r21 pop r20 pop r19 @@ -94,7 +75,6 @@ main: sts ADDR, r1 rjmp .loop .finloop: - in r13, PINB in r14, PORTB @@ -107,4 +87,3 @@ main: rjmp main - -- cgit v1.2.3-70-g09d2