久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標(biāo)題:
蜂鳴器模擬簡(jiǎn)易mp3
[打印本頁]
作者:
小小白111
時(shí)間:
2018-6-19 15:14
標(biāo)題:
蜂鳴器模擬簡(jiǎn)易mp3
#include <REG52.H>
#include <INTRINS.H>
int y=0,zhan,s;
/*
程序默認(rèn)IO連接方式:
*/
sbit sce = P0^0; //片選
sbit res = P0^1; //復(fù)位,0復(fù)位
sbit dc = P0^2; //1寫數(shù)據(jù),0寫指令
sbit sdin = P1^4; //數(shù)據(jù)
sbit sclk = P1^7; //時(shí)鐘
sbit Beep = P1^5 ;
sbit anjian0=P3^2;
sbit anjian1=P3^3;
sbit deng=P2^7;
unsigned char n=0,receive,o; //n為節(jié)拍常數(shù)變量
//八月桂花
unsigned char code music_tab0[] ={
0x18, 0x30, 0x1C , 0x10, //格式為: 頻率常數(shù), 節(jié)拍常數(shù), 頻率常數(shù), 節(jié)拍常數(shù), 48
0x20, 0x40, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x10,
0x1C, 0x10, 0x18 , 0x40,
0x1C, 0x20, 0x20 , 0x20,
0x1C, 0x20, 0x18 , 0x20,
0x20, 0x80, 0xFF , 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20, 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30, 0x80 , 0xFF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
};
//天空之城
unsigned char code music_tab1[] ={
0x1c, 0x30, 0x19, 0x30, 0x18, 0x40, 0x19, 0x30,
0x18, 0x30, 0x13, 0x30, 0x19, 0x18, 0x26, 0x30,
0x26, 0x30, 0x1c, 0x40, 0x20, 0x30, 0x1c, 0x30,
0x18, 0x30, 0x20, 0x60, 0x26, 0x30, 0x26, 0x30,
0x24, 0x40, 0x26, 0x30, 0x24, 0x30, 0x18, 0x40,
0x26, 0x60, 0x18, 0x20, 0x18, 0x20, 0x18, 0x20,
0x19, 0x40, 0x24, 0x30, 0x24, 0x30, 0x19, 0x30,
0x19, 0x60, 0x1c, 0x30, 0x19, 0x30, 0x18, 0x40,
0x19, 0x30, 0x18, 0x30, 0x13, 0x30, 0x19, 0x60,
0x26, 0x30, 0x26, 0x30, 0x1c, 0x40, 0x20, 0x30,
0x1c, 0x30, 0x18, 0x30, 0x20, 0x80, 0x26, 0x30,
0x24, 0x30, 0x24, 0x30, 0x18, 0x30, 0x19, 0x20,
0x19, 0x30, 0x18, 0x30, 0x15, 0x20, 0x15, 0x20,
0x13, 0x20, 0x18, 0x40, 0x18, 0x30, 0x19, 0x30,
0x1c, 0x20, 0x1c, 0x20, 0x19, 0x30, 0x20, 0x30,
0x1c, 0x60, 0x18, 0x30, 0x15, 0x30, 0x13, 0x40,
0x15, 0x30, 0x13, 0x30, 0x10, 0x30, 0x15, 0x60,
0x20, 0x30, 0x20, 0x30, 0x18, 0x30, 0x19, 0x30,
0x18, 0x30, 0x13, 0x30, 0x13, 0x60, 0x1c, 0x20,
0x19, 0x20, 0x18, 0x30, 0x19, 0x30, 0x15, 0x20,
0x15, 0x20, 0x18, 0x40, 0x20, 0x30, 0x20, 0x30,
0x12, 0x30, 0x13, 0x30, 0x15, 0x30, 0x18, 0x30,
0x13, 0xc0, 0x13, 0x80, 0x13, 0x30, 0x0e, 0x80,
0x10, 0x30, 0x10, 0x30, 0x13, 0x20, 0x15, 0x20,
0x18, 0x40, 0x18, 0x30, 0x15, 0x30, 0x18, 0x20,
0x15, 0x20, 0x15, 0x30, 0x10, 0x30, 0x13, 0x60,
0x13, 0x30, 0x0e, 0x60, 0x10, 0x60, 0x13, 0x20,
0x15, 0x20, 0x18, 0x40, 0x18, 0x30, 0x15, 0x30,
0x15, 0x20, 0x18, 0x20, 0x15, 0x30, 0x19, 0x30,
0x1c, 0x60, 0x1c, 0x30, 0x19, 0x30, 0x1c, 0xc0,
0x00,
};
//吉他
unsigned char code music_tab2[] ={
0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,
0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02,
0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02,
0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66,
0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00,
0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03,
0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02,
0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x18,0x66, 0x18,0x03,
0x19,0x02, 0x1A,0x02, 0x19,0x0C, 0x18,0x0D, 0x17,0x03,
0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,
0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66,
0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,
0x1B,0x0C, 0x1A,0x0D, 0x19,0x03, 0x17,0x00, 0x1F,0x01,
0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x10,0x02,
0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,
0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70,
0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66,
0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02,
0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C,
0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,
0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x00,
};
//6*16字符
unsigned char code shuzi[]={
/*-- 文字: G --*/
/*-- 宋體9; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=6x12 --*/
/*-- 高度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=6x16 --*/
0xF0,0x08,0x04,0x44,0xCC,0x40,0x00,0x01,0x02,0x02,0x01,0x00
};
unsigned char code yi[][24]=
{
//八
0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x00,0x08,0x04,0x03,0x00,
0x00,0x00,0x00,0x00,0x01,0x06,0x08,0x00,
//月
0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x08,0x06,0x01,0x00,
0x00,0x00,0x00,0x08,0x08,0x0F,0x00,0x00,
//桂
0x88,0x68,0xFF,0x48,0x20,0x24,0x24,0xBF,0x24,0x24,0x20,0x00,0x00,0x00,0x0F,0x00,
0x08,0x09,0x09,0x0F,0x09,0x09,0x08,0x00,
//花
0x82,0x42,0xE2,0x17,0x02,0x02,0xF2,0x87,0x42,0x22,0x02,0x00,0x00,0x00,0x0F,0x00,
0x04,0x02,0x07,0x08,0x08,0x08,0x0E,0x00,
};
/*-- 文字: 單 --*/
/*-- 宋體9; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=12x12 --*/
/*-- 高度不是8的倍數(shù),現(xiàn)調(diào)整為:寬度x高度=12x16 --*/
unsigned char code er[][24]=
{
//天
0x20,0x22,0x22,0x22,0xA2,0x7E,0xA2,0x22,0x22,0x22,0x20,0x00,0x08,0x08,0x04,0x02,
0x01,0x00,0x01,0x02,0x04,0x08,0x08,0x00,
//空
0x0C,0xA4,0x94,0x8C,0x85,0x86,0x84,0x8C,0x94,0xA4,0x0C,0x00,0x08,0x08,0x08,0x08,
0x08,0x0F,0x08,0x08,0x08,0x08,0x08,0x00,
//之
0x00,0x08,0x08,0x08,0x09,0x8A,0x48,0x28,0x18,0x08,0x00,0x00,0x00,0x08,0x04,0x02,
0x05,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
//城
0x08,0xFF,0x08,0x00,0xFC,0x24,0xE4,0x04,0xFF,0x84,0x65,0x00,0x02,0x03,0x09,0x06,
0x01,0x02,0x0B,0x04,0x03,0x04,0x0E,0x00,
};
unsigned char code shan[][24]=
{
//吉
0x04,0xA4,0xA4,0xA4,0xA4,0xBF,0xA4,0xA4,0xA4,0xA4,0x04,0x00,0x00,0x0F,0x04,0x04,
0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,
//它
0x1C,0x04,0xF4,0x84,0x85,0x46,0x44,0x24,0x24,0x04,0x1C,0x00,0x00,0x00,0x07,0x08,
0x08,0x08,0x08,0x08,0x08,0x0E,0x00,0x00,
//掃
0x88,0x88,0xFF,0x48,0x48,0x02,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x08,0x0F,0x00,
0x00,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,
//弦
0xF2,0x92,0x9E,0x00,0x44,0x64,0x55,0xCE,0x44,0x24,0x04,0x00,0x08,0x08,0x07,0x00,
0x04,0x06,0x05,0x04,0x04,0x06,0x0C,0x00,
};
void delay1ms(unsigned int ii) //1ms延時(shí)函數(shù)
{
unsigned int i,x;
for (x=0;x<ii;x++)
{
for (i=0;i<100;i++);
}
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口寫數(shù)據(jù)到LCD
輸入?yún)?shù):dt:寫入的數(shù)據(jù);
command :寫數(shù)據(jù)/命令選擇;
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i;
sce=0;
dc=command;
for(i=0;i<8;i++)
{
if(dt&0x80)
sdin=1;
else
sdin=0;
dt=dt<<1;
sclk=0;
sclk=1;
}
dc=1;
sce=1;
sdin=1;
}
/*---------------------------------------
LCD_init: 3310LCD初始化
----------------------------------------- */
void LCD_init(void)
{
res=0;
//delay1ms(10);
res=1;
LCD_write_byte(0x21,0); //初始化Lcd,功能設(shè)定使用擴(kuò)充指令
LCD_write_byte(0xC6,0); //設(shè)定液晶偏置電壓
LCD_write_byte(0x06,0); //溫度校正
LCD_write_byte(0x13,0); //1:48
LCD_write_byte(0x20,0); //使用基本指令
LCD_write_byte(0x0C,0); //設(shè)定顯示模式,正常顯示
}
/*-------------------------------------------
LCD_set_XY: 設(shè)置LCD坐標(biāo)函數(shù)
輸入?yún)?shù):X:0-83 Y:0-5
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/*------------------------------------------
LCD_clear: LCD清屏函數(shù)
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
/*---------------------------------------------
LCD_write_shu: 顯示6(寬)*16(高)點(diǎn)陣列數(shù)字字母符號(hào)等半角類
輸入?yún)?shù):c:顯示的字符;
-----------------------------------------------*/
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:頁 dd:字符
{
unsigned char i;
LCD_set_XY(row*6, page); // 列,頁
for(i=0; i<6;i++)
{
LCD_write_byte(shuzi[c*12+i],1);
}
LCD_set_XY(row*6, page+1); // 列,頁
for(i=6; i<12;i++)
{
LCD_write_byte(shuzi[c*12+i],1);
}
}
/**************************************************************/
/*-------------------------------------------------
LCD_write_chinese_string: 在LCD上顯示漢字
輸入?yún)?shù):X、Y :顯示漢字的起始X、Y坐標(biāo);
ch_with :漢字點(diǎn)陣的寬度
num :顯示漢字的個(gè)數(shù);
line :漢字點(diǎn)陣數(shù)組中的起始行數(shù)
row :漢字顯示的行間距
--------------------------------------------------*/
void LCD_write_chinese_string(unsigned char X, unsigned char Y,unsigned char ch_with,unsigned char num, unsigned char line,unsigned char row)
{
unsigned char i,n;
LCD_set_XY(X,Y); //設(shè)置初始位置
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++) //寫一個(gè)漢字
{
if (n==ch_with) //寫漢字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
{
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
}
LCD_write_byte(yi[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
void LCD_write_chinese_string1(unsigned char X, unsigned char Y,unsigned char ch_with,unsigned char num, unsigned char line,unsigned char row)
{
unsigned char i,n;
LCD_set_XY(X,Y); //設(shè)置初始位置
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++) //寫一個(gè)漢字
{
if (n==ch_with) //寫漢字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
{
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
}
LCD_write_byte(er[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
void LCD_write_chinese_string2(unsigned char X, unsigned char Y,unsigned char ch_with,unsigned char num, unsigned char line,unsigned char row)
{
unsigned char i,n;
LCD_set_XY(X,Y); //設(shè)置初始位置
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++) //寫一個(gè)漢字
{
if (n==ch_with) //寫漢字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
{
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
}
LCD_write_byte(shan[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
void int0() interrupt 1 //采用定時(shí)器中斷0 控制節(jié)拍 10.851MS
{ TH0=0xd8;
TL0=0xef;
n--;
}
void delay (unsigned char m) //控制頻率延時(shí)
{
unsigned i=3*m;
while(--i);
}
void delayms(unsigned char a) //豪秒延時(shí)子程序
{
while(--a); //采用while(--a) 不要采用while(a--); 各位可編譯一下看看匯編結(jié)果就知道了!
}
//外部中斷0
void int0_isr(void) interrupt 0 using 1
{
delayms(200);
EX0=0;//外部中斷0關(guān)
if(anjian0)
{
//LCD_write_chinese_string(1,0,12,4,0,0);
y++;//向上切歌
if(y==3)
{
y=0;
}
}
EX0=1;//外部中斷0開
}
//外部中斷1
void int1_isr(void) interrupt 2 using 2
{
delayms(200);
EX1=0;//外部中斷1關(guān)
if(!anjian1)
{
if(y==0)
{y=2;}
}
if(y>=1)
{
y--; //向下切歌
}
EX1=1;
}
//藍(lán)牙選歌
void com_int(void) interrupt 4
{
EA=0;//總中斷關(guān)
deng=SBUF;
if(RI==1)
{
o=SBUF;
RI=0;
switch(o)
{
case 0: y=0,LCD_clear(),LCD_write_chinese_string(1,0,12,4,0,0);break;//第一首歌
case 1: y=1,LCD_clear(),LCD_write_chinese_string1(1,0,12,4,0,0);break;//第二首歌
case 2: y=2,LCD_clear(),LCD_write_chinese_string2(1,0,12,4,0,0);break;//第三首歌
case 4: zhan=1;break;//暫停
case 5: zhan=0;break;//繼續(xù)
default:break;
}
}
EA=1;
}
//主函數(shù)
void main()
{
unsigned char i=0,p,m; //m為頻率常數(shù)變量
TMOD=0x21;//定時(shí)器方式1 16位 T1定時(shí)器 方式2
TH0=0xd8;
TL0=0xef; //55535
IE=0x82;
EA=1;//總中斷
EX0=1;//外部中斷0
EX1=1;
IT0=1;//跳沿觸發(fā)
IT1=1;
PS=1;//串口中斷最高
ES=1;
SCON=0xd0;//設(shè)置串口方式3
PCON=0x00;
TH1=0xfd; //9600
TL1=0xfd;
TR1=1; //接受定時(shí)器
sce=0;
res=0;
res=1;
LCD_init(); //初始化LCD模塊
LCD_clear(); //清屏幕
LCD_write_chinese_string(1,0,12,4,0,0);
play:
while(1)
{
//LCD_write_chinese_string(1,0,12,4,0,0);
while(zhan);//暫停
a: {switch(y)
{
case 0:
{
P2=0X01;
p=music_tab0[i];
if(p==0x00) { i=0, delayms(1000); goto play;} //如果碰到結(jié)束符,延時(shí)1秒,回到開始再來一遍
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //若碰到休止符,延時(shí)100ms,繼續(xù)取下一音符
else {m=music_tab0[i++], n=music_tab0[i++];}
TR0=1; //開定時(shí)器1
while(n!=0) Beep=~Beep,delay(m); //等待節(jié)拍完成, 通過P1口輸出音頻
TR0=0; //關(guān)定時(shí)器1 ;
}
break; //取頻率常數(shù) 和 節(jié)拍常數(shù)
case 1:
{
P2=0X02;
p=music_tab1[i];
if(p==0x00) { i=0, delayms(1000); goto play;} //如果碰到結(jié)束符,延時(shí)1秒,回到開始再來一遍
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //若碰到休止符,延時(shí)100ms,繼續(xù)取下一音符
else {m=music_tab1[i++], n=music_tab1[i++];}
TR0=1; //開定時(shí)器1
while(n!=0) Beep=~Beep,delay(m); //等待節(jié)拍完成, 通過P1口輸出音頻
TR0=0; //關(guān)定時(shí)器1 ;
}
break; //取頻率常數(shù) 和 節(jié)拍常數(shù)
case 2:
{
P2=0X04;
p=music_tab2[i];
if(p==0x00) { i=0, delayms(1000); goto play;} //如果碰到結(jié)束符,延時(shí)1秒,回到開始再來一遍
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //若碰到休止符,延時(shí)100ms,繼續(xù)取下一音符
else {m=music_tab2[i++], n=music_tab2[i++];}
TR0=1; //開定時(shí)器1
while(n!=0) Beep=~Beep,delay(m); //等待節(jié)拍完成, 通過P1口輸出音頻
TR0=0; //關(guān)定時(shí)器1 ;
}
}
}
}
}
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
成人欧美一区二区三区黑人孕妇
|
亚洲精品一区二区三区蜜桃久
|
91精品国产91久久久久久吃药
|
欧美日韩1区2区
|
伊人网在线综合
|
国产午夜精品一区二区三区四区
|
国产一区二区不卡
|
老熟女毛片
|
亚洲国产高清在线观看
|
夜夜爽99久久国产综合精品女不卡
|
成人免费毛片在线观看
|
99久久婷婷国产综合精品
|
亚洲精品中文字幕在线
|
欧美日韩在线免费观看
|
欧美不卡一区
|
国产视频一区二区
|
久久影院一区
|
欧美电影在线观看网站
|
少妇诱惑av
|
a在线观看
|
亚洲第一色站
|
在线看无码的免费网站
|
欧美日韩一区二区在线观看
|
久久免费香蕉视频
|
免费观看色
|
亚洲一二三区免费
|
毛片网站免费观看
|
色久影院
|
女人一区
|
国产精品黄色
|
色免费视频
|
午夜视频网站
|
国产精品三级久久久久久电影
|
色婷婷久久久久swag精品
|
午夜精品久久久久久久久久久久
|
日韩视频免费看
|
欧美综合在线观看
|
91在线影院
|
午夜电影一区二区
|
一区二区三区小视频
|
亚洲欧美在线一区
|