从串口发送两个指令,让蜂鸣器以不同频率交替发声一定时间。下面是while循环:
while(1) //等待中断
{
switch (RxValue) //RxValue为接收数据缓存
{
case 0x01:
PTCON &=~(1<<15);
PTPER=17279;
PDC1= 8639; ////频率改为100HZ,占空比改为50%
PTCON |=1<<15;
delay_ms(5000); //延时5000
PTCON &=~(1<<15);
PTPER=3455;
PDC1= 863; //频率改为100HZ,占空比改为50%
PTCON |=1<<15;
delay_ms(5000); //延时5000
break;
case 0x02:
PTCON &=~(1<<15);
PTPER=17279;
PDC1= 8639; //频率改为100HZ,占空比改为50%
PTCON |=1<<15;
delay_ms(10000); //延时10000
PTCON &=~(1<<15);
PTPER=3455;
PDC1= 863; ////频率改为100HZ,占空比改为50%
PTCON |=1<<15;
delay_ms(15000); //延时15000
break;
}
}
发送case 01的指令后,break停止不了蜂鸣器 一直在响,没法发送case 02的指令,用return就把程序全关了也不行。求助! |