;
;  "main_ags_t.txt" ;     
;
;

; - - - - - - - - - - - - - - - - - - - - - - - - - - -
;      
;  0  ,   OVF0
;    "irq_avr.txt"

; .org OVF0addr ; Timer/Counter0 Overflow
;irq_t0:
;  rjmp test_inp

; - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
;  ,   ,
;     
;
init_ags_t:
 ldi tmp0,1<<CLKPCE
 clr tmp1
 out CLKPR,tmp0
 out CLKPR,tmp1 ;    8 
 out genoutport,tmp1
 ldi tmp0,(1<<g2_out | 1<<g1_out | 1<<g0_out)
 out DDRD,tmp0
 out TCCR0A,tmp1
 out TCCR0B,tmp1
 ldi tmp0,1<<TOIE0
 out TIMSK,tmp0

; 500 Hz *2 = (500*2^24)/31250=536870,912
 ldi tmp0,low(536870)
 ldi tmp1,high(536870)
 ldi tmp2,BYTE3(536870)
 mov kod_f00,tmp0
 mov kod_f01,tmp1
 mov kod_f02,tmp2

; 1500 Hz *2 = (1500*2^24)/31250=1610612,736
 ldi tmp0,low(1610612)
 ldi tmp1,high(1610612)
 ldi tmp2,BYTE3(1610612)
 mov kod_f10,tmp0
 mov kod_f11,tmp1
 mov kod_f12,tmp2

; 15000 Hz *2 = (15000*2^24)/31250=16106127,36
 ldi tmp0,low(16106127)
 ldi tmp1,high(16106127)
 ldi tmp2,BYTE3(16106127)
 mov kod_f20,tmp0
 mov kod_f21,tmp1
 mov kod_f22,tmp2

 ldi g_flags,(1<<g2_on | 1<<g1_on | 1<<g0_on)
 ori g_flags,~(1<<g2_on | 1<<g1_on | 1<<g0_on) ;    

 sei
 ldi tmp0,gen_on
 out TCCR0B,tmp0 ;   
 ret

; - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
;   
;
test_inp:
  in gm_input,genoutport
  and gm_input,g_flags
  out genoutport,gm_input ;   
tone0:
    sbrs g_flags,g0_on
   rjmp tone1
    add bak_00,kod_f00
    adc bak_01,kod_f01
    adc bak_02,kod_f02
    brbc SREG_C,tone1
    sbrs gm_input,g0_out
    sbi genoutport,g0_out
    sbrc gm_input,g0_out
    cbi genoutport,g0_out
tone1:
    sbrs g_flags,g1_on
   rjmp tone2
    add bak_10,kod_f10
    adc bak_11,kod_f11
    adc bak_12,kod_f12
    brbc SREG_C,tone2
    sbrs gm_input,g1_out
    sbi genoutport,g1_out
    sbrc gm_input,g1_out
    cbi genoutport,g1_out
tone2:
    sbrs g_flags,g2_on
   reti
    add bak_20,kod_f20
    adc bak_21,kod_f21
    adc bak_22,kod_f22
    brbc SREG_C,end_tone
    sbrs gm_input,g2_out
    sbi genoutport,g2_out
    sbrc gm_input,g2_out
    cbi genoutport,g2_out
end_tone:
   reti

; ***** END OF FILE ******************************************************
