單片機(jī)教程實(shí)戰(zhàn) 蜂鳴器唱歌(SCM tutorial, Combatbuzzer singing)_第1頁(yè)
單片機(jī)教程實(shí)戰(zhàn) 蜂鳴器唱歌(SCM tutorial, Combatbuzzer singing)_第2頁(yè)
單片機(jī)教程實(shí)戰(zhàn) 蜂鳴器唱歌(SCM tutorial, Combatbuzzer singing)_第3頁(yè)
單片機(jī)教程實(shí)戰(zhàn) 蜂鳴器唱歌(SCM tutorial, Combatbuzzer singing)_第4頁(yè)
單片機(jī)教程實(shí)戰(zhàn) 蜂鳴器唱歌(SCM tutorial, Combatbuzzer singing)_第5頁(yè)
已閱讀5頁(yè),還剩19頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、單片機(jī)教程實(shí)戰(zhàn)2 蜂鳴器唱歌(SCM tutorial, Combat 2 buzzer singing)This article is contributed by 009 refugeesDOC documents may experience poor browsing on the WAP side. It is recommended that you first select TXT, or download the source file to the local view.SCM tutorial, Combat 2 buzzer singingRelease: 2009-11

2、-04 09:01 | Author: ordinary | source: network | view: 189The use of single-chip microcontroller (or SBC) music is probably one of the radio enthusiasts interested in problems. In this paper, the basic single-chip microcomputer experiment between the starting point, talk about the principles of musi

3、c programming principles, procedures, design principles, and gives specific examples for reference. The basic pronunciation experimental program design principle of single-chip we know that the sound frequency range of about tens to thousands of Hertz, if can use the program to control the single ma

4、chine of a line of high level or low level, in the mouth of the line will be able to produce a certain frequency square wave frequency, connected to the speakers can send certain the frequent rate of voice, if the use of delay time control program for high and low level, can change the output freque

5、ncy, thus changing the tone. For example, to produce 200HZ audio signals, according to figure 1 (if the temporary access horn experiment, can also be directly connected to P1 port in the horn line), the experimental procedure is: the subroutine DEL delay subroutine, when R3 is 1, the delay time is a

6、bout 20us, R3 stored in the 200HZ audio delay constant. The cycle is 1/200, which is 5ms seconds. Thus, when the P1.4 high or low duration is 2.5ms, or the time constant of R3 takes 2500/20=125 (7DH), the 200HZ tone can be emitted. Type the program into the learning machine and constantly modify the

7、 R3 constant to feel the change in pitch. In music, each note corresponds to a definite frequency. Table 1 gives the notes and their corresponding time constants at the C tone. According to the constants provided in Table 1, the reader can send his 16 decimal code to R3 and practice it repeatedly. A

8、ccording to table 1, the notes can be played. Thats not enough. One must accurately control the tempo of a piece of music, that is, the duration of a note. We can use the timer T0 to control the tempo of the note and send different initial values to produce different timing times. Just as the tempo

9、of a song is 94 beats per minute, or 0.64 beats per second. The relation between other beats and time is shown in table 2. However, since the maximum timing time of the T0 is only 131 MS, it is impossible to achieve different beats directly by changing the initial time value of the T0. We can use T0

10、 to generate a 10 millisecond time base, and then set an interrupt counter that controls the length of the beat by judging the value of the interrupt counter. The time constants corresponding to various beats are also shown in table 2. For example, for 1/4, the note is timed for 0.16 seconds, and th

11、e corresponding time constant is 16 (i.e. 10H); for 3 beat notes, the timing is 1.92 seconds, and the corresponding length of time is 192 (i.e., C0H). We will be the time constant of each note and its corresponding beat constant as a group, according to the order of all the constants in music are ar

12、ranged into a table, then the table procedures are removed from the notes and rhythm control, can realize the performance effect. In addition, the terminator and body stop can be represented respectively by code 00H and FFH, if the look-up table is 00HIndicates the end of the song; if the result of

13、the look-up table is FFH, the corresponding Pause effect is produced. In order to produce a rhythmic rhythm of the hand, a note is played in some notes (such as two identical notes) with a slightly different note inserted into the frequency of a unit of time. The block diagram is shown in figure 2.

