50191 views|0 replies

1379

Posts

0

Resources
The OP
 

Experiment 5. Controlling the sound of a single-chip microcomputer [Copy link]

The hardware connection of this experiment is the same as the previous one, and the program is not very complicated and easy to understand. What we mainly learn and refer to is the calling of his program. In the main program, it calls the "sound subroutine" and "0.5s delay subroutine", and the sound subroutine calls the "1ms delay subroutine" and "0.5ms delay subroutine".


;Main program
bb bit p2.0 ;Define bb to represent p2.0 in the following program
star: acall sund
acall d05s
ljmp star

;Sound subroutine
sund: mov r2,#250 ;Sound 250 cycles
slop1: clr bb ;Turn on v1 9015
acall d1ms ;Delay
setb bb ;Turn off v1 9015
acall d1ms
djnz r2,slop1
ret

;1ms delay subroutine
d1ms: mov r0,#2
dloop: mov r1,#250 ;Changing the value of r0 will change the sound frequency
djnz r1,$
djnz r0,dloop
ret

;0.5s delay subroutine
d05s: mov r0,#5
d05l1: mov r1,#200
d05l2: mov r2,#250
djnz r2,$
djnz r1,d05l2
djnz r0,d05l1
ret

end

In the previous sound experiment program, the sound was continuous. Here we make the sound into a subroutine, and fix the sound duration in the subroutine. Let the main program call it when needed, and return to the main program to do other work after the sound is finished. This program makes a delay of about 0.5S when it is not making a sound, so the whole program makes a sound of "bb---bb---bb......".
 

This post is from MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list