Digital music box based on AT89C51

Publisher:创意航海Latest update time:2020-10-10 Source: 51heiKeywords:AT89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

#define uchar unsigned char

#define uchar unsigned char

#define uint unsigned int

#define  LCDPORT P0

uchar code tab[]="Press key";

uchar code tab1[]="Select song";

uchar code tab2[]="First Song" ;

uchar code tab3[]="butterfly";

uchar code tab4[]="Second Song"        ;

uchar code tab5[]="Jingle bell ";

uchar code tab6[]="Third Song" ;

uchar code tab7[]="Yesterday";

uchar code tab8[]="Forth Song" ;

uchar code tab9[]="Youth League";

sbit LCDE=P2^2;

sbit LCDRW=P2^1;

sbit LCDRS=P2^0;

#define SYSTEM_OSC 12000000 //Define the crystal frequency to 12000000HZ

#define SOUND_SPACE 4/5 //Define the length fraction of ordinary note playing, //Every 4th note interval

sbit BeepIO = P3^7; //define output pin

sbit K1=P1^7;

unsigned int code FreTab[12] = { 262,277,294,311,330,349,369,392,415,440,466,494 }; //Original frequency table

unsigned char code SignTab[7] = { 0,2,4,5,7,9,11 }; //The position of 1~7 in the frequency table

unsigned char code LengthTab[7]= { 1,2,4,8,16,32,64 };                                                

unsigned char Sound_Temp_TH0, Sound_Temp_TL0; // Temporary storage of initial value of note timer

unsigned char Sound_Temp_TH1,Sound_Temp_TL1;        

unsigned char code Music_Girl[]=

{ 0x1B,0x02, 0x1A,0x02, 0x1B,0x02, 0x19,0x66, 0x1A,0x03,

  0x18,0x02, 0x17,0x02, 0x16,0x0D, 0x17,0x03, 0x18,0x0D,

  0x17,0x03, 0x19,0x66, 0x17,0x03, 0x16,0x0D, 0x17,0x03,

  0x19,0x0D, 0x16,0x03, 0x17,0x0D, 0x18,0x03, 0x17,0x0D,

0x16,0x03, 0x15,0x00, 0x19,0x02, 0x11,0x02, 0x16,0x02,

0x10,0x02, 0x15,0x02, 0x0F,0x00, 0x10,0x03, 0x15,0x03,

0x0F,0x00, 0x0D,0x01, 0x0F,0x66, 0x10,0x03, 0x15,0x66,

0x16,0x03, 0x10,0x0D, 0x15,0x03, 0x0F,0x03, 0x19,0x66,

0x1F,0x03, 0x1A,0x0D, 0x19,0x03, 0x17,0x03, 0x19,0x03,

0x16,0x00, 0x16,0x66, 0x17,0x03, 0x11,0x0C, 0x10,0x02,

0x19,0x66, 0x10,0x03, 0x15,0x02, 0x16,0x02, 0x0D,0x02,

  0x15,0x02, 0x10,0x0D, 0x0F,0x03, 0x10,0x0D, 0x15,0x03,

  0x0F,0x00, 0x17,0x66, 0x19,0x03, 0x11,0x02, 0x16,0x02,

0x10,0x0D, 0x15,0x03, 0x0F,0x15, 0x0D,0x03, 0x0F,0x02,

0x0D,0x03, 0x0F,0x0D, 0x10,0x03, 0x11,0x0D, 0x16,0x03,

  0x10,0x00, 0x0F,0x0D, 0x10,0x03, 0x15,0x66, 0x16,0x03,

  0x19,0x02, 0x17,0x02, 0x16,0x02, 0x17,0x0D, 0x16,0x03,

  0x15,0x02, 0x10,0x0D, 0x0F,0x03, 0x0D,0x01, 0x15,0x01,

0x10,0x03, 0x15,0x04, 0x10,0x0D, 0x0F,0x03, 0x0D,0x0D,

0x0F,0x03, 0x10,0x0D, 0x15,0x03, 0x0F,0x00, 0x17,0x0D,

0x19,0x03, 0x16,0x0D, 0x17,0x03, 0x16,0x0D, 0x15,0x03,

  0x11,0x02, 0x10,0x02, 0x0F,0x00, 0x00,0x00 };

