bellPin Alias PortB.3 freq Alias k note Alias k Const C=262% Const D=294% Const E=330% Const F=349% Const G=392% Const A=440% Const B=494% Const c=523% Const d=587% Const e=659% Const f=698% Const g=784% Const R=1% Dim ocr As Long Dim timer1_toggle_count As Long Dim duration As Long On COMPARE1A TIMER1_COMPA_vect Config bellPin=Output TCCR1A=0 TCCR1B=Bits(WGM12,CS10) Enable Interrupts Do Restore NOTES Do Read note If note=0 Then Exit Do Else If note=R Then Else Gosub tone End If Waitms 330 End If Loop Waitms 2400 Loop End tone: ocr=_XTAL/freq ocr=Int(ocr/2) ocr=ocr-1 If ocr>&hffff Then ocr=_XTAL/freq ocr=Int(ocr/2) ocr=ocr/64 ocr=ocr-1 TCCR1B=Bits(WGM12,CS11,CS10) Else TCCR1B=Bits(WGM12,CS10) End If timer1_toggle_count=freq*2 timer1_toggle_count=timer1_toggle_count*300 timer1_toggle_count=timer1_toggle_count/1000 OCR1A=ocr TIMSK.OCIE1A=1 Return TIMER1_COMPA_vect: If timer1_toggle_count=0 Then TIMSK=0 bellPin=0 Else PINB.3=1 timer1_toggle_count=timer1_toggle_count-1 End If Return NOTES: Data R,D,D,B,A,G,D,R, R,D,D,B,A,G,E,R, R,E,E,c,B,A,F,R, R,d,d,d,c,A,B,R Data R,D,D,B,A,G,D,R, R,D,D,B,A,G,E,R, R,E,E,c,B,A,d,d, d,d,e,d,c,A,G,R, d,R Data B,B,B,R, B,B,B,R, B,d,G,A,B,R,R,R, c,c,c,c,c,B,B,B, B,A,A,B,A,R, d,R Data B,B,B,R, B,B,B,R, B,d,G,A,B,R,R,R, c,c,c,c,c,B,B,B, d,d,c,A,G,R, g,R,0%