日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

单片机音频节奏灯_用C51写的单片机音乐彩灯程序

發(fā)布時(shí)間:2023/11/27 生活经验 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 单片机音频节奏灯_用C51写的单片机音乐彩灯程序 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

#define TLEDS 20//每個(gè)花樣狀態(tài)持續(xù)時(shí)間,以50mS為單位

#define NUM_OF_LED_S 4//每種模式LED花樣數(shù)?

typedef unsigned char uchar;

typedef unsigned int uint;

data uchar led_array_num;//當(dāng)前模式下,LED花樣狀態(tài)序號

data uchar music_array_num;//音符的序號

data uchar i;//模式號

data uchar t_count_led;//用于LED狀態(tài)持續(xù)時(shí)間計(jì)時(shí)

data uint t_count_music;//

data uint t_yinfu;//音符持續(xù)時(shí)間

uchar code led_array_p0[4][NUM_OF_LED_S]={{0xc0,0xc0,0xc0,0xc0},{0x38,0x38,0x38,0x38},{0x05,0x07,0x02,0x07},{0xff,0x81,0xff,0xff}};

uchar code led_array_p2[4][NUM_OF_LED_S]={{0x07,0x0b,0x0d,0x0e},{0x07,0x09,0x0e,0x00},{0x06,0x09,0x06,0x00},{0x07,0x09,0x0e,0x00}};

uchar code music_array_h[4][128]={{0xfc,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfe,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,

0xfc,0xfc,0xfc,0xfc,0xfc,0xf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,0x43,0x43,0x81,0x43,0x43,0x81,0x43},{0x03,0x03,0x8f,0x03,0x43,0x0b,0x03,0x03,0x8f,0x03,0xb5,0x43,0x03,0x03,0x81,0x08,0x43,0x0b,0x8f,0x33,0x33,0x08,0x43,0xb5,0x43},{0x43,0x43,0x81,0x81,0xc7,0xc7,0x81,0x33,0x33,0x08,0x08,0xb5,0xb5,0x43,0x81,0x81,0x33,0x33,0x08,0x08,0xb5,0x81,0x81,0x33,0x33,0x08,0x08,0xb5,0x43,0x43,0x81,0x81,0xc7,0xc7,0x81,0x33,0x33,0x08,0x08,0xb5,0xb5,0x43}};

uint code music_array_t[4][128]={{523,523,523,658,784,784,784,784,880,880,880,1046,784,698,698,698,880,658,658,658,784,593,593,593,593,593,784,784,523,523

,523,658,784,784,784,784,880,880,880,1046,784,698,698,698,880,658,658,658,658,658,784,593,593,593,593,658,523,0},{523,593,658,523,523,593,658,523,658,698,3134,658,698,3134,391,440,391,698,658,523,391,568,391,698,658,523,523,784,1046,523,784,1046,0},{391,391,880,391,523,1486,391,391,880,391,593,1569,391,391,3134,658,523,988,440,698,698,1317,523,593,1569,0},{523,523,784,784,880,880,784,698,698,658,658,593,593,523,784,784,698,698,658,658,593,784,784,698,698,658,658,593,523,523,784,784,880,880,784,698,698,658,658,593,593,523,0}};

void delay(void)

{

uchar c_1;

uchar c_2;

uchar c_3;

for (c_1=0; c_1< 10;c_1++)

for(c_2 = 0;c_2< 10;c_2++)

for(c_3 = 0; c_3<55;c_3++)

;

}

void main(void)

