• 大小: 20KB
    文件类型: .c
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: C/C++
  • 标签:

资源简介

C语言编写的用按键控制单片机播放音乐,用来学习播放音乐最适合。

资源截图

代码片段和文件信息

#include
#include 

#define uchar unsigned char
#define uint unsigned int
uchar Count;

void delayms(unsigned int ms);
void lcd_init();
void lcd_wcmd(unsigned char cmd bit Check);
void lcd_wdat(unsigned char dat);
void lcd_pos(unsigned char xpos unsigned char ypos);
void wr_string(unsigned char str[]);
void  huange();
void music1();
void music2();
void music3();

/***************************************************************************/
#ifndef __SOUNDPLAY_H_REVISION_FIRST__
#define __SOUNDPLAY_H_REVISION_FIRST__

//**************************************************************************

#define SYSTEM_OSC  12000000 //定义晶振频率12000000HZ
#define SOUND_SPACE  4/5  //定义普通音符演奏的长度分率//每4分音符间隔
sbit    BeepIO    =    P3^7; //定义输出管脚

unsigned int  code FreTab[12]  = { 262277294311330349369392415440466494 }; //原始频率表
unsigned char code SignTab[7]  = { 02457911 };    //1~7在频率表中的位置
unsigned char code LengthTab[7]= { 1248163264 };
unsigned char Sound_Temp_TH0Sound_Temp_TL0; //音符定时器初值暂存 
unsigned char Sound_Temp_TH1Sound_Temp_TL1; //音长定时器初值暂存



#define DATA_PORT  P0

sbit LCD_RS = P2 ^ 0;
sbit LCD_RW = P2 ^ 1;
sbit LCD_EN = P2 ^ 2;

sbit Speak =P3^7; //蜂鸣器器控制脚  

/*以下数组是音符编码*/ 

unsigned char key;

unsigned char code key_code[] =
{
  //键编码数组
  0xee 0xed 0xeb 0xe7 0xde 0xdd 0xdb 0xd7 0xbe 0xbd 0xbb
  0xb7 0x7e 0x7d 0x7b 0x77
};


//*****************************Music******************************************************
//挥着翅膀的女孩
unsigned char code Music_Girl[]={ 0x170x02 0x170x03 0x180x03 0x190x02 0x150x03
                                  0x160x03 0x170x03 0x170x03 0x170x03 0x180x03
                                  0x190x02 0x160x03 0x170x03 0x180x02 0x180x03
                                  0x170x03 0x150x02 0x180x03 0x170x03 0x180x02
                                  0x100x03 0x150x03 0x160x02 0x150x03 0x160x03
                                  0x170x02 0x170x03 0x180x03 0x190x02 0x1A0x03
                                  0x1B0x03 0x1F0x03 0x1F0x03 0x170x03 0x180x03
                                  0x190x02 0x160x03 0x170x03 0x180x03 0x170x03
                                  0x180x03 0x1F0x03 0x1F0x02 0x160x03 0x170x03
                                  0x180x03 0x170x03 0x180x03 0x200x03 0x200x02
                                  0x1F0x03 0x1B0x03 0x1F0x66 0x200x03 0x210x03
                                  0x200x03 0x1F0x03 0x1B0x03 0x1F0x66 0x1F0x03
                                  0x1B0x03 0x190x03 0x190x03 0x150x03 0x1A0x66
                                  0x1A0x03 0x190x03 0x150x03 0x150x03 0x170x03
                                  0x160x66 0x170x04 0x180x04 0x180x03 0x190x03
                                  0x1F0x03 0x1B0x03 0x1F0x66 0x20

评论

共有 条评论