unsigned char code Music_Jingle[]={

0x0F,0x03, 0x0F,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x03,

0x0F,0x66, 0x19,0x04, 0x19,0x04, 0x0F,0x03, 0x17,0x03,

0x16,0x03, 0x15,0x03, 0x10,0x02, 0x10,0x03, 0x10,0x03,

0x18,0x03, 0x17,0x03, 0x16,0x03, 0x10,0x66, 0x10,0x03,

0x19,0x03, 0x19,0x03, 0x18,0x03, 0x16,0x03, 0x17,0x02,

0x15,0x03, 0x0F,0x03, 0x0F,0x03, 0x17,0x03, 0x16,0x03,

0x15,0x03, 0x0F,0x66, 0x0F,0x03, 0x0F,0x03, 0x17,0x03,

0x16,0x03, 0x15,0x03, 0x10,0x66, 0x10,0x03, 0x10,0x03,

0x18,0x03, 0x17,0x03, 0x16,0x03, 0x19,0x03, 0x19,0x03,

0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x18,0x03,

0x16,0x03, 0x15,0x66, 0x17,0x03, 0x17,0x03, 0x17,0x02,

0x17,0x03, 0x17,0x03, 0x17,0x02, 0x17,0x03, 0x19,0x03,

0x15,0x03, 0x16,0x03, 0x17,0x01, 0x18,0x03, 0x18,0x03,

0x18,0x67, 0x18,0x04, 0x18,0x03, 0x17,0x03, 0x17,0x03,

0x17,0x04, 0x17,0x04, 0x17,0x03, 0x16,0x03, 0x16,0x03,

0x15,0x03, 0x16,0x03, 0x19,0x66, 0x19,0x03, 0x19,0x03,

0x18,0x03, 0x16,0x03, 0x15,0x02, 0x00,0x00  };

unsigned char code Music_Two[] ={

0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,

0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,

0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,

0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,

0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01,

0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,

0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01,

0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,

0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,

0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,

0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03,

0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01,

0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,

0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00,

0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03,

0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03,

0x16,0x0D, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03,

0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03,

0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03,

0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E,

0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E,

0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,

0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03,

0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03,

0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03,

0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02,

0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01,

0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03,

0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,

0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,

0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,

0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02,

0x10,0x03, 0x15,0x00, 0x00,0x00 };