14、Here is the program order, which can be played directly on the TD-III learning machine. For other types of learning machines, you just need to change the address accordingly. The program is playing folk songs, August osmanthus everywhere open, C tune, the rhythm of 94 beats / min. Readers can also f

15、ind a song on their own,According to the constant given in Table 1 and table 2, will be translated into music code into the machine, and the same procedure. This experiment method is simple, even if the person who doesnt understand music, it is easy to translate an unfamiliar piece of music into the

16、 code. It is interesting to learn a song with the performance of the machine. List of procedures (see the source instructions for a short time).Radio, 1992, issue third. Hardware connection: connecting hardware that just find a simulation machine or what MCU board, as long as you can work on the lin

17、e, the program input operation, but after a simulation speaker (should have one pair of you beside the computer) dial plug, plug connected to the front end of the P1. 0, on the back of the line to find the root line of the microcontroller, it should sound, and then how to improve the hardware connec

18、tion is your thing. youSCM tutorial, practical 3 keyboard scanning identificationRelease: 2009-11-04 09:02 | Author: ordinary | source: network | view: 150A keyboard is a switch matrix made up of several buttons. It is the most common input device for microcomputers. The user can input instructions,

19、 addresses and data to the computer through the keyboard and keyboard. Mining and general encoding keyboard MCU system, encoding keyboard is composed of SCM software system data system to identify the closed key on the keyboard, it has the advantages of simple structure, flexible use of which has be

20、en widely used, used in single-chip microcomputer system. Features: 1. Jitter of button switchFigure 1, figure 2The keys of the keyboard consist of two kinds of contact type and non-contact type. The application of the single chip microcomputer is usually made up of mechanical contact. In the figure

21、 below, when the switch S is not pressed, P1. The 0 input is high, and the S is closed after the P1. The 0 input is low. As the key is mechanical contact, when the mechanical contact is broken and closed, there will be jitter, P1. The waveform of the 0 input is shown in figure 2. This jitter is the

22、feeling of people, but on the computer, is completely can be sensed, because the computer processing speed is microsecond, while mechanical jitter time is at least a millisecond, on the computer, it has been a long time. As we mentioned earlier, there was a problem when interrupting. That is to say,

23、 sometimes the buttons are flexible and sometimes not working. Thats the reason. You only press the button once, but the computer has performed several interrupts,If the number of times of execution is exactly odd, then the result is as you would expect, and if the number of times executed is even n

24、umbered, it is wrong. In order for CPU to correctly read the state of the P1 port and make only one response to each keystroke, we must consider how to remove jitter. There are two commonly used dithering methods: hardware and software. SCM commonly used software method, therefore, for hardware meth

25、ods, we do not introduce. Software law is actually very simple, that is, in single-chip access to P1. After 0 messages are low, it is not immediately recognized that the S1 has been pressed, but is delayed 10 milliseconds or longer after some time to detect the P1 again. If 0 is still low, the S1 is

26、 indeed pressed, which actually avoids the jitter when the button is pressed. After detecting the release of the key (P1. 0 is high) and then 5-10 milliseconds delay, eliminate the trailing edge jitter, and then the key value processing. However, under normal circumstances, we usually do not deal wi

27、th the release of the back of the button, and practice has proved that it can also meet certain requirements. Of course, in practical applications, the requirements of the buttons are also very different. It is necessary to program the program according to different requirements, but the above is th

28、e principle of eliminating the key and dithering. 2 、 keyboard and SCM connectionFigure 4Figure 31, through the 1/0 port connection. Each button to one end of the microcontroller I/O port, and the other end of the ground, this is the easiest way, as shown in Figure 3 is the experimental board button

29、 access, four buttons received P3.2, P3.3, P3.4 and P3.5. For this key, each program can use the method of continuous inquiry, the function is: check whether there is a key to close, if there is a key closed, then remove the key jitter, determine the key number, and transferred to the corresponding

30、key processing. Here is a routine. The function is very simple, four keys are defined as follows: P3.2:, press this button is light to flow (top-down) P3.3: stop, press this button is to stop the flow, all the lights for the dark P3.4:, press this button, the lamp flows from top to bottomP3.5:, pres

