📄 simple_piano.bas
字号:
'Program: Simple_piano.bas
'Description: Use Pushbutton unit and speaker unit to build a simple piano
' which plays "Do" note when Button 0 is pressed. Similarly for
' other "Re", "Mi" and "Fa" notes.
Define LOADER_USED 1 'Required for bootloader to program the MCU
' ---[ Ports and Variables initialisation]-------------------------
ADCON1 = 7 'All digital input for Port A
TrisA = %11111111 ' which used for pushbutton
TrisC = %00010000 'Configure I/O pins for Port C.
PortC = %00000000 'Initialise Port C
cl var byte
' ---[ Main Code ]----------------------
Main: 'Label. Main program starts here
BUTTON porta.2,1,255,1,cl,1,playdo 'Check the Button 0. If pressed, then goto playdo
BUTTON porta.3,1,255,1,cl,1,playre 'Similarly do the same check for other buttons
BUTTON porta.4,1,255,1,cl,1,playmi ' i.e. Re, Mi, and Fa
BUTTON porta.5,1,255,1,cl,1,playfa
goto main
playdo:
freqout PortC.5, 500, 1047
goto Main
playre:
freqout PortC.5, 500, 1175
goto Main
playmi:
freqout PortC.5, 500, 1319
goto Main
playfa:
freqout PortC.5, 500, 1396
goto Main
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -