#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
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
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【What should I do】Bullshit
- STM32 supports VCP+MSC+HID mode
- How does AD20 perform multi-person collaboration? (Multiple picture warning
- 13. [Learning LPC1768 library functions] ADC experiment
- How often should flying probe test probes be replaced?
- Learn about SPICE for circuit simulation
- Application of RPA in the customer service industry
- FPGA Competition Adventure Detailed Explanation.pdf
- How to use BlueNRG-1 AES encryption library
- Discussion on the matching problem of PA input