色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 51單片機-蜂鳴器

          51單片機-蜂鳴器

          作者: 時間:2016-12-02 來源:網(wǎng)絡 收藏


          單片機如何輸出頻率:



          得到600HZ的頻率:

          #include
          sbit p = P3^4;

          void main(){
          p = 1;
          EA = 1;
          ET0 = 1;
          TMOD = 0x01;
          TH0 = (65536-833)/256;
          TL0 = (65536-833)%256;
          TR0 = 1;
          while(1);
          }

          void time0() interrupt 1{
          p = ~p;
          TH0 = (65536-833)/256;
          TL0 = (65536-833)%256;
          }

          內循環(huán)一次8.3us

          void delay8us(unsigned char x){
          unsigned char i,j;
          for(i = 0; i < x; i++)
          for(j = 0; j < 1; j++)
          ;
          }

          音符頻率及定時器初值對照表:




          4*4電子琴程序的實現(xiàn):

          #include
          #define uchar unsigned char
          #define uint unsigned int
          uint DATE,i;
          sbit buzz = P3^4;
          sbit L0 = P0^0;
          sbit L1 = P0^1;
          sbit L2 = P0^2;
          sbit L3 = P0^3;
          sbit H0 = P0^4;
          sbit H1 = P0^5;
          sbit H2 = P0^6;
          sbit H3 = P0^7;
          uchar TH0_DATA = 0;
          uchar TL0_DATA = 0;
          uchar code qin[] = {262,277,293,329,349,392,440,494};


          評論


          技術專區(qū)

          關閉