Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Microcontroller Design Sharing and Customization

Diary of an Electronics Engineer

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Specific Implementation Function:

Using the 51 microcontroller and 24C04 to store music and play it through a speaker.

Design Introduction

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Introduction to the 51 Microcontroller

The 51 microcontroller is a low-power, high-performance CMOS 8-bit microcontroller with 8K of programmable Flash memory, providing a highly flexible and efficient solution for numerous embedded control applications.

The 51 series microcontrollers have the following standard features:

8k bytes of Flash, 512 bytes of RAM,

32 I/O lines, watchdog timer,

Built-in 4KB EEPROM,

MAX810 reset circuit,

Three 16-bit timers/counters,

A 6-vector, 2-level interrupt structure,

Full-duplex serial port.

Additionally, the 51 series can stop the CPU in idle mode, allowing RAM, timers/counters, serial ports, and interrupts to continue functioning. In power-down protection mode, the RAM content is preserved, the oscillator is frozen, and the microcontroller stops working until the next interrupt or hardware reset.The chip used in this design is compatible with all 51 series microcontrollers (including AT series and STC series).

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Design Approach

Literature Research Method: Collect and organize relevant research materials, read literature to prepare for the study;

Survey Research Method: Discover related problems and solutions through surveys, analysis, and specific experiments;

Comparative Analysis Method: Compare the specific principles of different designs and the performance differences of similar sensors, analyzing the current research status and development prospects of the system;

Software and Hardware Design Method: Implement hardware through software and hardware design, and finally test whether all functions meet the requirements.

Reference template for microcontroller design papers:

Graduation Project Worry-Free | Microcontroller Graduation Project Paper Template

Design Content

Simulation Diagram (Proteus 8.7)

This design uses Proteus 8.7 software for simulation design, as shown in the figure.

Note: Free sharing, please draw the simulation according to the figure below!!

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Proteus 8.7 software materials and simulation solutions:

Proteus 8.7 installation and cracking tutorial (includes installation package)

Common problems and solutions for Proteus simulation

Simple tutorial for Proteus 8.7

Program (Keil 5)

This design uses KEIL 5 software for program design.

Note: All code is shared for free, please create your own project!!!!

This design is written in C language, and the complete code is as follows:

#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define NOP4() {_nop_();_nop_();_nop_();_nop_();}
sbit SCL = P1^0;
sbit SDA = P1^1;
sbit SPK = P3^0;
uchar code HI_LIST[] = {
	0,226,229,232,233,236,238,240,241,242,245,246,247,248};
uchar code LO_LIST[] = {
	0,4,13,10,20,3,8,6,2,23,5,26,1,4,3};
uchar code Song_24C04[] = {
	1,2,3,1,1,2,3,1,3,4,5,3,4,5};
uchar sidx;
void DelayMS(uint x){
	uchar t;
	while(x--){
		for(t=120;t>0;t--);
	}
}
void Start(){
	SDA=1;SCL=1;NOP4();SDA=0;NOP4();SCL=0;
}
void Stop(){
	SDA=0;SCL=0;NOP4();SCL=1;NOP4();SDA=1;
}
void RACK(){
	SDA=1;NOP4();SCL=1;NOP4();SCL=0;
}
void NO_ACK(){
	SDA=1;SCL=1;NOP4();SCL=0;SDA=0;
}
void Write_A_Byte(uchar b){
	uchar i;
	for(i=0;i<8;i++){
		b<<=1;SDA=CY;_nop_();SCL=1;NOP4();SCL=0;
	}
	RACK();
}
void Write_IIC(uchar addr,uchar dat){
	Start();
	Write_A_Byte(0xa0);
	Write_A_Byte(addr);
	Write_A_Byte(dat);
	Stop();
	DelayMS(10);
}
uchar Read_A_Byte(){
	uchar i,b;
	for(i=0;i<8;i++){
		SCL=1;b<<=1;B|=SDA;SCL=0;
	}
	return b;
}
uchar Read_Current(){
	uchar d;
	Start();
	Write_A_Byte(0xa1);
	d=Read_A_Byte();
	NO_ACK();
	Stop();
	return d;
}
uchar Random_Read(uchar addr){
	Start();
	Write_A_Byte(0xa0);
	Write_A_Byte(addr);
	Stop();
	return Read_Current();
}
void T0_INT() interrupt 1{
	SPK=!SPK;
	TH0=HI_LIST[sidx];
	TL0=LO_LIST[sidx];
}
void main(){
	uchar i;
	IE=0x82;
	TMOD=0x00;
	for(i=0;i<14;i++){
		Write_IIC(i,Song_24C04[i]);
	}
	while(1){
		for(i=0;i<14;i++){
			sidx=Random_Read(i);
			TR0=1;
			DelayMS(300);
		}
	}
}

The running result is shown in the figure:

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

Keil C51 software materials and usage tutorials:

Keil C51 installation and cracking tutorial (includes installation package)

Tips for using KEIL5

Simple tutorial for Keil 5

Contact Us

Music Storage and Speaker Playback Using 51 Microcontroller and 24C04

More design content:

Microcontroller Physical Design

Microcontroller Simulation Design Projects

Microcontroller Tutorials

Free Design Materials (C Language)

Free Design Materials (Assembly)

Common Problem Solutions

Welcome to follow the WeChat public account “Diary of an Electronics Engineer“!!

If you want to contact us, please reply with the keyword “Customer Service” in the public account!!

Leave a Comment