'Programme Genmel2.bas

define osc 20


include "modedefs.bas"

Adresse		var byte
Codenote	var byte
Note		var byte
Duree		var byte
Dureenote	var word
Freq		var word

INPUT	PORTB.0
INPUT	PORTB.1
OUTPUT	PORTB.6
OUTPUT	PORTB.7

'******************************************************
'* Test ddu mode de fonctionnement:                   *
'* Si PortB.1=1 alors ==> Programmation de la melodie *
'* Si PortB.1=0 alors ==> Execution de la melodie     *
'******************************************************

if portB.1=1 then
                 goto prog
             else
                 goto music
endif

'***************************
'* Execution de la melodie *
'***************************
music:

high portB.6
low  portB.7

pause 1000

Adresse=0

play:

read Adresse,Codenote
read Adresse+1,Duree

if Codenote=0 then goto music

if Duree=255 then Dureenote=4000
if Duree=254 then Dureenote=3000
if Duree=253 then Dureenote=2660
if Duree<=200 then Dureenote=Duree*10

Select Case Codenote
       case 1
            Freq=131
       case 2
            Freq=139
       case 3
            Freq=147
       case 4
            Freq=156
       case 5
            Freq=165
       case 6
            Freq=175
       case 7
            Freq=185
       case 8
            Freq=196
       case 9
            Freq=208
       case 10
            Freq=220
       case 11
            Freq=233
       case 12
            Freq=247

       case 13
            Freq=262
       case 14
            Freq=277
       case 15
            Freq=294
       case 16
            Freq=311
       case 17
            Freq=330
       case 18
            Freq=349
       case 19
            Freq=370
       case 20
            Freq=392
       case 21
            Freq=415
       case 22
            Freq=440
       case 23
            Freq=466
       case 24
            Freq=494

       case 25
            Freq=523
       case 26
            Freq=554
       case 27
            Freq=587
       case 28
            Freq=622
       case 29
            Freq=659
       case 30
            Freq=698
       case 31
            Freq=740
       case 32
            Freq=784
       case 33
            Freq=831
       case 34
            Freq=880
       case 35
            Freq=932
       case 36
            Freq=988

End select

freqout portB.5,Dureenote,Freq

Adresse=Adresse+2

pause 35

goto play

'**********************************************
'* Reception des notes et placement en EEPROM *
'**********************************************
prog:

high portB.7
low  portB.6
recoit:
        serin PORTB.0,T2400,Adresse,Note,Duree
        write Adresse,Note
        write Adresse+1,Duree
        write Adresse+2,0
        write Adresse+3,0
goto recoit

END
