led7seg.s
changeset 25 33496b1a964f
parent 23 a6afc0eb347f
child 26 db2ec641c955
equal deleted inserted replaced
24:8100038e3d58 25:33496b1a964f
    33 ;; Timer
    33 ;; Timer
    34 .include "timer.inc"
    34 .include "timer.inc"
    35 
    35 
    36 ;; Utils
    36 ;; Utils
    37 .include "delay.inc"
    37 .include "delay.inc"
    38 
    38 .include "div.inc"
    39 ;; Count down from 9
    39 
       
    40 Sleep_ADC:
       
    41         ; delay
       
    42         rcall       ADC_Read8 
       
    43         
       
    44         ; Sleep for 64 * var timer cycles
       
    45         ldi         r17, 64
       
    46         mul         r16, r17
       
    47         mov         XL, r0
       
    48         mov         XH, r1 
       
    49 
       
    50         rjmp       Timer_Sleep
       
    51 
       
    52 ;; Show ADC value
       
    53 Main_ShowADC:
       
    54         ; load value to r16
       
    55         mov         r16, r10
       
    56         ; rcall       ADC_Read8
       
    57 
       
    58         ; display from r16
       
    59         rcall       LED7_ShowHex
       
    60         
       
    61         ; *g*
       
    62         ldi         XL, 0
       
    63         ldi         XH, 16
       
    64         rcall       Timer_Sleep
       
    65 
       
    66         ; continue
       
    67         rjmp        Main_ShowADC
       
    68 
       
    69 ;; Count down from F
    40 ; Returns once we've hit zero
    70 ; Returns once we've hit zero
    41 Main_Countdown:
    71 Main_Countdown:
    42         ; init from F
    72         ; init from F
    43         ldi         r24, LED7_F
    73         ldi         r24, LED7_F
    44 
    74 
    45 _count_loop:
    75 _count_loop:
    46         ; display
    76         ; display
    47         mov         r16, r24
    77         mov         r16, r24
       
    78         mov         r16, r24
    48         rcall       LED7_Show
    79         rcall       LED7_Show
    49 
    80 
    50         ; exit if zero
    81         ; exit if zero
    51         tst         r24
    82         tst         r24
    52         breq        _count_end
    83         breq        _count_end
    53 
    84 
    54         ; count down
    85         ; count down
    55         dec         r24
    86         dec         r24
    56 
    87 
    57         ; wait...
    88         ; wait...
    58         rcall        Delay_1s
    89         rcall       Sleep_ADC
    59 
    90 
    60         ; next
    91         ; next
    61         rjmp        _count_loop
    92         rjmp        _count_loop
    62 
    93 
    63 _count_end:
    94 _count_end:
       
    95         ; done
       
    96         ret
       
    97 
       
    98 ;; Count up from 00 -> 255
       
    99 ; Returns once done
       
   100 Main_CountUp:
       
   101         ; init from 0
       
   102         ldi         r24, 0
       
   103 
       
   104 _countup_loop:
       
   105         ; display
       
   106         mov         r16, r24
       
   107         rcall       LED7_ShowDec
       
   108 
       
   109         ; wait...
       
   110         rcall       Sleep_ADC
       
   111 
       
   112         ; exit if zero
       
   113         cpi         r24, 255
       
   114         breq        _countup_end
       
   115 
       
   116         ; count up
       
   117         inc         r24
       
   118 
       
   119         ; continue
       
   120         rjmp        _countup_loop
       
   121 
       
   122 _countup_end:
    64         ; done
   123         ; done
    65         ret
   124         ret
    66 
   125 
    67 ;; Blink between dot and empty
   126 ;; Blink between dot and empty
    68 Main_Blink:
   127 Main_Blink:
    69 _blink_loop:
   128 _blink_loop:
    70         ; dot
   129         ; dot
    71         ldi         r16, LED7_DOT
   130         ldi         r16, LED7_DOT
       
   131         ldi         r17, LED7_EMPTY
    72         rcall       LED7_Show
   132         rcall       LED7_Show
    73 
   133 
    74         ; wait...
   134         ; wait...
    75         rcall       Delay_1s
   135         rcall       Sleep_ADC
    76         
   136         
    77         ; empty
   137         ; empty
    78         ldi         r16, LED7_EMPTY
   138         ldi         r16, LED7_EMPTY
       
   139         ldi         r17, LED7_DOT
    79         rcall       LED7_Show
   140         rcall       LED7_Show
    80         
   141         
    81         rcall       Delay_1s
   142         ; wait... 
       
   143         rcall       Sleep_ADC
    82         
   144         
    83         ; loop
   145         ; loop
    84         rjmp        _blink_loop
   146         rjmp        _blink_loop
    85  
   147  
    86 ;; Chase segments
   148 ;; Chase segments
    95         mov         r17, r24
   157         mov         r17, r24
    96         com         r17
   158         com         r17
    97         rcall       LED7_ShowRaw
   159         rcall       LED7_ShowRaw
    98 
   160 
    99         ; delay
   161         ; delay
   100         rcall       ADC_Read8 
   162         rcall       Sleep_ADC
   101         ;mov         r16, r10
   163         
   102 
       
   103         ldi         r17, 64
       
   104         mul         r16, r17
       
   105         mov         XL, r0
       
   106         mov         XH, r1 
       
   107 
       
   108         rcall       Timer_Sleep
       
   109 
       
   110         ; next segment
   164         ; next segment
   111         lsl         r24
   165         lsl         r24
   112         
   166         
   113         ; go back to A if we hit G
   167         ; go back to A if we hit G
   114         sbrc        r24, 6
   168         sbrc        r24, 6
   142     
   196     
   143     ; LCD (requires interrupts, blocks)
   197     ; LCD (requires interrupts, blocks)
   144         rcall       LED7_Init    
   198         rcall       LED7_Init    
   145     
   199     
   146     ; Run
   200     ; Run
   147         ; spin!
   201         rcall       Main_ShowADC
   148         rcall       Main_Spin
   202         ; rcall       Main_Spin
   149         
   203         ; rcall       Main_Countup
   150         ; count!
       
   151         ; rcall       Main_Countdown
   204         ; rcall       Main_Countdown
   152         ; rcall       Main_Blink
   205         ; rcall       Main_Blink
   153 
   206 
   154 end:
   207 end:
   155         rjmp        end
   208         rjmp        end