标题: 普中单片机蜂鸣器驱动程序 [打印本页]

作者: 暂无反应    时间: 2021-5-3 17:21
标题: 普中单片机蜂鸣器驱动程序
新学会了用蜂鸣器
普中的蜂鸣器是无源的,需要晶振才能响。
这里使用的是100微秒的周期
端口是P1^5

单片机源程序如下:
  1. #include <reg51.h>
  2. sbit buzzer=P1^5;
  3. void Delay100us()                //@11.0592MHz
  4. {
  5.         unsigned char i;


  6.         i = 43;
  7.         while (--i);
  8. }

  9. void main()
  10. {
  11.         while(1)
  12.         {
  13.         buzzer=1;
  14.                 Delay100us();
  15.                 buzzer=0;
  16.                 Delay100us();
  17.                
  18.         }
  19. }
复制代码







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1