{

led_array_num = 0;

music_array_num = 0;

t_yinfu = music_array_t[0][0];? //初始化

//delay();

i = 0;

TMOD = 0x11;? //定時(shí)器工作方式設(shè)置

TR0 = 0; //關(guān)定時(shí)器

TR1 = 0;

TH1 = 0x3c;

TL1 = 0xb0;

P0 = led_array_p0[0][0];//彩燈

P2 = led_array_p2[0][0];

t_count_led = 0;

TH0 = music_array_h[0][0];//音樂

TL0 = music_array_l[0][0];

t_yinfu = music_array_t[0][0];

t_count_music = 0;

IE = 0x8a;

TR0 = 1;

TR1 = 1;

//以下開始掃描按鍵

while(1)

{

P1_0 = 1;

if(P1_0 == 0)

{

delay();

if(P1_0 == 0)

{

TR0 = 0;

TR1 = 0;

i = 0;//去抖動(dòng)

led_array_num = 0;

music_array_num = 0;

TH1 = 0x3c;

TL1 = 0xb0;

P0 = led_array_p0[0][0];//彩燈

P2 = led_array_p2[0][0];

t_count_led = 0;

TH0 = music_array_h[0][0];//音樂

TL0 = music_array_l[0][0];

t_yinfu = music_array_t[0][0];

t_count_music = 0;

while(P1_0 == 0)

{

while(P1_0 == 0)

t_count_music = 0;

delay();

}

TR0 = 1;

TR1 = 1;

}

}

if(P1_1 == 0)

{

delay();

if(P1_1 == 0)

{

TR0 = 0;

TR1 = 0;

i = 1;

led_array_num = 0;

music_array_num = 0;

TH1 = 0x3c;

TL1 = 0xb0;

P0 = led_array_p0[1][0];//彩燈

P2 = led_array_p2[1][0];

t_count_led = 0;

TH0 = music_array_h[1][0];//音樂

TL0 = music_array_l[1][0];

t_yinfu = music_array_t[1][0];

t_count_music = 0;

while(P1_1 == 0)

{

while(P1_1 == 0)

t_count_music = 0;

delay();

}

TR0 = 1;

TR1 = 1;

}

}

if(P1_2 == 0)

{

delay();

if(P1_2 == 0)

{

TR0 = 0;

TR1 = 0;

i = 2;

led_array_num = 0;

music_array_num = 0;

TH1 = 0x3c;

TL1 = 0xb0;

P0 = led_array_p0[2][0];//彩燈

P2 = led_array_p2[2][0];

t_count_led = 0;

TH0 = music_array_h[2][0];//音樂

TL0 = music_array_l[2][0];

t_yinfu = music_array_t[2][0];

t_count_music = 0;

while(P1_2 == 0)

{

while(P1_2 == 0)

t_count_music = 0;

delay();

}

TR0 = 1;

TR1 = 1;

}

}

if(P1_3 == 0)

{

delay();

if(P1_3 == 0)

{

TR0 = 0;

TR1 = 0;

i = 3;

led_array_num = 0;

music_array_num = 0;

TH1 = 0x3c;

TL1 = 0xb0;

P0 = led_array_p0[3][0];//彩燈

P2 = led_array_p2[3][0];

t_count_led = 0;

TH0 = music_array_h[3][0];//音樂

TL0 = music_array_l[3][0];

t_yinfu = music_array_t[3][0];

t_count_music = 0;

while(P1_3 == 0)

{

while(P1_3 == 0)

t_count_music = 0;

delay();

}

TR0 = 1;

TR1 = 1;

}

}

}

}

void Timer0IntRoute(void) interrupt 1

{

t_count_music++;

P1_4 = ~P1_4;

TH0 = music_array_h[i][music_array_num];//音樂

TL0 = music_array_l[i][music_array_num];

if(t_count_music >= t_yinfu)

{

t_yinfu = music_array_t[i][++music_array_num];

if(t_yinfu == 0)

{

music_array_num = 0;

t_yinfu = music_array_t[i][music_array_num];

}

TH0 = music_array_h[i][music_array_num];//音樂

TL0 = music_array_l[i][music_array_num];

t_count_music = 0;

}

}

void Timer1IntRoute(void) interrupt 3

{

t_count_led++;

TH1 = 0x3c;

TL1 = 0xb0;

if(t_count_led >= TLEDS)

{

t_count_led = 0;

led_array_num++;

if(led_array_num>=NUM_OF_LED_S)

led_array_num = 0;

P0 = led_array_p0[i][led_array_num];

P2 = led_array_p2[i][led_array_num];

}

}

總結(jié)

以上是生活随笔為你收集整理的单片机音频节奏灯_用C51写的单片机音乐彩灯程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。