SCM experiment experiment [] speaker

Experiment two speakers experiment
1, experimental purposes
1. master hardware circuit speaker;
written 2 master speaker of the program and how to make the speaker make different sounds.
Second, the experiments show
LM386 LM386 pin pin illustrated in Figure 2-1 Introduction

It is an LM386 integrated audio amplifier, with its low power consumption, voltage gain adjustable range of a large power supply voltage, less external components and the total harmonic distortion of the power amplifier, etc., widely used in tape recorders and radio.
Pin 2 is the inverting input terminal, inverting input terminal 3; 5 as an output pin; pins 6 and 4 are power supply and ground; pins 1 and 8 of the gain setting voltage terminal; as used pin 7 and the
indirect bypass capacitance, usually taken 10μF.


FIG. 2-1 LM386 pin Introduction

This experiment using seven notes generated by the speaker SCM, SCM STC12C5A60S2 the PCA / PWM output high speed clock output pulses, filtering the amplified pulses drive speaker sound. Determined by the timing frequency of the sound is constant, the length of the sound is controlled by a timer T0. Experiments gave only seven audio programs.
Third, the experimental content and Step
Content:
P1.3 port minimum system microcontroller unit emits high-speed pulse, P1.3 port connected to the voice system unit VIN port signal line, the speaker function program loop issued seven notes while using adjustable resistance adjusting loudness of sound.
Step:
1, a hardware circuit is connected, and compiled programming * .hex file;
2, open test box power;
3, reference STC12C5A60S2 download instructions STC_ISP software instructions, download the program to the microcontroller;
4, signal lines connected to the microcontroller VIN port P1.3 speech system unit with a minimum of system units;
5, open voice switching system unit;
6, the speaker will hear seven notes issued cycle, while taking advantage of the adjustable resistor adjusted loudness of the sound. If the result is not correct, modify the program, repeat the above operation.

 1 #include <reg51.h>
 2 
 3 sfr CCON = 0xD8;
 4 sbit CCF0 = CCON^0;
 5 sbit CCF1 = CCON^1;
 6 sfr CMOD = 0xD9;
 7 sfr CL = 0xE9;
 8 sfr CH = 0xF9;
 9 sfr CCAPM0 = 0xDA;
10 sfr CCAP0L = 0xEA;
11 sfr CCAP0H = 0xFA;
12 sbit CR = CCON^6;
13 sbit CF = CCON^7;
14 
15 unsigned char TABLE[]={
16      0x1A,0x29,0x47,0x25,0x8F,0x20,0x0CC,0x1E,0x81,0x1B,0x0EA,0x17,0x9F,0x15
17 };                                                                            
18 
19 unsigned char time0_cnt;
20 unsigned char data_cnt; //Ranging from 0 to 6, where 0 represents DO tone. 
21 is unsigned int TEMP;         // used to load the 16-bit time interval. 
22 is  
23 is  void main ( void )
 24  {
 25      the SP = 0x64 ;
 26 is      time0_cnt = 15 ;
 27      TEMP = 0x291A ;
 28      the TMOD = . 1 ;
 29  
30      the CCON = 0 ;
 31 is      CL = 0 ;
 32      CH = 0 ;
 33 is      the CMOD = 2 ;
34 
35     CCAP0L = 0x1A;
36     CCAP0H = 0x29;
37     CCAPM0 = 0x4D;
38     data_cnt = 1;
39 
40     CR = 1; 
41     EA = 1 ;
42     ET0 = 1;
43     TR0 = 1; 
44 
45     while(1);
46 }
47 
48 void T0_int(void) interrupt 1 
49 {
50     time0_cnt -- ;
51     
52     if( time0_cnt == 0 ) {
53          time0_cnt = 15;
54 
55         data_cnt = ( data_cnt + 1 ) % 7 ; 
56         temp = TABLE[data_cnt*2+1];
57         temp <<= 8 ;
58         temp += TABLE[data_cnt*2];
59     }
60 }
61 
62 void PCA_INT(void) interrupt 7
63 {
64     unsigned int temp1 ; 
65     CCF0 = 0; 
66 
67     temp1 = (CCAP0H << 8);
68     temp1 =  temp1 + CCAP0L  ;
69 
70     temp1 += temp;
71 
72     CCAP0L = temp1&0xff;
73     CCAP0H = ((temp1&0xff00)>>8);
74 }
View Code

 

Guess you like

Origin www.cnblogs.com/Osea/p/11083130.html