如何用单片机IO发出类似”咔嚓“或”叮咚“声音?

2019-12-27 18:40发布

如题,单片机的PWM通道已经用完,可以用定时器或者软件延时来驱动IO端口,发出类似拍照”咔嚓声“或门铃”叮咚“声?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
38条回答
amazing030
2019-12-30 01:06
code u8 alarm_tab[200] =                 
{
        210,210,210,210,210,210,219,219,219,219,
        219,218,218,218,217,217,217,216,216,215,
        215,215,214,214,213,213,212,211,211,210,
        210,209,208,208,207,206,206,205,204,204,
        203,202,201,201,200,199,198,198,197,196,
        195,195,194,193,192,192,191,190,190,189,
        188,187,187,186,185,185,184,183,183,182,
        181,181,180,180,179,179,178,178,177,177,
        176,176,176,175,175,174,174,174,174,173,
        173,173,173,173,172,172,172,172,172,172,
        172,172,172,172,172,172,173,173,173,173,
        173,174,174,174,174,175,175,175,176,176,
        177,177,178,178,179,179,180,180,181,181,
        182,183,183,184,185,185,186,187,187,188,
        189,189,190,191,192,192,193,194,195,195,
        196,197,198,198,199,200,201,201,202,203,
        204,204,205,206,206,207,208,208,209,210,
        210,211,211,212,212,213,214,214,215,215,
        215,216,216,217,217,217,218,218,218,219,
        219,219,219,219,210,210,210,210,210,210
};

for (i = 0 ; i < 800; i++)
{
        Delay_us(alarm_tab[i/4] - 18);
        BEEP = !BEEP;
}
我用这个做警报声,也调了些时间,感觉效果还可以,延时自己调下改变音调

一周热门 更多>