author | Tero Marttila <terom@fixme.fi> |
Sat, 08 May 2010 20:09:08 +0300 | |
changeset 23 | a6afc0eb347f |
parent 18 | 79b25e81721f |
child 25 | 33496b1a964f |
permissions | -rw-r--r-- |
18 | 1 |
;; |
2 |
;; Driving 7-segment LED displays over SPI |
|
3 |
;; |
|
4 |
||
5 |
; Output Enable control |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
.equ LED7_DDR = DDRB |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
.equ LED7_PORT = PORTB |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
.equ LED7_OE = PORTB1 ; Output Enable (Low) |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
18 | 10 |
; Font for 7-segment display |
11 |
; Includes decimal digits 0-9, hexadecimal digits A-F, and some special chars |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
LED7_Font: |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
.db 0b00111111, 0b00000110 ; 0, 1 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
.db 0b01011011, 0b01001111 ; 2, 3 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
.db 0b01100110, 0b01101101 ; 4, 5 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
.db 0b01111101, 0b00000111 ; 6, 7 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
.db 0b01111111, 0b01100111 ; 8, 9 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
.db 0b01110111, 0b01111100 ; A, b |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
.db 0b00111001, 0b01011110 ; C, d |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
.db 0b01111001, 0b01110001 ; E, f |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
.db 0b10000000, 0b00000000 ; ., |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
|
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
23 |
.equ LED7_0 = 0 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
24 |
.equ LED7_1 = 1 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
25 |
.equ LED7_2 = 2 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
26 |
.equ LED7_3 = 3 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
27 |
.equ LED7_4 = 4 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
28 |
.equ LED7_5 = 5 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
29 |
.equ LED7_6 = 6 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
30 |
.equ LED7_7 = 7 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
31 |
.equ LED7_8 = 8 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
32 |
.equ LED7_9 = 9 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
33 |
.equ LED7_A = 10 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
34 |
.equ LED7_B = 11 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
35 |
.equ LED7_C = 12 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
36 |
.equ LED7_D = 13 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
37 |
.equ LED7_E = 14 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
38 |
.equ LED7_F = 15 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
39 |
.equ LED7_DOT = 16 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
40 |
.equ LED7_EMPTY = 17 |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
|
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
42 |
; output buffer |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
43 |
.set LED7_COUNT = 2 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
44 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
45 |
.dseg |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
46 |
led7_buffer: .byte LED7_COUNT |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
47 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
48 |
.cseg |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
;; Initialize LCD to empty, and enable |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
LED7_Init: |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
52 |
; Setup ENable port |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
sbi LED7_PORT, LED7_OE ; Disabled (Low) |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
sbi LED7_DDR, LED7_OE ; Out |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
55 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
56 |
; Initialize buffer |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
ldi r16, 0b11111111 |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
58 |
sts led7_buffer + 0, r16 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
59 |
sts led7_buffer + 1, r16 |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
; Output |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
62 |
ldi r16, LED7_COUNT |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
63 |
ldi XL, low(led7_buffer + LED7_COUNT) |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
64 |
ldi XH, high(led7_buffer + LED7_COUNT) |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
65 |
rcall SPI_SendBuf |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
|
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
67 |
; Enable output once the initial display has been shifted out |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
cbi LED7_PORT, LED7_OE |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
; Done |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
ret |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
|
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
73 |
LED7_LoadChar: |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
clr r0, 0 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
; Prep address |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
; base addr for font table |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
78 |
ldi ZH, high(2 * LED7_Font) |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
79 |
ldi ZL, low(2 * LED7_Font) |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
; offset |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
82 |
add ZL, r8 |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
adc ZH, r0 |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
; Load char |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
86 |
lpm r8, Z |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
87 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
88 |
; Done |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
89 |
ret |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
90 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
91 |
;; Display a single digit on the display |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
92 |
;; Input: r16, r17 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
93 |
LED7_Show: |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
94 |
mov r8, r16 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
95 |
rcall LED7_LoadChar |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
96 |
mov r16, r8 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
97 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
98 |
mov r8, r16 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
99 |
rcall LED7_LoadChar |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
100 |
mov r16, r8 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
101 |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
102 |
;; Continue |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
103 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
104 |
;; Display a raw segment mask |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
105 |
;; Input: r16, r17 |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
106 |
LED7_ShowRaw: |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
107 |
; Set buffer |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
108 |
sts led7_buffer + 0, r16 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
109 |
sts led7_buffer + 1, r17 |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
110 |
|
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
111 |
; Output |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
112 |
ldi r16, LED7_COUNT |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
113 |
ldi XL, low(led7_buffer + LED7_COUNT) |
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
114 |
ldi XH, high(led7_buffer + LED7_COUNT) |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
115 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
116 |
; Display |
23
a6afc0eb347f
synchronous SPI, two-digit led7
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
117 |
rjmp SPI_SendBuf |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
118 |
|
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
119 |