#include "reg52.h" typedef unsigned char u8; typedef unsigned int u16; sbit beep = P2^5; void delay(u16 i) { while(i--); } void main() { while(1){ beep = ~beep; //高低电平来回变换 delay(10); beep = 1; //改变占空比,来控制声音大小 delay(10); beep = 0; delay(5); } }
2023-12-24 22:17:16
#include "reg52.h" typedef unsigned char u8; typedef unsigned int u16; sbit beep = P2^5; void delay(u16 i) { while(i--); } void main() { while(1){ beep = ~beep; //高低电平来回变换 delay(10); beep = 1; //改变占空比,来控制声音大小 delay(10); beep = 0; delay(5); } }