unsigned char code Music_Yesterday[]={

0x15,0x03, 0x15,0x03, 0x16,0x03, 0x17,0x02, 0x19,0x02,

0x19,0x03, 0x17,0x03, 0x19,0x03, 0x17,0x03, 0x1A,0x02,

0x19,0x66, 0x17,0x02, 0x17,0x03, 0x19,0x03, 0x1A,0x02,

0x16,0x02, 0x17,0x03, 0x19,0x02, 0x1A,0x15, 0x17,0x03,

0x19,0x03, 0x1A,0x02, 0x21,0x02, 0x20,0x03, 0x1F,0x02,

0x1B,0x03, 0x1B,0x66, 0x19,0x03, 0x17,0x03, 0x19,0x02,

0x17,0x02, 0x16,0x14, 0x15,0x03, 0x15,0x03, 0x16,0x03,

0x17,0x03, 0x19,0x02, 0x19,0x03, 0x19,0x03, 0x17,0x03,

0x19,0x03, 0x17,0x03, 0x1A,0x03, 0x19,0x02, 0x17,0x03,

0x17,0x02, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1B,0x02,

0x17,0x03, 0x19,0x02, 0x1A,0x03, 0x1A,0x01, 0x1B,0x02,

0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1A,0x66, 0x1B,0x03,

0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x02, 0x1A,0x66,

0x1A,0x03, 0x1B,0x03, 0x1F,0x02, 0x1F,0x02, 0x1A,0x03,

0x1F,0x02, 0x20,0x03, 0x20,0x16, 0x1F,0x02, 0x20,0x02,

0x21,0x03, 0x21,0x03, 0x21,0x03, 0x21,0x02, 0x20,0x03,

0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x66,

0x17,0x03, 0x19,0x03, 0x19,0x14, 0x1F,0x03, 0x20,0x03,

0x21,0x03, 0x21,0x03, 0x21,0x03, 0x21,0x03, 0x21,0x02,

0x20,0x03, 0x1F,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x66,

0x17,0x03, 0x19,0x03, 0x19,0x14, 0x1A,0x03, 0x1B,0x03,

0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x03,

0x20,0x66, 0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x02,

0x1F,0x03, 0x20,0x66, 0x1F,0x03, 0x20,0x03, 0x21,0x02,

0x21,0x02, 0x20,0x03, 0x1F,0x02, 0x1A,0x03, 0x1A,0x02,

0x17,0x02, 0x17,0x03, 0x1A,0x03, 0x17,0x03, 0x19,0x03,

0x19,0x14, 0x17,0x03, 0x17,0x03, 0x16,0x04, 0x15,0x04,

0x15,0x03, 0x16,0x03, 0x17,0x01, 0x17,0x03, 0x18,0x02,

0x16,0x03, 0x16,0x14, 0x17,0x03, 0x17,0x03, 0x17,0x03,

0x18,0x02, 0x16,0x03, 0x16,0x16, 0x15,0x03, 0x16,0x03,

0x17,0x03, 0x16,0x01, 0x1F,0x02, 0x20,0x02, 0x21,0x03,

0x21,0x03, 0x21,0x03, 0x21,0x02, 0x20,0x03, 0x1F,0x03,

0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x03, 0x1A,0x02,

0x17,0x03, 0x19,0x03, 0x19,0x14, 0x1F,0x02, 0x20,0x02,

0x21,0x03, 0x21,0x03, 0x21,0x03, 0x21,0x66, 0x20,0x03,

0x1F,0x03, 0x1B,0x03, 0x1F,0x03, 0x1B,0x03, 0x1A,0x66,

0x17,0x03, 0x19,0x03, 0x19,0x00, 0x00,0x00 };



uchar k;

void delay1(void) //delay program

{

        flying i,j;

        for(i=20;i>0;i--)

        for(j=248;j>0;j--);

}


void Getch (  )

{ fly X,Y,Z;

        P1=0xff;

        P1=0xf3; //First set the number of P0 and scan the line

        if(P1!=0xf3) // Check if a key is pressed

                { delay1(); //delay, software interference removal

                         if(P1!=0xf3) //Confirm button is pressed X = P3;

                          {        

                                X=P1; //Save the status when a key is pressed during row scanning

                                P1=0xfc; //column scan

                                Y=P1; //Save the status when a key is pressed during column scanning

                                 Z=X|Y;

        //Get the key value

                                switch ( Z ) //Judge the key value (which key is pressed)

                                {

                                        case 0xf9: k=0; break; //Assign key value

                                        case 0xf5: k=1; break;

                                        case 0xfa: k=2; break;

                                        case 0xf6: k=3; break;

                                       

                                }

                          }

                }        

}                  

void Delay()

{         uint uiCount;

         for(uiCount=0;uiCount<250;uiCount++);

}


void WriteCMD(uchar Commond) //LCD write instruction function      

{

Delay(); //Delay first.

LCDE=1; //Then change the LCD to write command status.

LCDRS=0;

LCDRW=0;

LCDPORT=Commond; //Output command again.

LCDE=0; //Finally execute the command.

}


void WriteData(uchar dat) //LCD write data function      

{ Delay(); //Delay first.

LCDE=1; //Then change the LCD to write data state.

LCDRS=1;

LCDRW=0;

LCDPORT=dat; //Output data again.

LCDE=0; //Finally display the data.

}


void init()

{

         LCDRW=0;

    LCDE=0;

          WriteCMD(0x38);

         WriteCMD(0x0c);

         WriteCMD(0x06);

         WriteCMD(0x01);

         WriteCMD(0x80);

}


void mydelay(int x)