31、s this button, the lamp flows up and down UpDown EQU 00H StartEnd EQU 01H; downlink symbol; start and stop sign LAMPCODE EQU 21H; the flow of data stored ORG code 0000H AJMP MAIN ORG 30H MAIN: MOV SP, #5FH MOV P1, #0FFH CLR UpDown; start in the up state of CLR StartEnd; MOV LAMPCODE #0FEH is in a st

32、opped state, starting; single lamp flow code LOOP: ACALL KEY; JNB F0 LNEXT calls the keyboard program,; if no key is pressed, ACALL will continue to KEYPROC; otherwise the call handler LNEXT: ACALL LAMP keyboard; call lights display program AJMP LOOP; repeated cycle, the main program is over DELAY:;

33、 MOV R7, #100 D1: MOV R6, #100 DJNZ R6, $DJNZ R7, D1 RET; delay procedures, keyboard processing call KEYPROC: MOV A, B JB ACC.2; get the keys from the B register, KeyStart; analysis of key generation If the bit is pressed, the bit is 1 (because it has been reversed in the keyboard program), JB, ACC.

34、3, KeyOverJB ACC.4, KeyUp JB ACC.5, KeyDown AJMP KEY_RET KeyStart: SETB StartEnd; the first key is pressed after the treatment of AJMP KEY_RET KeyOver: CLR StartEnd; second key press after processing AJMP third KEY_RET KeyUp: SETB UpDown; AJMP KEY_RET key press after treatment of KeyDown: CLR UpDown

35、; fourth KEY: key pressed processing KEY_RET:RET CLR F0 Qing; F0, said no key is pressed. ORL P3, #00111100B; P3 port is connected with the key position of the four MOV 1 A, P3; P3 A #11000011B; the value of ORL, the remaining 4 position 1 CPL A; JZ K_RET inverse; if 0 is no key press ACALL DELAY; o

36、therwise the delay to the ORL P3 #00111100B MOV key to shake. A P3, ORL A, #11000011B CPL A JZ K_RET MOV B, A; indeed a key is pressed, the key will be stored in B SETB F0; set the key press mark of K_RET: ORL P3, #00111100B; here wait for the cycle bond release of MOV A, P3ORL A, #11000011B CPL A J

37、Z K_RET1; until the data read counter to 0 keys released, AJMP K_RET K_RET1: RET returned from the keyboard handler; D500MS:; PUSH PSW SETB RS0 MOV delay time R7 water lamp, #200 D51: MOV R6, #250 D52: NOP NOP NOP NOP DJNZ R6, D52 DJNZ R7, D51 POP PSW RET; LAMP: JB StartEnd, LampStart; if StartEnd=1

38、, launched MOV P1, #0FFH AJMP LAMPRET; or close all show that return LampStart: JB UpDown, LAMPUP; if UpDown=1, to MOV A LAMPCODE RL A flow, it is actually a left shift; MOV LAMPCODE, A MOV P1. A LCALL D500MSAJMP LAMPRET LAMPUP: MOV A, LAMPCODE RR A; MOV LAMPCODE is actually the right to flow down,

39、A MOV P1, A LCALL D500MS LAMPRET: RET END the above procedure function is very simple, but it demonstrates the basic idea of a keyboard handler, the program itself is very simple, is not very practical, but also have a lot of factors in the actual work to be considered, such as the main loop every t

40、ime call light cycle program, will cause the key reaction dull, and if press the button,The lights dont flow anymore, until theyre released, and so on. We can think about these problems and think of some good solutions. 2, using interrupt mode: as shown in figure 4. All keys are received with a non,

41、 when any button is pressed, will make the gate output level is low, causing the microcontroller interrupt, its advantage is not cyclic query continuously in the main program, if a key is pressed, the MCU to do corresponding processingSinglechip music program designAuthor: anonymous source: hits: 37

42、44 update: 2009/4/1 * * * 15:25:50The use of single-chip (or single board) music is probably one of the radio enthusiasts interested in problems. In this paper, starting from the basic experiment of single-chip microcomputer, the design principle of the music program is discussed, and some specific

43、examples are given for reference. SCM basic pronunciation experiment, we know that the sound spectrum range of about tens to several thousand Hertz, if you can use the program to control a single machine, a mouth line of high level, orLow level, in the mouth of the line will be able to have a certai

