普中科技 a4
#include <REGX52.H> #include <INTRINS.H> typedef unsigned char u8; typedef unsigned int u16; typedef unsigned long u32; void delay_10us(u16 t) { while(--t); } //蜂鸣器 sbit buzzer = P2^5; //频率 u16 music_base_frequency[7] = { 523, 587, 670, 720, 784, 880, 988 }; #define base_time 500000 #define zero_time (100000 / 10) u8 xxx[] = { 1,0,1,0, 5,0,5,0, 6,0,6,0, 5,5,0,0, 4,0,4,0, 3,0,3,0, 2,0,2,0, 1,1,0,0, 5,0,5,0, 4,0,4,0, 3,0,3,0, 2,2,0,0, 5,0,5,0, 4,0,4,0, 3,0,3,0, 2,2,0,0, 1,0,1,0, 5,0,5,0, 6,0,6,0, 5,5,0,0, 4,0,4,0, 3,0,3,0, 2,0,2,0, 1,1,0,0, }; void main() { u16 i=0; u16 count = 0; u16 delay_time = 0; for(i = 0; i < sizeof(xxx); ++i) { if(0 == xxx[i]) { delay_10us(zero_time); } else { delay_time = 1000000 / music_base_frequency[xxx[i]] / 2; count = base_time / delay_time; delay_time = delay_time / 10; while(--count) { buzzer = !buzzer; delay_10us(delay_time); } } } while(1); }
标签:蜂鸣器,小星星,xxx,delay,单片机,base,time,u16 From: https://www.cnblogs.com/yybdy/p/17601092.html