{ int i,j;

for(i=x;i>0;i--)

for(j=255;j>0;j--);

}

void InitialSound(void)

{

        BeepIO = 0;

        Sound_Temp_TH1 = (65535-(1/1200)*SYSTEM_OSC)/256; // Calculate the initial value that TL1 should be loaded with (initial value of 10ms)

        Sound_Temp_TL1 = (65535-(1/1200)*SYSTEM_OSC)%256; // Calculate the initial value that TH1 should be loaded with

        TH1 = Sound_Temp_TH1;

        TL1 = Sound_Temp_TL1;

        TMOD  |= 0x11;

        ET0    = 1;

        ET1 = 0;

        TR0           = 0;

        TR1    = 0;

        EA = 1;

}


void BeepTimer0(void) interrupt 1 //Interrupt when a note occurs

{

        BeepIO = !BeepIO;

        TH0    = Sound_Temp_TH0;

         TL0    = Sound_Temp_TL0;

}


   void Play(unsigned char *Sound,unsigned char Signature,unsigned Octachord,unsigned int Speed)

{

        unsigned int NewFreTab[12]; //New frequency table

[1] [2]
Keywords:AT89C51 Reference address:Digital music box based on AT89C51

Previous article:51 single chip microcomputer automatic water vending machine program
Next article:Two-way motor drive H-bridge L9110

Recommended ReadingLatest update time:2024-11-17 00:08

Design of RFID car anti-theft system based on GSM network
1. Features of anti-theft system Early car anti-theft systems were mainly composed of mechanical door locks and wheel locks. The function of the car locks has evolved from simply controlling the opening of the car door to controlling the ignition and manipulating the car circuit. With the development of moder
[Microcontroller]
Design of RFID car anti-theft system based on GSM network
Design of Multi-point Temperature Detection System Based on AT89C51
0 Introduction In industrial production and daily life, multi-point temperature detection systems are widely used, such as non-destructive temperature detection of fire protection electrical equipment, overheating fault prediction detection of power equipment, temperature detection of air-conditioning syste
[Microcontroller]
Design of time/displacement commutation controller based on microcontroller AT89C51
introduction In the actual production process, control components with automatic reversing functions are often used, such as round-trip operation (displacement) in machining, forward and reverse output of DC power supply, forward and reverse operation of motors, etc. When the forward (or reverse) operation reaches a
[Microcontroller]
Design of automatic range switching frequency with AT89C51 microcontroller as the core
In recent years, with the rapid development of science and technology, especially the rapid rise of related integrated circuit production technologies such as microcontrollers, it has promoted the rapid development of the instrumentation and home appliance industries. Program codes are used to simplify the complexity
[Microcontroller]
Design of automatic range switching frequency with AT89C51 microcontroller as the core
Single chip microcomputer (AT89C51) timer/counter experiment case
case analysis Here are three types that are often encountered: It is known that the 8051 microcontroller's fosc=12MHz is timed by T1. Try to program the P1.0 pin to output a square wave with a period of 2ms. Given that the 8051 microcontroller has a fosc of 12MHz and uses T1 for timing, try programming the P1.0 pi
[Microcontroller]
Single chip microcomputer (AT89C51) timer/counter experiment case
Sharing of DC motor PWM speed control program based on AT89C51 single chip microcomputer
This is a PWM speed control program for DC motors with AT89C51 MCU. The program can be directly used in AT89C52, AT89S51, AT89S51, STC89C51, STC89C52 MCUs. The MCU crystal uses 11.0592M. The DC motor is controlled by L298 integrated circuit. The frequency of the generated PWM is about 91Hz. The pins of L298 have been
[Microcontroller]
Sharing of DC motor PWM speed control program based on AT89C51 single chip microcomputer
AT89C51 digital electronic clock
This digital clock can achieve a variable precision clock with an accuracy error of ≤ 1S/day, and can easily adjust the clock, time, timing time, etc.              LED1 bit p1.0; LED definition         led2 bit p1.1              led3 bit p1.2         led4 bit p1.3        led5 bit p1.4        led6 bit p1.5         led7
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号