led7seg.s
changeset 6 88c930373d62
parent 4 b45780fbd7e8
child 7 697ea917c901
equal deleted inserted replaced
5:7feeaeb473b5 6:88c930373d62
   161         add         ZL, r16
   161         add         ZL, r16
   162         adc         ZH, r0
   162         adc         ZH, r0
   163 
   163 
   164     ; Load char
   164     ; Load char
   165         lpm         r16, Z
   165         lpm         r16, Z
   166 
   166     
       
   167     ;; Continue
       
   168 
       
   169 ;; Display a raw segment mask
       
   170 ;;  Input: r16
       
   171 LCD_ShowRaw:
   167     ; Invert
   172     ; Invert
   168         com         r16
   173         com         r16
   169 
   174 
   170     ; Display
   175     ; Display
   171         rcall        SPI_Send
   176         rjmp        SPI_Send
   172     
       
   173     ; Done
       
   174         ret
       
   175 
   177 
   176 ;; Delay for approx. 1s
   178 ;; Delay for approx. 1s
   177 Delay_1s:
   179 Delay_1s:
   178         ; 20 * 255 * 255 = 1.3M cycles
   180         ; 20 * 255 * 255 = 1.3M cycles
   179         ldi         r20, 40
   181         ldi         r20, 40
   188         dec         r20
   190         dec         r20
   189         brne        delay
   191         brne        delay
   190 
   192 
   191         ret
   193         ret
   192 
   194 
       
   195 ;; Count down from 9
       
   196 ; Returns once we've hit zero
       
   197 Main_Countdown:
       
   198         ; init from 9
       
   199         ldi         r24, LCD_9
       
   200 
       
   201 loop:
       
   202         ; display
       
   203         mov         r16, r24
       
   204         rcall       LCD_Show
       
   205 
       
   206         ; exit if zero
       
   207         tst         r24
       
   208         ret
       
   209 
       
   210         ; count down
       
   211         dec         r24
       
   212 
       
   213         ; wait...
       
   214         rcall        Delay_1s
       
   215 
       
   216         ; next
       
   217         rjmp        loop
       
   218 
       
   219 ;; Blink between dot and empty
       
   220 Main_Blink:
       
   221 _blink_loop:
       
   222         ; dot
       
   223         ldi         r16, LCD_DOT
       
   224         rcall       LCD_Show
       
   225 
       
   226         ; wait...
       
   227         rcall       Delay_1s
       
   228         
       
   229         ; empty
       
   230         ldi         r16, LCD_EMPTY
       
   231         rcall       LCD_Show
       
   232         
       
   233         rcall       Delay_1s
       
   234         
       
   235         ; loop
       
   236         rjmp        _blink_loop
       
   237  
       
   238 ;; Chase segments
       
   239 Main_Spin:
       
   240 _spin_init:
       
   241         ; init from top
       
   242         ldi         r24, 0b00000001 
       
   243 
       
   244 _spin_next:
       
   245         ; display
       
   246         mov         r16, r24
       
   247         rcall       LCD_ShowRaw
       
   248 
       
   249         ; wait
       
   250         rcall       Delay_1s
       
   251 
       
   252         ; next segment
       
   253         lsl         r24
       
   254         
       
   255         ; go back to A if we hit G
       
   256         sbrc        r24, 6
       
   257         rjmp        _spin_init
       
   258 
       
   259         rjmp        _spin_next
   193 
   260 
   194 Main:
   261 Main:
   195 init:
   262 init:
   196     ; Stack
   263     ; Stack
   197         ldi         r16, high(RAMEND)
   264         ldi         r16, high(RAMEND)
   205     ; SPI
   272     ; SPI
   206         rcall       SPI_Init
   273         rcall       SPI_Init
   207     
   274     
   208     ; LCD (requires interrupts)
   275     ; LCD (requires interrupts)
   209         rcall       LCD_Init    
   276         rcall       LCD_Init    
   210 
   277     
   211 ;; Count down from 9
   278     ; Run
   212 count:
   279         ; spin!
   213         ; init from 9
   280         rcall       Main_Spin
   214         ldi         r24, LCD_9
       
   215 
       
   216 loop:
       
   217         ; display
       
   218         mov         r16, r24
       
   219         rcall       LCD_Show
       
   220 
       
   221         ; exit if zero
       
   222         tst         r24
       
   223         breq        blink
       
   224 
       
   225         ; count down
       
   226         dec         r24
       
   227 
       
   228         ; wait...
       
   229         rcall        Delay_1s
       
   230 
       
   231         ; next
       
   232         rjmp        loop
       
   233    
       
   234 ;; Blink between dot and empty
       
   235 blink:
       
   236         rcall       Delay_1s
       
   237         
       
   238         ; dot
       
   239         ldi         r16, LCD_DOT
       
   240         rcall       LCD_Show
       
   241 
       
   242         ; wait...
       
   243         rcall       Delay_1s
       
   244         
       
   245         ; empty
       
   246         ldi         r16, LCD_EMPTY
       
   247         rcall       LCD_Show
       
   248         
       
   249         ; loop
       
   250         rjmp        blink
       
   251 
   281 
   252 end:
   282 end:
   253         rjmp        end
   283         rjmp        end
   254 
   284