From b68b15d2018bf8ff9e96afc4df6084c764d0768b Mon Sep 17 00:00:00 2001 From: lucic71 Date: Wed, 3 Jun 2020 17:56:24 +0300 Subject: [PATCH] Started working on 7 segment display --- 7_segment_display/Makefile | 25 +++++++++++++ 7_segment_display/segment.s | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 7_segment_display/Makefile create mode 100644 7_segment_display/segment.s diff --git a/7_segment_display/Makefile b/7_segment_display/Makefile new file mode 100644 index 0000000..5341bcd --- /dev/null +++ b/7_segment_display/Makefile @@ -0,0 +1,25 @@ +BINARY=segment + +AS=avr-as +LD=avr-ld +OBJCOPY=avr-objcopy +AVRDUDE=avrdude + +AVRDUDE_CONFIG=/etc/avrdude.conf + +TTY=/dev/ttyACM0 + +ARCH=atmega328p + +build: + $(AS) -g -mmcu=$(ARCH) -o $(BINARY).o $(BINARY).s + $(LD) -o $(BINARY).elf $(BINARY).o + $(OBJCOPY) -O ihex -R .eeprom $(BINARY).elf $(BINARY).hex + +upload: + $(AVRDUDE) -C $(AVRDUDE_CONFIG) -p $(ARCH) -c arduino -P $(TTY) -b 115200 -D -U flash:w:$(BINARY).hex:i + +run: build upload + +clean: + ls | grep $(BINARY) | grep -v *.s | xargs rm -f -- diff --git a/7_segment_display/segment.s b/7_segment_display/segment.s new file mode 100644 index 0000000..ea78ae8 --- /dev/null +++ b/7_segment_display/segment.s @@ -0,0 +1,72 @@ +; For function calling conventions I will stick to this one: +; http://www.nongnu.org/avr-libc/user-manual/FAQ.html +; (see 'Function call conventions') + +.equ RAMEND, 0x08FF + +.equ SREG, 0x3F +.equ SPL, 0x3D +.equ SPH, 0x3E + +; This memory mappings can be found in iom328p.h header file. + +.equ PORTD, 0x0B +.equ DDRD, 0x0A + +.org 0x0000 + + rjmp INIT + +INIT: + + ; Description: + ; ----------- + ; + ; Reset the system status in SREG, initialize the stack using SPL and + ; SPH and set output PINs on PORTB. We need 7 output PINs for the 7 + ; segment display so we will use DIGITAL PINs 0-6. + + clr r16 + out SREG, r16 + + ldi r16, lo8(RAMEND) + out SPL, r16 + + ldi r16, hi8(RAMEND) + out SPH, r16 + + ldi r16, 0x7F + out DDRD, r16 + +LOOP: + + ; Description: + ; ----------- + ; + ; COUNTER will implement a loop that counts from 0 to 9 and calls the ENCODE + ; subroutine to translate the binary number into a 7 segment displayable + ; number. After the subroutine is finished, WAIT will be called because we + ; want some delay between the numbers. + + clr r16 + +COUNTER: + + mov r24, r16 + call ENCODE + + call WAIT + + inc r16 + cpi r16, 0x0A + brne COUNTER + + rjmp LOOP + +ENCODE: + + ret + +WAIT: + + ret