当前位置:首页 > 单片机 > 单片机
[导读]//----------------------------------------------------- //<<12*12点阵+音乐产生>> // MCU:89C51 晶振:12M //编写日期:2010。12。25 //编写人:李春起 #include <REG51.H> #define uchar unsigned char

//-----------------------------------------------------
//<<12*12点阵+音乐产生>>
// MCU:89C51  晶振:12M
//编写日期:2010。12。25
//编写人:李春起
#include <REG51.H>
#define uchar unsigned char
#define uint unsigned int
uint a=0,a1=0,a2=0;
uint miusfla,miust,mius=64536;
uint disfla1,sta=0;
char flag=0,mdflag=0;
sbit k1=P3^2;
sbit k2=P3^3;
sbit YY=P3^1;

uchar code tabfas[]={
//==============笑脸===================================
//P0口
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
//P1口
0x8E,0x4D,0xAB,0x57,0x5F,0x9F,0x9F,0x5F,0x5F,0xAF,0x4F,0x8F,
0x8E,0x4D,0xAB,0x97,0x9F,0x9F,0x9F,0x9F,0x9F,0xAF,0x4F,0x8F,
//P2口
0x87,0x88,0x50,0x20,0xA4,0x68,0x68,0xA4,0x20,0x50,0x88,0x87,
0x87,0x88,0x50,0x20,0xA4,0x68,0x68,0xA4,0x20,0x50,0x88,0x87,  
//P0口
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0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//日
//0x0E,0x4D,0xDB,0x67,0xCF,0x4F,0x0F,0x8F,0x4F,0x4F,0x2F,0x0F,    //新
//0x0E,0x0D,0x8B,0x47,0x7F,0x4F,0xCF,0x4F,0x4F,0x4F,0x4F,0x0F,    //年
0x0E,0x0D,0xEB,0x07,0x8F,0x8F,0xEF,0x8F,0x8F,0x8F,0x0F,0x0F, //快
0x0E,0x8D,0x4B,0x47,0x4F,0xAF,0x1F,0x0F,0x0F,0x0F,0x0F,0x0F, //乐
0xCE,0x2D,0x2B,0x27,0x4F,0x8F,0x8F,0x4F,0x2F,0x2F,0x2F,0xCF, //心形
0x0F,0x0F,0x2B,0x27,0xAF,0x6F,0xFF,0x6F,0xAF,0x2F,0x2F,0x0F, //李
0x0E,0x0D,0x2B,0xA7,0xAF,0xFF,0xAF,0xAF,0x2F,0x0F,0x0F,0x0F, //春
0x0E,0x0D,0x4B,0x47,0xEF,0x4F,0x4F,0x8F,0x8F,0x8F,0x0F,0x0F,  //起
//0x0E,0xFD,0x5B,0x57,0x5F,0xFF,0x0F,0x4F,0x4F,0xCF,0x4F,0x0F, //题
0xCE,0x2D,0x2B,0x27,0x4F,0x8F,0x8F,0x4F,0x2F,0x2F,0x2F,0xCF, //心形
//P2口
0x08,0x04,0xFE,0x05,0x08,0x43,0x3E,0x02,0x3E,0x23,0x30,0x00, //祝
0x00,0x09,0x0A,0x7F,0x2A,0x08,0x0F,0x09,0x7F,0x09,0x0F,0x00,  //钟
0x00,0x02,0x01,0x7F,0x02,0x22,0x22,0x3F,0x22,0x22,0x02,0x00,   //仕
0xc0,0x3f,0x88,0x6a,0x2a,0xff,0x2a,0xff,0x2a,0x6a,0xde,0x88,//廉
0x00,0x21,0x20,0x20,0x24,0x24,0x3F,0x24,0x24,0x20,0x20,0x00, //生
0x00,0x00,0x00,0x3F,0x22,0x22,0x22,0x22,0x3F,0x00,0x00,0x00,  //日
//0x00,0x2A,0x5A,0xFF,0x1A,0x2A,0x40,0x3F,0x02,0x7E,0x02,0x00,   //新
//0x08,0x09,0x0F,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x08,0x00,    //看
0x01,0x06,0x7F,0x22,0x14,0x0C,0x07,0x0C,0x14,0x27,0x24,0x00, //快
0x00,0x23,0x12,0x0E,0x22,0x7F,0x06,0x0A,0x13,0x22,0x00,0x00, //乐
0x03,0x04,0x08,0x10,0x20,0x60,0x20,0x10,0x08,0x04,0x02,0x01,  //心形
0x00,0x00,0x11,0x11,0x12,0x52,0xFB,0x1A,0x16,0x11,0x11,0x00, //李
0x00,0x12,0x0A,0xFE,0xAB,0xAA,0xAA,0xFE,0x0A,0x12,0x00,0x00, //春
0x40,0x21,0x1D,0x09,0x1F,0x25,0x41,0x5D,0x54,0x53,0x58,0x00,   //起
//0x84,0x45,0x35,0x3D,0x55,0x95,0x84,0xAF,0x9D,0x91,0xAF,0x80, //题
0x03,0x04,0x08,0x10,0x20,0x60,0x20,0x10,0x08,0x04,0x02,0x01,  //心形
};
//----------------音符----------------------
uint code miusdata[]={
//祝你生日快乐
64260,64260,64399,64260,64579,64524,64260,64260,
64399,64260,64684,64580,64260,64260,64898,64777,
64580,64524,64399,64819,64819,64777,64580,64777,
64684,0,
64260,64260,64399,64260,64579,64524,64260,64260,
64399,64260,64684,64580,64260,64260,64898,64777,
64580,64524,64399,64819,64819,64777,64580,64684,
64580,0,  
64580,64580,64684,64580,64819,64777,64580,64580,
64684,64580,64898,64819,64580,64580,65058,64968,
64819,64777,64684,65000,65000,64960,64819,64967,
64898,0,
64580,64580,64684,64580,64819,64777,64580,64580,
64684,64580,64898,64819,64580,64580,65058,64968,
64819,64777,64684,65000,65000,64960,64819,64898,
64819,0
};
//---------------节拍-----------------------
uchar code miustime[]={
40,40,80,80,80,160,40,40,80,80,80,160,40,40,
80,80,80,80,80,40,40,80,80,80,160,80,
40,40,80,80,80,160,40,40,80,80,80,160,40,40,
80,80,80,80,80,40,40,80,80,80,160,80,
40,40,80,80,80,160,40,40,80,80,80,160,40,40,
70,75,80,80,80,40,40,80,80,80,160,80,
40,40,80,80,80,160,40,40,80,80,80,160,40,40,
70,75,80,80,80,40,40,80,80,80,160,80,
};
void delay500();

