Multi-mode 51 single-chip heart-shaped water light + breathing light + buzzer music

Publisher:码农创想家Latest update time:2020-03-20 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Basic hardware DIY design

Circuit Hardware:

[MCU]STC89C52RC

[Peripherals]Buzzer/24 LEDs/4 corner buttons


1) Overall schematic diagram

insert image description here

2) PCB circuit

insert image description here

3) 3D_PCB

TOP layer

insert image description here

2. MCU Programming

1) Breathing light [simple analog PWM]

//Breathing light [PWM modulation]

while(1)

{

for(high=1;high {

P2=P1=P0=0XFF;

delay2(high);

P2=P1=P0=0X00;

low=cycle-high;

delay2(low);

}

for(low=1;low {

P2=P1=P0=0XFF;;

high=cycle-low;

delay2(high);

P2=P1=P0=0X00;

delay2(low);

}

}


2) Buzzer music

// Define the simple blue and white porcelain music score [timer generates music pulse]


// Define the simple blue and white porcelain music score [timer generates music pulse]

uchar code music[][2]={{0,4},

{0,4},{24,4},{24,4},{21,4},{19,4},{21,4},{14,8},{19,4},{21,4},{24,4},{21,4},{19,16},{0,4},{24,4},{24,4},{21,4},{19,4},{21,4},{12,8},{19,4},{21,4},{24,4},{19,4},{17,16},{0,4},{17,4},{19,4},{21,4},

{24,4},{26,4},{24,4},{22,4},{24,4},{21,4},{21,4},{19,4},{19,16},{0,4},

{17,4},{19,4},{17,4},{17,4},{19,4},{17,4},{19,4},{19,4},{21,8},{24,4},{21,4},{21,12},{0,4},{24,4},{24,4},{21,4},{19,4},{21,4},{14,8},{19,4},{21,4},{24,4},{21,4},{19,16},{0,4},{24,4},{24,4},{21,4},

{19,4},{21,4},{12,8},{19,4},{21,4},{24,4},{19,4},{17,16},{0,4},{17,4},{19,4},{21,4},{24,4},{26,4},{24,4},{22,4},{24,4},{21,4},{21,4},{19,4},{19,12},{12,4},{21,8},{19,4},{19,8},{17,16},

{0xFF,0xFF}};


//Buzzer music [Timer generates music pulse]

while(1)

{

m=music[i][0];n=music[i][1]; 

if(m==0x00)

{TR0=0;delay1(n);i++;} 

else if(m==0xFF)

{TR0=0;delay1(30);i=0;} 

else if(m==music[i+1][0]) 

{TR0=1;delay1(n);TR0=0;pause();i++;}

else

{TR0=1;delay1(n);i++;}

}

}


3) Several simple water lights

//Buzzer music [Timer generates music pulse]

void disp10() //State 10: All LEDs are turned off (3 LEDs with 8 grids are turned off counterclockwise)

{

for(i=0;i<9;i++)

{

P0=table5[i];

P2=table4[i];

P1=table4[i];

delay(100);

}

delay(300);

}


void disp11() //State 11 The 3 LEDs are lit for 8 consecutive grids and rotate clockwise

{

for(j=0;j<2;j++)

{

for(i=0;i<8;i++)

{

P0=table0[i];

P2=table1[i];

P1=table1[i];

delay(100);

}

P0=0xff; P2=0xff; P1=0xff;

for(i=0;i<8;i++)

{

P0=table0[i];

P2=table1[i];

P1=table1[i];

delay(100);

}

P0=0xff; P2=0xff; P1=0xff; 

}

}


void disp12() //3 LEDs light up intermittently for 8 grids, and then gradually light up clockwise (until all are lit)

{

for(i=0;i<8;i++)

{

P0=table2[i];

P2=table3[i];

P1=table3[i];

delay(100);

}

delay(1000);

}


void disp13() //State 13: All LEDs are turned off (3 LEDs with 8 grids of intervals start to turn off clockwise)

{

for(i=0;i<8;i++)

{

P0=table4[i];

P2=table5[i];

P1=table5[i];

delay(100);

}

delay(300);

}


void disp14() //State 14: LED turns off to full brightness (gradually lights up from P0.0, P1.0, P1.7, and P2.0)

{

for(i=0;i<8;i++)

{

P0=table2[i];

P2=table2[i];

if(i<4)

{

P1=table8[i];

}

delay(100);

}

}


void disp15() //State 15: LED turns from fully lit to fully off (gradually turns off from P0.7, P1.3, P1.4, and P2.7)

{

for(i=0;i<8;i++)

{

P0=table5[i];

P2=table5[i];

if(i<4)

{

P1=table11[i];

}

delay(100);

}

}


3. Effect display

image.png

1) Top-level diagram of the physical circuit

insert image description here

2) Physical circuit bottom diagram

insert image description here

The interior is relatively simple (* ̄︶ ̄)


3) Overall effect diagram

Rechargeable design


Built-in lithium battery connected to lithium battery charging module [can be charged via mini-USB charging port]


Playability


Three debug buttons and one reset button are reserved

The program can be improved: Press the function key to switch modes directly without pressing reset.

insert image description here

Reference address:Multi-mode 51 single-chip heart-shaped water light + breathing light + buzzer music

Previous article:Learning experience of addressing mode of single chip microcomputer C51 assembly instruction
Next article:Getting Started with 51 MCU - Lighting up the First LED

Latest Microcontroller Articles
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号