led7seg.s
changeset 32 7ceb76b5a104
parent 30 5226e512755c
equal deleted inserted replaced
31:dfb246ecaf23 32:7ceb76b5a104
     1 .nolist
     1 .nolist
     2 .include "m168def.inc"      ; Same family as 328P
     2 .include "m168def.inc"      ; Same family as 328P
     3 .list
     3 .list
     4 
     4 
       
     5 
     5 ;; Interrupt Vector
     6 ;; Interrupt Vector
     6 .org 0x00
     7 .org 0x00
     7         rjmp        init
     8         rjmp        init
     8 
     9 
     9 .org OC1Aaddr
    10 .org OC1Aaddr
    33 
    34 
    34 ;; DIPs
    35 ;; DIPs
    35 .include "dip.inc"
    36 .include "dip.inc"
    36 
    37 
    37 ;; ADC
    38 ;; ADC
       
    39 
       
    40 ; ADC Interrupt handler
       
    41 On_ADC:
       
    42     ; DEBUG
       
    43 		sbi			PIND, PORTD7
       
    44 
       
    45     ; Check timer, from r16
       
    46         rcall       ADC_Read8
       
    47 
       
    48         ldi         r17, 64
       
    49         mul         r16, r17
       
    50         mov         XL, r0
       
    51         mov         XH, r1 
       
    52 
       
    53         rjmp       Timer_Update
       
    54 
       
    55 .set ADC_Handler = On_ADC
       
    56 
    38 .include "adc.inc"
    57 .include "adc.inc"
    39 
    58 
    40 ;; Timer
    59 ;; Timer
    41 .set TIMER0_CB_A = SPI_Update
    60 .set TIMER0_CB_A = SPI_Update
    42 
    61 
    46 .include "delay.inc"
    65 .include "delay.inc"
    47 .include "div.inc"
    66 .include "div.inc"
    48 
    67 
    49 Sleep_ADC:
    68 Sleep_ADC:
    50         ; delay
    69         ; delay
    51         ; rcall       ADC_Read8 
    70         rcall       ADC_Read8 
    52         rcall       DIP_Read8
    71         ; rcall       DIP_Read8
    53         
    72         
    54         ; Sleep for 64 * var timer cycles
    73         ; Sleep for 64 * var timer cycles
    55         ldi         r17, 64
    74         ldi         r17, 64
    56         mul         r16, r17
    75         mul         r16, r17
    57         mov         XL, r0
    76         mov         XL, r0
    59 
    78 
    60         rjmp       Timer_Sleep
    79         rjmp       Timer_Sleep
    61 
    80 
    62 ;; Show value
    81 ;; Show value
    63 Main_ShowValue:
    82 Main_ShowValue:
    64     ; DEBUG
       
    65 		sbi			PIND, PORTD7
       
    66 
       
    67         ; load value to r16
    83         ; load value to r16
    68         ; rcall       DIP_Read8
    84         ; rcall       DIP_Read8
    69         ; rcall       ADC_Read8
    85         rcall       ADC_Read8
    70         rcall       Timer0_Read8
    86         ; rcall       Timer0_Read8
    71 
    87 
    72         ; display from r16
    88         ; display from r16
    73         rcall       LED7_ShowHex
    89         rcall       LED7_ShowHex
    74         
    90         
    75         ; wait
    91         ; wait
   174 _spin_next:
   190 _spin_next:
   175         ; display
   191         ; display
   176         mov         r16, r24
   192         mov         r16, r24
   177         mov         r17, r24
   193         mov         r17, r24
   178         com         r17
   194         com         r17
       
   195         andi        r17, 0b00111111
   179         rcall       LED7_ShowRaw
   196         rcall       LED7_ShowRaw
   180 
   197 
   181         ; delay
   198         ; delay
   182         rcall       Sleep_ADC
   199         rcall       Sleep_ADC
   183         
   200         
   216     ; DEBUG
   233     ; DEBUG
   217         sbi         DDRD, PORTD7
   234         sbi         DDRD, PORTD7
   218         cbi         PORTD, PORTD7
   235         cbi         PORTD, PORTD7
   219 
   236 
   220     ; Run
   237     ; Run
       
   238         rcall       Main_Countup
       
   239         ; rcall       Main_Countdown
   221         ; rcall       Main_ShowValue
   240         ; rcall       Main_ShowValue
   222         rcall       Main_Spin
   241         ; rcall       Main_Spin
   223         ; rcall       Main_Countup
   242         rcall       Main_Blink
   224         ; rcall       Main_Countdown
       
   225         ; rcall       Main_Blink
       
   226 
   243 
   227 end:
   244 end:
   228         rjmp        end
   245         rjmp        end
   229 
   246