卸扣厂家
免费服务热线

Free service

hotline

010-00000000
卸扣厂家
热门搜索:
行业资讯
当前位置:首页 > 行业资讯

基于51单片机的点阵音乐祝你生日快乐

发布时间:2020-07-21 17:42:55 阅读: 来源:卸扣厂家

//-----------------------------------------------------//12*12点阵+音乐产生>>// MCU:89C51 晶振:12M //编写日期:2010。12。25//编写人:李春起#include REG51.H>#define uchar unsigned char#define uint unsigned intuint 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,0xD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F,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;im;i++) { for(j=0;j300;j++) {kk();if(sta){sta=0;goto abc;}} } abc:;}//------按键消拉动用----------------void delay500(){ uint i1; P0=0XFF; P1=0X0F; P2=0X00; for(i1=0;i132000;i1++);}//=========定时器T0用于频率产生和显示======================void time0() interrupt 1{ P0=0XFF; P1=0X0F; P2=0X00; TH0=mius>>8; TL0=mius0xff; YY=~YY; switch(flag) { case 0:{ //笑脸 P0=tabfas[a]; P1=tabfas[a+24]; P2=tabfas[a+48]; if(++disfla1700){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(++disfla1500){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(++disfla1700){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(++disfla1500){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=mius0xff; 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; } }}

晶振相关文章:晶振原理

重庆碧莲盛地址

南宁碧莲盛植发医院

碧莲盛 南京

碧莲盛植发

相关阅读