m820250322006siebensegmentlight.inc


;; (C) David Vajda
;; 2025-03-22
;; siebensegment 1fach klassisch
;.include "m8def.inc"

;ldi r16, HIGH (RAMEND)
;out SPH, r16
;ldi r16, LOW (RAMEND)
;out SPL, r16

inithexout7seg:
push r16
ldi r16, 0xff
out DDRC, r16
out DDRB, r16
ldi r16, 0xff
out DDRD, r16
pop r16
ret

hexoutascii:
push r16
ldi r18, 0b01010101
out PORTD, r18
andi r16, 0b00001111
rcall bcddecode
rcall out7
pop r16
ret

out7:
com r24
out PORTC, r24
sbrs r24, 6
rjmp next
ldi r24, 0x01
out PORTB, r24
rjmp next2
next:
ldi r24, 0x00
out PORTB, r24
next2:
ret

bcddecode:
push r16
push ZH
push ZL
ldi ZH, HIGH (seg7B)
ldi ZL, LOW (seg7B)
;; das stimmte natuerlich nicht mit dem adiw - das ist konstante laut i
inc r16
bcddecodeloop1:
lpm r24, Z+
dec r16
brne bcddecodeloop1
pop ZL
pop ZH
pop r16
ret

sleep:
push r16
push r17
push r18
ldi r16, 0xff
sleeploop1:
ldi r17, 0x0b
sleeploop2:
dec r17
brne sleeploop2
dec r16
brne sleeploop1
pop r18
pop r17
pop r16
ret

seg7: .db 0b00111111, 0b00001100, 0b01011011, 0b01011110, 0b01101100, 0b01110110, 0b01110111, 0b00011100, 0b01111111, 0b01111110, 0b01111101, 0b01100111, 0b00110011, 0b01001111, 0b01110011, 0b01110001
.equ seg7B = seg7*2

; 1 e
; 2 d
; 4 c
; 6 b
; 7 a
; 9 f
; 10 g

; 1 e
; 2 d
; 3 c
; 4 b
; 5 a
; 6 f
; 7 g

;; 0: abcdef 1 2 3 4 5 6      0b 0 0111 111
;; 1: bc 4 3
;; 2: abged 5 4 7 1 2
;; 3: abgcd 5 4 7 3 2
;; 4: fgbc 6 7 4 3
;; 5: afgcd 5 6 7 3 2
;; 6: afgcde 5 6 7 3 2 1
;; 7: abc 5 4 3
;; 8: abcdefg 1 2 3 4 5 6 7
;; 9: abcdfg 2 3 4 5 6 7
;; A: abcefg 3 4 5 6 7
;; b: cdefg 2 3 6 7
;; C: afde: 1 2 5 6
;; d: bcdeg 1 2 3 4 7
;; E: adefg 1 2 5 6 7
;; F: aefg 1 5 6 7

;; 1: bc 3 4                    0b 0 0001 100
;; 2: abged 1 2 4 5 7           0b 0 1011 011
;; 3: abgcd 2 3 4 5 7           0b 0 1011 110
;; 4: fgbc 3 4 6 7              0b 0 1101 100
;; 5: afgcd 2 3 5 6 7           0b 0 1110 110
;; 6: afgcde 1 2 3 5 6 7        0b 0 1110 111
;; 7: abc 3 4 5                 0b 0 0011 100
;; 8: abcdefg 1 2 3 4 5 6 7     0b 0 1111 111
;; 9: abcdfg  2 3 4 5 6 7       0b 0 1111 110


;; A: abcefg 1 3 4 5 6 7        0b 0 1111 101
;; b: cdefg 1 2 3 6 7           0b 0 1100 111
;; C: afde: 1 2 5 6             0b 0 0110 011
;; d: bcdeg 1 2 3 4 7           0b 0 1001 111
;; E: adefg 1 2 5 6 7           0b 0 1110 011
;; F: aefg 1 5 6 7              0b 0 1110 001