//==========按键==========================================
void kk()
{
   if(!k1){delay500();if(++flag>1)flag=0;else {a=72;a2=0;}sta=1;}
   if(!k2){delay500();if(++mdflag>1)mdflag=0;sta=1;}
}
//=========延时===========================================
void delay(uint m)
{
   uint i,j;
   for(i=0;i<m;i++)
   {
     for(j=0;j<300;j++)
  {kk();if(sta){sta=0;goto abc;}}
   }
   abc:;
}
//------按键消拉动用----------------
void delay500()
{
  uint i1;
  P0=0XFF;
  P1=0X0F;
  P2=0X00;
  for(i1=0;i1<32000;i1++);
}
//=========定时器T0用于频率产生和显示======================
void time0() interrupt 1
{
  P0=0XFF;
  P1=0X0F;
  P2=0X00;
  TH0=mius>>8;
  TL0=mius&0xff;
  YY=~YY;
  switch(flag)
  {
    case 0:{ //笑脸
           P0=tabfas[a];
              P1=tabfas[a+24];
              P2=tabfas[a+48];
              if(++disfla1<700){if(++a>11)a=0;}
              if(disfla1>=700){if(++a>23)a=11;}
              if(disfla1>800){a=0;disfla1=0;}
         }break;
case 1:{ //汉字
           P0=tabfas[a];
           P1=tabfas[a+192];
     P2=tabfas[a+348];
     if(++disfla1<500){if(++a>(a2+83))a=(a2+72);}
       else{if(++a>(a2+83))a=(a2+72);}
     if(disfla1>1000){a2+=12;disfla1=0;}
     if(a2>144){a2=0;}
         }break;
default:break;
  }
}
//========定时器T1只用于显示================================
void time1() interrupt 3
{
  P0=0XFF;
  P1=0X0F;
  P2=0X00;
  TH1=0xf8;
  TL1=0x30;
  switch(flag)
  {
    case 0:{ //笑脸
           P0=tabfas[a];
              P1=tabfas[a+24];
              P2=tabfas[a+48];
              if(++disfla1<700){if(++a>11)a=0;}
              if(disfla1>=700){if(++a>23)a=11;}
              if(disfla1>800){a=0;disfla1=0;}
         }break;
case 1:{ //汉字
           P0=tabfas[a];
           P1=tabfas[a+192];
     P2=tabfas[a+348];
     if(++disfla1<500){if(++a>(a2+83))a=(a2+72);}
       else{if(++a>(a2+83))a=(a2+72);}
     if(disfla1>1000){a2+=12;disfla1=0;}
     if(a2>144){a2=0;}
         }break;
default:break;
  }
}
/////////////////////////////////////////////////////////////
//=========================================================//
//----------------主程序-----------------------------------//
//=========================================================//
/////////////////////////////////////////////////////////////
void main()
{
  P0=0XFF;
  P1=0X0F;
  P2=0X00;
  P3=0XFD;
  TMOD=0X11;
  TH0=mius>>8;
  TL0=mius&0xff;
  TH1=0xf8;
  TL1=0x30;
  TR0=1;
  ET0=1;
  TR1=0;
  ET1=1;
  EA=1;
  while(1)
  {
    switch(mdflag)
    {
      case 0:{//音乐暂停
      TR0=0;TR1=1;kk();sta=0;
           }break;
     case 1:{ //音乐继续
       TR0=0;
       delay(1);
                TR0=1;  
                mius=miusdata[a1];
                if(mius==0){TR0=0;TR1=1;}
      else {TR1=0;TR0=1;}
                delay(miustime[a1]);
                if(++a1>=104)a1=0;
           }break;
   default:break;
    }
  }
}   
 

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

