51单片机用无源蜂鸣器播放凤凰传奇神曲

  • Post author:
  • Post category:其他


#include"Buzzer_music.h"
 //左边发射极
uchar time_h,time_l;
sbit BUZZER = P2^3;
 
void main()
{
    uchar i,j;
    P2M1 = 0X00;
    P2M0 = 0XFF;
    TMOD = 0x01;
    ET0 = 1;
    EA = 1;
//  TR0 = 1;
    i = 0;
    j = 0;
    while(1)
    {
        while(display[i][1] != 0xff)
        {
//          if(display[i][0] == 0xff)
//          {
//              TR0 = 0;
//              Delay_ms(100);
//          }
//          else
//          {
                time_h = m_note[display[i][0]][0];
                time_l = m_note[display[i][0]][1];
                TH0 = time_h;
                TL0 = time_l;
                ET0 = 1;
                TR0 = 1;
                Delay_ms(1000);
                TR0 = 0;
                ET0 = 0;
                BUZZER = 0;
//          }
            Delay(display[i][1]);
            i++;
        }
        i = 0;
    }
}
 
vo



版权声明:本文为LinLingPeng_原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。