📄 piano.c
字号:
//Piano.c
//
//Body: HT48C50-1
//Mask option
//BZ/BZB : All Disable
//the others use the default value
#include <ht48c50-1.h>
#pragma vector isr_4 @ 0x4
#pragma vector isr_8 @ 0x8
#pragma vector isr_c @ 0xc
//ISR for safequard
void isr_4(){} // external ISR
void isr_8(){} // timer/event 0
//initialize registers for safeguard
void safeguard_init(){
_intc = 0;
_tmr0c = 0;
_tmr0 = 0;
_tmr1c = 0;
_tmr1h = 0;
_tmr1l = 0;
_pac = 0xff;
_pbc = 0xff;
_pcc = 0xff;
_pdc = 0xff;
}
#define _tmr1c4 _11_4 //timer1 enable bit
const unsigned char frq[16] = {
0x21, 0xfe, 0x58, 0xfe, 0x84, 0xfe, 0x99, 0xfe,
0xc1, 0xfe, 0xe3, 0xfe, 0x2, 0xff, 0x11, 0xff};
unsigned char frq_idx;
void initial();
void wait_key_press();
void wait_key_release();
void start_sound();
void stop_sound();
void main(){
safeguard_init();
initial();
while(1){
wait_key_press();
start_sound();
wait_key_release();
stop_sound();
}
}
void wait_key_press(){
unsigned char i, key;
key = 0;
while(!key)
key = ~_pa;
for(i=0; i<8; i++){
if (key & 0x1){
frq_idx = i << 1;
break;
}
key >>= 1;
}
}
void wait_key_release(){
unsigned char key;
key = 1;
while(key)
key = ~_pa;
}
void start_sound(){
_intc = 9; //enable timer1
_tmr1c = 0x80; //timer mode
_tmr1l = frq[frq_idx]; //load sound freq.
_tmr1h = frq[frq_idx+1];
_tmr1c4 = 1; //start timer1
}
void stop_sound(){
_tmr1c4 = 0; //stop timer1
_pb = 0;
}
void isr_c(){ // timer1
_pb = ~_pb; // generate square wave
}
void initial(){
_pac = 0xff; //set port A to input port
_pbc = 0; //set port B to output port
_pb = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -