mian.c
- #include "sys.h"
- #include "delay.h"
- #include "led.h"
- #include "beep.h"
- u8 music[]={
- 5,10,10,5,5,9,9,16,8,8,8,9,10,5,5,16, //???????,???????
- 6,8,8,6,5,10,10,16,9,8,8,6,9,16, //???????,?????
- 5,10,10,5,5,9,9,16,8,8,8,6,5,10,10,16, //???????,???????
- 6,11,11,6,5,10,10,16,9,8,8,6,8,16, //???????,?????
- 5,12,5,5,12,5,9,16,8,6,8,8,8,10,12,16, //???????,???????!
- 8,6,8,8,8,13,12,10,9,8,6,8,8,10,9,16, //??????,?????,?????
- 5,12,5,5,12,5,9,16,8,6,8,8,13,12,16, //???????,??????
- 8,8,8,13,12,10,9,8,6,8,8,9,8,16, //?????????,??????
- };
- u8 time[] = {
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, //???????,???????
- 4,4,4,4,4,4,4,4,4,4,4,4,8,4, //???????,?????
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, //???????,???????
- 4,4,4,4,4,4,4,4,4,4,4,4,8,4, //???????,?????
- 4,4,2,2,4,4,4,4,4,4,2,2,4,4,8,4, //???????,???????!
- 4,4,2,2,4,4,4,4,4,4,4,4,4,4,8,4, //??????,?????,?????
- 4,4,2,2,4,4,4,4,4,4,4,4,4,8,4, //???????,??????
- 4,4,4,4,4,4,4,4,4,4,4,4,8,4, //?????????,??????
- };
- void Sound(u16 frq)
- {
- u32 n;
- BEEP = 0;
- if(frq != 1000)
- {
- n = 500000/((u32)frq);
- BEEP = 0;
- delay_us(n);
- BEEP = 1;
- delay_us(n);
- }
- else
- {
- delay_us(1000);
- }
- }
- void play(void)
- {
- uc16 tone[] = {247,262,294,330,349,392,440,494,523,587,659,698,784,1000};//?????
- u8 music[]={
- 5,5,6,8,7,6,5,6,13,13,//??
- 5,5,6,8,7,6,5,3,13,13,
- 2,2,3,5,3,5,6,3,2,1,
- 6,6,5,6,5,3,6,5,13,13,
- 5,5,6,8,7,6,5,6,13,13,
- 5,5,6,8,7,6,5,3,13,13,
- 2,2,3,5,3,5,6,3,2,1,
- 6,6,5,6,5,3,6,1,
- 13,8,9,10,10,9,8,10,9,8,6,
- 13,6,8,9,9,8,6,9,8,6,5,
- 13,2,3,5,5,3,5,5,6,8,7,6,
- 6,10,9,9,8,6,5,6,8
- };
- u8 time[] = {
- 2,4,2,2,2,2,2,8,4, 4, //??
- 2,4,2,2,2,2,2,8,4, 4,
- 2,4,2,4,2,2,4,2,2,8,
- 2,4,2,2,2,2,2,8,4 ,4,
- 2,4,2,2,2,2,2,8,4, 4,
- 2,4,2,2,2,2,2,8,4, 4,
- 2,4,2,4,2,2,4,2,2,8,
- 2,4,2,2,2,2,2,8,
- 4, 2,2,2, 4, 2,2,2, 2,2,8,
- 4, 2,2,2,4,2,2,2,2,2,8,
- 4, 2,2,2,4,2,2,5,2,6,2,4,
- 2,2 ,2,4,2,4,2,2,12
- };
- u32 yanshi;
- u16 i,e;
- yanshi = 10;
- for(i=0;i<sizeof(music)/sizeof(music[0]);i++)
- {
- for(e=0;e<((u16)time<i>)*tone[music<i>]/yanshi;e++)
- {
- Sound((u32)tone[music<i>]);
- }
- }
- }
- int main(void)
- {
- delay_init();
- LED_Init();
- BEEP_Init();
- BEEP = 0;
- play();
- while(1);
- }</i></i></i>
复制代码
beep.c
- #include "beep.h"
- void BEEP_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_ResetBits(GPIOB,GPIO_Pin_8);
- }
复制代码
beep.h
- #ifndef __BEEP_H
- #define __BEEP_H
- #include "sys.h"
- #define BEEP PBout(8)
- void BEEP_Init(void);
- #endif
复制代码
|