Compare commits
5 Commits
6b696180d2
...
119942f88e
Author | SHA1 | Date |
---|---|---|
lucic71 | 119942f88e | |
lucic71 | 10f12f31cd | |
lucic71 | 0025446b12 | |
lucic71 | 09efd45646 | |
lucic71 | 91cbd23255 |
|
@ -0,0 +1,35 @@
|
|||
BINARY=lcd
|
||||
|
||||
AS=avr-as
|
||||
LD=avr-ld
|
||||
OBJCOPY=avr-objcopy
|
||||
GDB=avr-gdb
|
||||
|
||||
AVRDUDE=avrdude
|
||||
AVRDUDE_CONFIG=/etc/avrdude.conf
|
||||
|
||||
TTY=/dev/ttyACM0
|
||||
|
||||
ARCH=atmega328p
|
||||
|
||||
SIMAVR=simavr
|
||||
|
||||
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
|
||||
|
||||
sim:
|
||||
$(SIMAVR) -m $(ARCH) $(BINARY).elf -g
|
||||
|
||||
debug:
|
||||
$(GDB) $(BINARY).elf
|
||||
|
||||
|
||||
run: build upload
|
||||
|
||||
clean:
|
||||
ls | grep $(BINARY) | grep -v *.s | xargs rm -f --
|
|
@ -0,0 +1,55 @@
|
|||
.equ RAMEND, 0x08FF
|
||||
|
||||
.equ SREG, 0x3F
|
||||
.equ SPL, 0x3D
|
||||
.equ SPH, 0x3E
|
||||
|
||||
.equ PORTD, 0x0B
|
||||
.equ DDRD, 0x0A
|
||||
|
||||
.equ PORTB, 0x05
|
||||
.equ DDRB, 0x04
|
||||
|
||||
.equiv PINCONFIG, 24
|
||||
|
||||
.org 0x0000
|
||||
|
||||
INIT_MEM:
|
||||
|
||||
; Description:
|
||||
; -----------
|
||||
;
|
||||
; Reset the system status in SREG, initialize the stack using SPL and
|
||||
; SPH and set output PINs on PORTB.
|
||||
;
|
||||
; Pins used for DATA will be DIGITAL PIN 1-7 from PORTD and DIGITAL PIN 8
|
||||
; from PORTB.
|
||||
;
|
||||
; Pins used for REGISTER SELECT, READ/WRITE and ENABLE are DIGITAL PINS
|
||||
; 10, 11, respectively 12 from PORTB.
|
||||
|
||||
clr r16
|
||||
out SREG, r16
|
||||
|
||||
ldi r16, lo8(RAMEND)
|
||||
out SPL, r16
|
||||
|
||||
ldi r16, hi8(RAMEND)
|
||||
out SPH, r16
|
||||
|
||||
ldi r16, 0xFE
|
||||
out DDRD, r16
|
||||
|
||||
ldi r16, 0x1C
|
||||
out DDRB, r16
|
||||
|
||||
INIT_LCD:
|
||||
|
||||
ldi PINCONFIG, 0x10
|
||||
out PORTB, PINCONFIG
|
||||
|
||||
ldi PINCONFIG, 0x70
|
||||
out PORTD, PINCONFIG
|
||||
|
||||
MAIN:
|
||||
rjmp MAIN
|
|
@ -8,4 +8,4 @@ disass
|
|||
end
|
||||
|
||||
# Here you can put a breakpoint to skip some code
|
||||
b ENCODE
|
||||
b COMPUTED
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 755 KiB |
|
@ -0,0 +1,22 @@
|
|||
7 SEGMENT DISPLAY
|
||||
|
||||
segment.s implements the logic behind displaying numbers between 0 and 9 on
|
||||
a 7 segment display. The PIN configuration is the following:
|
||||
|
||||
* a - DIGITAL PIN 0
|
||||
* b - DIGITAL PIN 1
|
||||
* c - DIGITAL PIN 2
|
||||
* d - DIGITAL PIN 3
|
||||
* e - DIGITAL PIN 4
|
||||
* f - DIGITAL PIN 5
|
||||
* d - DIGITAL PIN 6
|
||||
|
||||
All these PINs are connected on PORTD, so we need to keep that in mind when
|
||||
writing our output to the correct PORT.
|
||||
|
||||
The boolean formulas used to configure the PINs are calcualted using
|
||||
Karnaugh Diagrams.
|
||||
|
||||
As a final word, don't forget to add resistors in series with each display
|
||||
PIN, on the breadboard, because I forgot to do so and I completely screwed
|
||||
a display.
|
|
@ -13,22 +13,22 @@
|
|||
.equ PORTD, 0x0B
|
||||
.equ DDRD, 0x0A
|
||||
|
||||
; Aliases for registers. It is easier to develop the logic this way.
|
||||
; Aliases for registers. ABIT, BBIT, CBIT, DBIT contain the bits in the binary
|
||||
; representation of numbers displayed on the 7 segment display. A is the MSB
|
||||
; and D is the LSB. RESULT, TEMP1 and EOREG are registers used when computing
|
||||
; the boolean functions for each PIN. PINCONFIG is the register that decides
|
||||
; which PINs are set when sending voltage to the 7 segment display.
|
||||
|
||||
.equiv ABIT, 17
|
||||
.equiv BBIT, 18
|
||||
.equiv CBIT, 19
|
||||
.equiv DBIT, 20
|
||||
|
||||
.equiv RESULT, 21
|
||||
.equiv TEMP1, 22
|
||||
.equiv TEMP2, 23
|
||||
|
||||
; Aliases for PINs connected to the 7 segment display. These are the
|
||||
; values written in PORTD. DIGITAL PINs 0-6 are connected to PINs a-g
|
||||
; of the 7 segment display.
|
||||
|
||||
; TO BE IMPLEMENTED
|
||||
.equiv EOREG, 23
|
||||
|
||||
.equiv PINCONFIG, 30
|
||||
|
||||
.org 0x0000
|
||||
|
||||
|
@ -82,11 +82,22 @@ COUNTER:
|
|||
|
||||
ENCODE:
|
||||
|
||||
; Reset PINCONFIG and RESULT registers.
|
||||
|
||||
clr PINCONFIG
|
||||
clr RESULT
|
||||
|
||||
; Output a blank screen to put some delay between digits, it looks smoother
|
||||
; this way.
|
||||
|
||||
out PORTD, PINCONFIG
|
||||
call WAIT
|
||||
|
||||
; Description:
|
||||
; -----------
|
||||
;
|
||||
; To represent a digit we will use a 4 bit number looking like this DCBA
|
||||
; (A is the LSB and D is the MSB). The equations for the 7 segment display
|
||||
; To represent a digit we will use a 4 bit number looking like this ABCD
|
||||
; (A is the MSB and D is the LSB). The equations for the 7 segment display
|
||||
; PINs are the following, they can be easily computed using Karnaugh
|
||||
; Diagrams:
|
||||
;
|
||||
|
@ -94,40 +105,52 @@ ENCODE:
|
|||
; b = !B + !C!D + CD
|
||||
; c = B + !C + D
|
||||
; d = !B!D + C!D + B!CD + !BC + A
|
||||
; e = !b!d + C!D
|
||||
; e = !B!D + C!D
|
||||
; f = A + !C!D + B!C + B!D
|
||||
; g = A + B!C + !BC + C!D
|
||||
;
|
||||
; Each PIN equation will be computed in r21 and sent to its corresponding
|
||||
; Each PIN equation will be computed in RESULT and sent to its corresponding
|
||||
; PIN. Other registers will be used to extract the bits from the binary
|
||||
; number and to perform logic operations.
|
||||
|
||||
mov ABIT, r24
|
||||
andi ABIT, 0x01
|
||||
|
||||
mov BBIT, r24
|
||||
asr BBIT
|
||||
andi BBIT, 0x01
|
||||
mov DBIT, r24
|
||||
andi DBIT, 0x01
|
||||
|
||||
mov CBIT, r24
|
||||
asr CBIT
|
||||
asr CBIT
|
||||
andi CBIT, 0x01
|
||||
|
||||
mov DBIT, r24
|
||||
asr DBIT
|
||||
asr DBIT
|
||||
asr DBIT
|
||||
mov BBIT, r24
|
||||
asr BBIT
|
||||
asr BBIT
|
||||
andi BBIT, 0x01
|
||||
|
||||
mov ABIT, r24
|
||||
asr ABIT
|
||||
asr ABIT
|
||||
asr ABIT
|
||||
|
||||
; After shifting each bit in its corresponding register, clear carry flag
|
||||
; because we will perform multiple ROL's and don't want any additional
|
||||
; bit coming from Carry in RESULT.
|
||||
|
||||
clc
|
||||
|
||||
; EOREG will be used for eor'ing with register TEMP1 or RESULT
|
||||
; It is equivalent with flipping the bit in TEMP1 or RESULT.
|
||||
|
||||
ldi EOREG, 0x01
|
||||
|
||||
; Compute a. Steps:
|
||||
;
|
||||
; 1. Move A in RESULT and perform OR with C
|
||||
; 2. Move B in TEMP1 and perform AND with B
|
||||
; 3. Perform OR between (A + C) and BD
|
||||
; 4. Move B in TEMP1, perform or with D and negate the result (!B!D = !(B + D))
|
||||
; (to negate all the bits we will use exclusive or between the register
|
||||
; and the value 0xFF)
|
||||
; 5. Perform OR between (A + C + BD) and !B!D
|
||||
; 1. Move A in RESULT
|
||||
; 2. Perform RESULT = RESULT + C
|
||||
; 3. Compute DB using TEMP1 and perform RESULT = RESULT + BD
|
||||
; 4. Compute !D!B = !(D + B) using TEMP1 and EOREG and perform
|
||||
; RESULT = RESULT + !B!D.
|
||||
; 5. Write RESULT to DIGITAL PIN 0
|
||||
|
||||
COMPUTEA:
|
||||
|
||||
mov RESULT, ABIT
|
||||
|
||||
|
@ -139,13 +162,222 @@ ENCODE:
|
|||
|
||||
mov TEMP1, BBIT
|
||||
or TEMP1, DBIT
|
||||
ldi TEMP2, 0xFF
|
||||
eor TEMP1, TEMP2
|
||||
andi TEMP1, 0x01
|
||||
and RESULT, TEMP1
|
||||
eor TEMP1, EOREG
|
||||
or RESULT, TEMP1
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
; Compute b. Steps:
|
||||
;
|
||||
; 1. Move B in RESULT and invert the bits.
|
||||
; 2. Compute !C!D using TEMP1 and EOREG and perform RESULT = RESULT + !C!D
|
||||
; 3. Compute CD using TEMP1 and perform RESULT = RESULT + CD
|
||||
; 4. Write RESULT to DIGITAL PIN 1
|
||||
|
||||
COMPUTEB:
|
||||
|
||||
mov RESULT, BBIT
|
||||
eor RESULT, EOREG
|
||||
|
||||
mov TEMP1, CBIT
|
||||
or TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, CBIT
|
||||
and TEMP1, DBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
rol RESULT
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
; Compute c. Steps:
|
||||
;
|
||||
; 1. Move B in RESULT
|
||||
; 2. Perform RESULT = RESULT + !C
|
||||
; 3. Perform RESULT = RESULT + D
|
||||
; 4. Write RESULT to DIGITAL PIN 2
|
||||
|
||||
COMPUTEC:
|
||||
|
||||
mov RESULT, BBIT
|
||||
|
||||
mov TEMP1, CBIT
|
||||
eor TEMP1, EOREG
|
||||
or RESULT, TEMP1
|
||||
|
||||
or RESULT, DBIT
|
||||
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
; Compute d. Steps:
|
||||
;
|
||||
; 1. Move A int RESULT
|
||||
; 2. Perform RESULT = RESULT + !B!D
|
||||
; 3. Perform RESULT = RESULT + C!D
|
||||
; 4. Perform RESULT = RESULT + B!CD
|
||||
; 5. Perform RESULT = RESULT + !BC
|
||||
; 6. Write RESULT to DIGITAL PIN 3
|
||||
|
||||
COMPUTED:
|
||||
|
||||
mov RESULT, ABIT
|
||||
|
||||
mov TEMP1, BBIT
|
||||
or TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, CBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, CBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, BBIT
|
||||
and TEMP1, DBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, BBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, CBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
; Compute e. Steps:
|
||||
;
|
||||
; 1. Compute RESULT = C!D
|
||||
; 2. Compute RESULT = RESULT + !B!D
|
||||
; 3. Write RESULT to DIGITAL PIN 4
|
||||
|
||||
COMPUTEE:
|
||||
|
||||
mov RESULT, DBIT
|
||||
eor RESULT, EOREG
|
||||
and RESULT, CBIT
|
||||
|
||||
mov TEMP1, BBIT
|
||||
or TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
or RESULT, TEMP1
|
||||
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
; Compute f. Steps:
|
||||
;
|
||||
; 1. Compute RESULT = A
|
||||
; 2. Compute RESULT = RESULT + !C!D
|
||||
; 3. Compute RESULT = RESULT + B!C
|
||||
; 4. Compute RESULT = RESULT + B!D
|
||||
; 5. Write RESULT to DIGITAL PIN 5
|
||||
|
||||
COMPUTEF:
|
||||
|
||||
mov RESULT, ABIT
|
||||
|
||||
mov TEMP1, CBIT
|
||||
or TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, CBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, BBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, BBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
; Compute g. Steps:
|
||||
;
|
||||
; 1. Compute RESULT = B!C
|
||||
; 2. Compute RESULT = RESULT + !BC
|
||||
; 3. Compute RESULT = RESULT + C!D
|
||||
; 4. Compute RESULT = RESULT + A
|
||||
; 5. Write RESULT to DIGITAL PIN 6
|
||||
|
||||
COMPUTEG:
|
||||
|
||||
mov RESULT, CBIT
|
||||
eor RESULT, EOREG
|
||||
and RESULT, BBIT
|
||||
|
||||
mov TEMP1, BBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, CBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
mov TEMP1, DBIT
|
||||
eor TEMP1, EOREG
|
||||
and TEMP1, CBIT
|
||||
or RESULT, TEMP1
|
||||
|
||||
or RESULT, ABIT
|
||||
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
rol RESULT
|
||||
|
||||
or PINCONFIG, RESULT
|
||||
|
||||
WRITE_RESULT:
|
||||
|
||||
out PORTD, PINCONFIG
|
||||
|
||||
ret
|
||||
|
||||
WAIT:
|
||||
|
||||
; Description
|
||||
; -----------
|
||||
;
|
||||
; Loop 0x{r17, r18, r19} times (for example 0x300000) times because the
|
||||
; internal clock of the board is to fast and the digits cannot be seen.
|
||||
; We know that 0x400000 iterations take approximately 0.7s so we can make
|
||||
; further calcualtions based on this (or by looking in the instruction set
|
||||
; at the clock cycles taken by each instruction used in the loop).
|
||||
|
||||
ldi r17, 0x30
|
||||
ldi r18, 0x00
|
||||
ldi r19, 0x00
|
||||
|
||||
_WAIT:
|
||||
|
||||
dec r19
|
||||
brne _WAIT
|
||||
|
||||
dec r18
|
||||
brne _WAIT
|
||||
|
||||
dec r17
|
||||
brne _WAIT
|
||||
|
||||
ret
|
||||
|
|
Loading…
Reference in New Issue