44、n frequency square wave with certain frequency, the sound of horns can, if the use of delay time control program for high and low level, can change the output frequency, thus changing the tone. For example, to produce 200HZ audio signals, according to figure 1 (if the temporary access horn experimen

45、t, can also be directly connected to P1 port in the horn line), the experimental procedure is: the subroutine DEL delay subroutine, when R3 is 1, the delay time is about 20us, R3 stored in the 200HZ audio delay constant. The cycle is 1/200, which is 5ms seconds. Thus, when the P1.4 high or low level

46、 has a duration of 2.5ms, i.e., the time constant of R3 takes 2 500/20=125 (7DH), the tone of the 200HZ can be emitted. Type the program into the learning machine and continue to modify the R3 constant to feel the change in pitch. In music, each note corresponds to a definite frequency. Table 1 give

47、s the notes and their corresponding time constants at the C tone. According to the constants provided in Table 1, the reader can send his 16 decimal code to R3 and practice it repeatedly. According to table 1, the notes can be played. Thats not enough. One must accurately control the tempo of a piec

48、e of music, that is, the duration of a note. Note the rhythm, we can use timer T0 to control, send different initial value, can produce different timing time. Just as the tempo of a song is 94 beats per minute, or 0.64 beats per second. The relation between other beats and time is shown in table 2.

49、However, since the maximum timing time of the T0 is only 131 MS, it is impossible to achieve the different tempo directly with the initial time value of the change of T0. We can use T0 to generate a 10 millisecond time base, and then set an interrupt counter that controls the length of the beat by j

50、udging the value of the interrupt counter. The time constants corresponding to various beats are also shown in table 2. For example, for 1/4, the time is 0.16 seconds, and the corresponding time constant is 16 (10H). For 3 beat notes, the timing is 1.92 seconds, and the corresponding time is 192 (C0

51、H). We will beat the time constant of each note and its corresponding as a group, according to the order of all the constants in music are arranged into a table, then the table procedures are removed from the notes and rhythm control, can achieve the performance effect. In addition, the terminator a

52、nd body stop can be represented by code 00H and FFH respectively. If the look-up table is 00H, it indicates the end of the song. If the look-up table is FFH, the corresponding Pause effect is produced. In order to produce a rhythmic rhythm of the hand, a note in a certain unit of notes (such as two

53、identical notes) is inserted into a unit of time with a slightly different frequency. The program list is given below,It can be played directly on the TD-III learning machine. For other different types of learning machines, you just need to change the address accordingly. The program is playing folk

54、 songs, August osmanthus everywhere open, C tune, the rhythm of 94 beats / min. The reader can also automatically find a song, according to the constant table 1 and table 2 given, will be translated into music code into the machine, and the same procedure. This experiment method is simple, even if t

55、he person who doesnt understand music, it is easy to translate an unfamiliar piece of music into the code. It is interesting to learn a song with the performance of the machine.List of procedures (see the source instructions for a short time).The block diagram is shown in figure 2.Click here to brow

56、se the picture at the new window W singlechip tutorial networkHardware connection: a random simulation machine or what MCU board, as long as you can work on the line, the program input operation, and then find a speaker (should have a right next to your computer) dial plug, plug connected to the fro

57、nt end of the P1. 0, on the back of the line to find the root line of the microcontroller, it should sound, and then how to improve the hardware connection is your thing.Music assembly code, code 1, Voice.asmORG 0000H, LJMP, START, ORG, 000BH, INC, 20H, interrupt service, interrupt counter plus 1, M

58、OV, TH0, #0D8H, MOV, TL0, #0EFH, 12M, crystal oscillator, forming 10 milliseconds interruptRETI START: MOV SP, #50H MOV TH0, #0D8H MOV TL0, #0EFH MOV TMOD, #01H MOV IE, #82H MUSIC0: NOP MOV DPTR, #DAT; DPTR MOV header address to send 20H, #00H; MOV B interrupt counter 0, #00H; MUSIC1: NOP CLR 0 serial number table A MOVC A, A+DPTR; look-up table access code JZ END0; CJNE A is 00H, then the end of #0FFH, MUSIC5, LJMP MUSIC3 MUSIC5: NOP MOV R6, A INC DPTR MOV A, B MOVC A, A+DPTR; R7 MOV R7 code to send the beat, A SETB TR0 MUSIC2: NOP CP

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論