//-----------------------------------------------------
//<<12*12点阵+音乐产生>>
// MCU:89C51 晶振:12M
//编写日期:2010。12。25
//编写人:李春起
#include
#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,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0xFF,0xFF,0xFF,0xFF,0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4F,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
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;
}
}
}
上一篇:基于AT89S52单片机的舵机控制系统设计
下一篇:基于单片机的阳台智能隐形防盗网
推荐阅读最新更新时间:2024-03-16 13:08
- 热门资源推荐
- 热门放大器推荐
设计资源 培训 开发板 精华推荐
- Allegro MicroSystems 在 2024 年德国慕尼黑电子展上推出先进的磁性和电感式位置感测解决方案
- 左手车钥匙,右手活体检测雷达,UWB上车势在必行!
- 狂飙十年,国产CIS挤上牌桌
- 神盾短刀电池+雷神EM-i超级电混,吉利新能源甩出了两张“王炸”
- 浅谈功能安全之故障(fault),错误(error),失效(failure)
- 智能汽车2.0周期,这几大核心产业链迎来重大机会!
- 美日研发新型电池,宁德时代面临挑战?中国新能源电池产业如何应对?
- Rambus推出业界首款HBM 4控制器IP:背后有哪些技术细节?
- 村田推出高精度汽车用6轴惯性传感器
- 福特获得预充电报警专利 有助于节约成本和应对紧急情况