zoukankan      html  css  js  c++  java
  • 51单片机蜂鸣器之《东西》

    #include <reg51.h>
    #define uint unsigned int
    #define uchar unsigned char
    sbit voice=P1^5;
    uchar code sound[]={0xff,
                        0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,
                        0x2b,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0xff,0x20,0x2b,0x20,0x30,0x20,
                        0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,
                        0x30,0x20,0x2b,0x20,0x2b,0x20,0x30,0x20,0xff,0x20,0x30,0x20,0x2b,0x20,
                        0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,
                        0x2b,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0xff,0x20,0x2b,0x20,0x30,0x20,
                        0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,
                        0x30,0x20,0x20,0x20,0x20,0x20,0x26,0x20,0xff,0x20,0xff,0x20,0x26,0x20,
                        0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,
                        0x26,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,0xff,0x20,0x2b,0x20,0x30,0x20,
                        0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,
                        0x30,0x20,0x2b,0x20,0x2b,0x20,0x30,0x20,0xff,0x20,0x30,0x20,0x2b,0x20,
                        0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,0x2b,0x20,0x26,0x20,
                        0x2b,0x20,0x26,0x20,0x2b,0x20,0x2b,0x20,0xff,0x20,0x2b,0x20,0x30,0x20,
                        0x2b,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x2b,0x20,0x2b,0x20,0x30,0x20,
                        0xff,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x39,0x20,0x40,0x20,0x39,0x20,
                        0x30,0x20,0x2b,0x20,0xff,0x20,0x30,0x20,0x26,0x20,0x26,0x20,0x2b,0x20,
                        0x30,0x20,0x30,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x39,0x20,0x40,0x20,
                        0x39,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x20,0x20,0x26,0x20,0xff,0x20,
                        0xff,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x39,0x20,0x40,0x20,0x39,0x20,
                        0x30,0x20,0x2b,0x20,0xff,0x20,0x30,0x20,0x2b,0x20,0x30,0x20,0x20,0x20,
                        0x26,0x20,0x2b,0x20,0x30,0x20,0xff,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,
                        0x20,0x20,0x26,0x20,0x2b,0x20,0x30,0x20,0x39,0x20,0x40,0x20,0x30,0x20,
                        0xff,0x20,0x00,
                       };
    uchar zdjs=0, jp;
    del(yj);
    void main(void)
      {
          uint dpjs=0;
          uchar yj;
          TMOD=0x01,IE=0x82;
          TH0=0xd8, TL0=0xef;
       TR0=1;
    while(1)
       {  
          zdjs=0;
          dpjs++; yj=sound[dpjs]; 
         dpjs++; jp=sound[dpjs];
       while(zdjs!=jp)
           { 
          if(yj!=0xff)
       {
                 if(yj!=0)
                   {
                 voice=!voice;
                     del(yj);
                    }
                    else
              {
              dpjs=0; 
                          break;
                         }
        }
        else
          {
            voice=0;
                     del(jp);
        }
          }
           }
       }
    time0() interrupt 1  using 1
          {
             TH0=0xd8, TL0=0xef;
             zdjs++;
               }
    del(yj)
        {
          uchar yj2=2;
           while(yj!=0)
             {      
                   while(yj2!=0)
                      {
                         yj2--;
                         }
                      yj2=2;
                 yj--;  
           }
       
         }
  • 相关阅读:
    获取设备唯一标识 uuid(采用第三方库SSKeychain)
    基于定时器的动画和性能调优
    获取设备的唯一标识uuid
    获取网络状态ios(2G、3G、4G、Wifi)
    equals 为什么要把常量写在前面?
    svn提交更新代码提示Please execute the 'Cleanup' command 的解决办法
    C# 一次循环获取树的两种方法
    递归拼装无限层级菜单树
    mysql错误:Column count doesn't match value count at row 1解决办法
    IDEA 解决Number objects are compared using '==', not 'equals()' 警告
  • 原文地址:https://www.cnblogs.com/liangjinjie/p/10307353.html
Copyright © 2011-2022 走看看