Program Deurbel
Const E4 = 329
Const G4 = 392
Const A4 = 440
Const A4h = 466
Const B4a = 499
Const C5 = 523
Const C5h = 554
Const D5 = 587
Const D5h = 622
Const E5 = 659
Const F5 = 698
Const G5 = 784
Const A5 = 880
Const A5a = 932
Const B5a = 987
Const C6 = 1047
Const D6 = 1175
Const NOTE as WORD [13] = (D5h, D5, D5h,D5, C5,A4h, D5, C5,D5h, G5, C6,B5a, G5)
Const DUR as Word [13] = (250,250,250,250,375,125,250,1000,250,750,500,250,1500)
Const NOTE1 as WORD [13] = ( C5, C5, C5, C5, G4, E5, E5, E5, E5, C5)
Const DUR1 as Word [13] = (500, 200, 200, 500, 700, 500, 200, 200, 500, 750)
Const DLY1 as Byte [13] = ( 15, 15, 15, 15, 0, 0, 15, 15, 15, 0)
Const NOTE2 as WORD [11] = (E5, E5, E5, E5, E5, E5, E5, G5, C5, D5, E5)
Const DUR2 as Word [11] = (250, 250, 500, 250, 250, 500, 250, 250, 250, 250, 750)
Const DLY2 as Byte [11] = ( 15, 15, 100, 15, 15, 150, 0, 0, 0, 0, 0)
Const NOTE3 as WORD [22] = (G4, G4, E5, C5, C5, C5, G4, G4, E5, C5, C5, C5, G4, G4, D5, C5H, D5, C5H, D5, E5, C5)
Const DUR3 as Word [22] = (220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 250, 250, 250, 250, 250, 250, 250, 250, 700)
Const DLY3 as Byte [22] = ( 15, 0, 0, 15, 15, 15, 15, 0, 0, 15, 15, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0)
Const NOTE4 as WORD [23] = ( G5, A5, G5, E5, G5, A5, G5, E5, D6, D6, B5a, C6, C6, G5, A5, A5, C6, B5a, A5, G5, A5, G5, E5)
Const DUR4 as Word [23] = (420, 420, 420, 620, 420, 420, 420, 620, 420, 320, 520, 420, 320, 520, 320, 220, 320, 220, 320, 320, 320, 320, 620)
Const DLY4 as Byte [23] = ( 0, 0, 0, 200, 0, 0, 0, 200, 15, 0, 200, 15, 0, 200, 15, 0, 0, 0, 0, 0, 0, 0, 0)
Const NOTE5 as WORD [16] = ( G4, C5, C5, C5, D5, E5, E5, E5, E5, D5, E5, F5, B4a, D5, C5, C5)
Const DUR5 as Word [16] = (420, 220, 220, 520, 420, 220, 220, 520, 420, 420, 420, 320, 320, 420, 220, 420)
Const DLY5 as Byte [16] = ( 0, 15, 15, 200, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 15, 0)
Const NOTE6 as WORD [30]= ( C5, F5, F5, G5, F5 , E5, D5, D5, D5, G5, G5, A5, G5, F5, E5, C5, C5, A5, A5, A5a, A5, G5, F5, D5, C5, C5, D5, G5, E5, F5)
Const DUR6 as Word [30] = (420, 220, 220, 220, 220, 220, 220, 420, 420, 220, 220, 220, 220, 220, 220, 420, 420, 220, 220, 220, 220, 220, 220, 420, 420, 420, 420, 420, 420, 720)
Const DLY6 as Byte [30] = ( 0, 15, 0, 0, 0, 0, 15, 15, 0, 15, 0, 0, 0, 0, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0)
Const PLUS as byte = 100
Dim Time As Byte[7]
Dim Toon As Byte
Dim Xmas as byte
Dim Switch1 as sbit at PORTA.0
Sub procedure Write_DS3231()
i2c1_Start()
i2c1_Wr(0xD0)
i2c1_Wr(0x00)
i2c1_Repeated_Start()
i2c1_Wr(0xD0)
i2c1_Wr(0x01)
i2c1_Wr(0x31)
i2c1_Wr(0x12)
i2c1_Wr(0x3)
i2c1_Wr(0x01)
i2c1_Wr(0x11)
i2c1_Wr(0x19)
i2c1_Stop()
End Sub
Sub procedure Read_DS3231()
i2c1_Start()
i2c1_Wr(0xD0)
i2c1_Wr(0x00)
i2c1_Repeated_Start()
i2c1_Wr(0xD1)
Time[0] = Bcd2Dec(i2c1_Rd(1))
Time[1] = Bcd2Dec(i2c1_Rd(1))
Time[2] = Bcd2Dec(i2c1_Rd(1) And 0x3F)
Time[3] = Bcd2Dec(i2c1_Rd(1))
Time[4] = Bcd2Dec(i2c1_Rd(1))
Time[5] = Bcd2Dec(i2c1_Rd(1) And 0x7F)
Time[6] = Bcd2Dec(i2c1_Rd(0))
i2c1_Stop()
End Sub
Sub Procedure Midsomer
For Toon = 0 to 12
Sound_Play(Note[Toon], (Dur[Toon] + Plus))
Next Toon
End Sub
Sub Procedure Verjaardag
For Toon = 0 to 9
Sound_Play(Note1[Toon], (Dur1[Toon] + Plus))
VDelay_MS(DLY1[Toon])
Next Toon
End sub
Sub Procedure JingleBells
For Toon = 0 to 10
Sound_Play(Note2[Toon], (Dur2[Toon] + Plus))
VDelay_MS(DLY2[Toon])
Next Toon
End sub
Sub Procedure HoorWieKlopt
For Toon = 0 to 21
Sound_Play(Note3[Toon], (Dur3[Toon] + Plus))
VDelay_MS(DLY3[Toon])
Next Toon
End sub
Sub Procedure StilleNacht
For Toon = 0 to 22
Sound_Play(Note4[Toon], (Dur4[Toon] + Plus))
VDelay_MS(DLY4[Toon])
Next Toon
End sub
Sub Procedure Denneboom
For Toon = 0 to 15
Sound_Play(Note5[Toon], (Dur5[Toon] + Plus))
VDelay_MS(DLY5[Toon])
Next Toon
End sub
Sub Procedure Merry_Xmas
For Toon = 0 to 29
Sound_Play(Note6[Toon], (Dur6[Toon] + Plus))
VDelay_MS(DLY6[Toon])
Next Toon
End sub
main:
ANSELB = 0
ANSELA = 0
TRISA = 0
TRISB = 0
PORTA = %11111111
OSCCON = %11110000
i2c1_init(100000)
Sound_Init(PORTB, 3)
Xmas = 0
While True
if Switch1 = 0 then
delay_ms(20)
if Switch1 = 0 then
Read_DS3231()
Delay_ms(100)
if ((Time[4] > 15) and (Time[5] = 11) Or ((Time[4] < 6) And (Time[5] = 12))) then
HoorWieKlopt()
else
if ((Time[4] = 13) AND (Time[5] = 06) or ((Time[4] = 15) AND (Time[5] = 12))) then
Verjaardag()
else
if (Time[4] = 24)AND (Time[5] = 12) then
StilleNacht()
else
if (Time[4] > 5) AND (Time[4] < 27) AND (Time[5] = 12) then
Xmas = Xmas + 1
If Xmas > 3 then
Xmas = 1
end if
select case Xmas
case 1
JingleBells()
case 2
Denneboom()
case 3
Merry_Xmas()
end select
else
Midsomer()
end if
end if
end if
end if
end if
end if
Delay_ms(100)
Wend
end.