1.
Experimental tasks
When the switch SP1 is pressed , the AT89S51 microcontroller generates a "ding dong" sound which is output from the P1.0 port to the LM386 and then sent to the speaker after being amplified.
2.
Circuit diagram
Figure 4.19.1
3.
Hardware connection on the system board
(1. Connect the P1.0 port in the "MCU System" area to the SPK IN port in the "Audio Amplifier Module" area with a wire ;
(2.
Connect an
8
ohm or
16
ohm speaker
to the
SPK OUT
port
in the "Audio Amplifier Module" area
;
(3.
Connect the
P3.7/RD
port
in the "MCU System" area
to the
SP1
port
in the "Standalone Keyboard" area with a wire
;
4.
Programming methods
(1. We use the MCU real timer / counter T0 to generate 700HZ and 500HZ frequencies. According to the timer / counter T0 , we take the timing of 250us . Therefore, the frequency of 700HZ needs to go through 3 times of 250us timing, and the frequency of 500HZ needs to go through 4 times of 250us timing.
(2.
During the design process, only when
SP1
is
pressed will
T0
start working. When
T0
is finished working, it returns to the initial state.
(3.
The "ding" and "dong" sounds each take
0.5
seconds, so the timer
/
counter
T0
needs to complete
the
0.5
second timing, which
requires
2000
times based on
the 250us
benchmark
.
6.
Assembly source program
T5HZ
EQU 30H
T7HZ
EQU 31H
T05SA
EQU 32H
T05SB
EQU 33H
FLAG
BIT 00H
STOP
BIT 01H
SP1
BIT P3.7
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START:
MOV TMOD,#02H
MOV TH0, #06H
MOV TL0, #06H
SETB ET0
SETB OF
NSP:
JB SP1,NSP
LCALL DELY10MS
JB SP1,NSP
SETB TR0
MOV T5HZ, #00H
MOV T7HZ,#00H
MOV T05SA,#00H
MOV T05SB,#00H
CLR FLAG
CLR STOP
JNB STOP,$
LJMP NSP
DELY10MS:
MOV R6,#20
D1:
MOV R7,#248
DJNZ R7,$
DJNZ R6,D1
RIGHT
INT_T0:
INC T05SA
MOV A,T05SA
CJNE A,#100,NEXT
MOV T05SA,#00H
INC T05SB
MOV A,T05SB
CJNE A,#20,NEXT
MOV T05SB,#00H
JB FLAG,STP
CPL FLAG
LJMP NEXT
STP:
SETB STOP
CLR TR0
LJMP DONE
NEXT:
JB FLAG,S5HZ
INC T7HZ
MOV A,T7HZ
CJNE A,#03H,DONE
MOV T7HZ,#00H
CPL P1.0
LJMP DONE
S5HZ:
INC T5HZ
MOV A,T5HZ
CJNE A,#04H,DONE
MOV T5HZ, #00H
CPL P1.0
LJMP DONE
DONE:
NETWORKS
END
7.
C language source program
#include
unsigned char t5hz;
unsigned char t7hz;
unsigned int tcnt;
bit stop;
bit flag;
void main(void)
{
unsigned char i,j;
TMOD=0x02;
TH0=0x06;
TL0=0x06;
ET0=1;
EA=1;
while(1)
{
if(P3_7==0)
{
for(i=10;i>0;i--)
for(j=248;j>0;j--);
if(P3_7==0)
{
t5hz=0;
t7hz=0;
tcnt=0;
flag=0;
stop=0;
TR0=1;
while(stop==0);
}
}
}
}
void t0(void) interrupt 1 using 0
{
tcnt++;
if(tcnt==2000)
{
tcnt=0;
if(flag==0)
{
flag=~flag;
}
else
{
stop=1;
TR0=0;
}
}
if(flag==0)
{
t7hz++;
if(t7hz==3)
{
t7hz=0;
P1_0=~P1_0;
}
}
else
{
t5hz++;
if(t5hz==4)
{
t5hz=0;
P1_0=~P1_0;
}
}
}
Previous article:Dynamic digital display technology
Next article:Timing counter T0 as timing application technology (Part 2)
- Popular Resources
- Popular amplifiers
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
- Arduino Bluetooth Obstacle Avoidance Car
- AC Current Sensor = AC Current Transducer = AC Current Transducer
- The control motor is found to have insufficient stroke. Please provide a solution.
- [Flower carving DIY] Interesting and fun music visualization series project (27) - Magnetic stirring LED water rotating lamp
- Failed to import brd file into AD
- The battery management chip used is Zhongying's SH39F004! Why is the filtering starting from the sixth battery not filtering the GND?...
- KiCad to other EDA conversion
- 【Silicon Labs Development Kit Review】– Joy & Unboxing
- [Raspberry Pi 3B+ Review] Burning System & Locking Static IP & SSH Login & SFTP Login
- STM32F407VET6 Another question about PWM wave