0
Follow
0
View

protues controls the buzzer

lijie43011 注册会员
2023-02-25 21:24

The answer part of the reference GPT, GPT_Pro better solve the problem
Use proteus51 microcontroller control buzzer send 1KHz signal, First of all, we should understand the working principle of 51 MCU timer T1, it is composed of 16 bit timer, you can use it to produce a certain period of interrupt, so as to achieve the control of the buzzer.

Before writing the code, we first calculated the 1KHz signal parameters of the T1 timer according to the 12MHz system clock frequency. The calculation formula is: each interrupt interval = system clock frequency/interrupt frequency. Therefore, we used 12MHz/1000Hz=12000 to get 12,000 clock cycles for each interrupt interval.

Next is to write these parameters into 51 MCU code, the code is as follows:

// 定义T1的工作方式,使用定时器T1的16位模式
TMOD = 0x10; 
// 设置T1的计数值为12000,即当计数值减到0时发生中断
TH1 = 0x30; // 12000/256=46.875=>46
TL1 = 0xB8; // 12000-256*46=184=>B8 
// 初始化P1.7口为输出方式
P1_7 = 0; 
// 启动定时器T1
TR1 = 1; 
// 进入死循环,不断处理中断
while (1) { 
    // 检测T1中断标志位,如果中断标志位为1,表明发生了中断,则执行以下代码 
    if (TF1 == 1) { 
        // 清除T1中断标志位 
        TF1 = 0;  
        // 将P1.7口由0切换到1或从1切换到0 
        P1_7 = ~P1_7;  
        // 重新设置T1的计数值 
        TH1 = 0x30; // 12000/256=46.875=>46 
        TL1 = 0xB8; // 12000-256*46=184=>B8 
    }  
} 

The above code is the use of proteus51 MCU control buzzer to send 1KHz signal steps, through the interrupt of timer T1 to P1.7 pin control buzzer signal. During the whole process, we need to correctly set the timer T1 according to the required signal frequency, so as to get the required signal.
If the answer is helpful, please accept it.

About the Author

Question Info

Publish Time
2023-02-25 21:24
Update Time
2023-02-25 21:24