9月2日消息,不造车的华为或将催生出更大的独角兽公司,随着阿维塔和赛力斯的入局,华为引望愈发显得引人瞩目。

关键字: 阿维塔 塞力斯 华为

加利福尼亚州圣克拉拉县2024年8月30日 /美通社/ -- 数字化转型技术解决方案公司Trianz今天宣布,该公司与Amazon Web Services (AWS)签订了...

关键字: AWS AN BSP 数字化

伦敦2024年8月29日 /美通社/ -- 英国汽车技术公司SODA.Auto推出其旗舰产品SODA V,这是全球首款涵盖汽车工程师从创意到认证的所有需求的工具,可用于创建软件定义汽车。 SODA V工具的开发耗时1.5...

关键字: 汽车 人工智能 智能驱动 BSP

北京2024年8月28日 /美通社/ -- 越来越多用户希望企业业务能7×24不间断运行,同时企业却面临越来越多业务中断的风险,如企业系统复杂性的增加,频繁的功能更新和发布等。如何确保业务连续性,提升韧性,成...

关键字: 亚马逊 解密 控制平面 BSP

8月30日消息,据媒体报道,腾讯和网易近期正在缩减他们对日本游戏市场的投资。

关键字: 腾讯 编码器 CPU

8月28日消息,今天上午,2024中国国际大数据产业博览会开幕式在贵阳举行,华为董事、质量流程IT总裁陶景文发表了演讲。

关键字: 华为 12nm EDA 半导体

8月28日消息,在2024中国国际大数据产业博览会上,华为常务董事、华为云CEO张平安发表演讲称,数字世界的话语权最终是由生态的繁荣决定的。

关键字: 华为 12nm 手机 卫星通信

要点: 有效应对环境变化,经营业绩稳中有升 落实提质增效举措,毛利润率延续升势 战略布局成效显著,战新业务引领增长 以科技创新为引领,提升企业核心竞争力 坚持高质量发展策略,塑强核心竞争优势...

关键字: 通信 BSP 电信运营商 数字经济

北京2024年8月27日 /美通社/ -- 8月21日,由中央广播电视总台与中国电影电视技术学会联合牵头组建的NVI技术创新联盟在BIRTV2024超高清全产业链发展研讨会上宣布正式成立。 活动现场 NVI技术创新联...

关键字: VI 传输协议 音频 BSP

北京2024年8月27日 /美通社/ -- 在8月23日举办的2024年长三角生态绿色一体化发展示范区联合招商会上,软通动力信息技术(集团)股份有限公司(以下简称"软通动力")与长三角投资(上海)有限...

关键字: BSP 信息技术
关闭
关闭