led7seg.inc
author Tero Marttila <terom@fixme.fi>
Sat, 08 May 2010 20:07:18 +0300
changeset 21 95549ce0e3da
parent 18 79b25e81721f
child 23 a6afc0eb347f
permissions -rw-r--r--
timer: try and actually sleep
;;
;; Driving 7-segment LED displays over SPI
;;

; Output Enable control
.equ LED7_DDR    = DDRB
.equ LED7_PORT   = PORTB
.equ LED7_OE     = PORTB1                ; Output Enable (Low)

; Font for 7-segment display
; Includes decimal digits 0-9, hexadecimal digits A-F, and some special chars
LED7_Font:
.db     0b00111111, 0b00000110      ; 0, 1
.db     0b01011011, 0b01001111      ; 2, 3
.db     0b01100110, 0b01101101      ; 4, 5
.db     0b01111101, 0b00000111      ; 6, 7
.db     0b01111111, 0b01100111      ; 8, 9
.db     0b01110111, 0b01111100      ; A, b
.db     0b00111001, 0b01011110      ; C, d
.db     0b01111001, 0b01110001      ; E, f
.db     0b10000000, 0b00000000      ; ., 

;.db     0b00111111,     ; 0
;        0b00000110,     ; 1
;        0b01011011,     ; 2
;        0b01001111,     ; 3
;        0b01100110,     ; 4
;        0b01101101,     ; 5
;        0b01111101,     ; 6
;        0b00000111,     ; 7
;        0b01111111,     ; 8
;        0b01100111,     ; 9
;        0b10000000,     ; .
;        0b01000000      ; 

.equ LED7_0      = 0
.equ LED7_1      = 1
.equ LED7_2      = 2
.equ LED7_3      = 3
.equ LED7_4      = 4
.equ LED7_5      = 5
.equ LED7_6      = 6
.equ LED7_7      = 7
.equ LED7_8      = 8
.equ LED7_9      = 9
.equ LED7_A      = 10
.equ LED7_B      = 11
.equ LED7_C      = 12
.equ LED7_D      = 13
.equ LED7_E      = 14
.equ LED7_F      = 15
.equ LED7_DOT    = 16
.equ LED7_EMPTY  = 17

;; Initialize LCD to empty, and enable
LED7_Init:
    ; Setup ENable port
        sbi         LED7_PORT, LED7_OE    ; Disabled (Low)
        sbi         LED7_DDR, LED7_OE     ; Out

        ; empty
        ldi         r16, 0b11111111

    ; Output
        rcall       SPI_SendRecv
        rcall       SPI_Wait

    ; Enable
        cbi         LED7_PORT, LED7_OE

    ; Done
        ret

;; Display a single digit on the display
;;  Input: r16
LED7_Show:
        clr         r0, 0

    ; Prep address
        ; base addr for font table
        ldi         ZH, high(2*LED7_Font)
        ldi         ZL, low(2*LED7_Font)
        
        ; offset
        add         ZL, r16
        adc         ZH, r0

    ; Load char
        lpm         r16, Z
    
    ;; Continue

;; Display a raw segment mask
;;  Input: r16
LED7_ShowRaw:
    ; Invert
        ; com         r16

    ; Display
        rjmp        SPI_SendRecv