一. 系统概述
该系统以STM32单片机为核心控制单元,通过按键选择特定的门牌号,显示对应的楼号在数码管上。当按下门铃按键时,系统会发出报警通知。
二. 仿真概述
- 在仿真模式下,按下门牌选择按键时,数码管上会显示相应的门牌号。
- 按下门铃按键时,蜂鸣器会发出响亮的报警声,提醒用户。
三.程序设计
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Key.h"
#include "LED.h"
#include "PWM.h"
uint8_t KeyNum;
uint8_t Num;
const uint16_t tone[21] = {3817,3401,3030,2865,2551,2272,2024,
1912,1703,1517,1432,1275,1136,1012,
956,851,758,715,637,568,506};
const uint8_t music1_tone[25] = {4,4,8,4,7,6,4,4,5,4,8,7,4,4,11,9,7,6,5,10,10,9,7,8,7};
const uint8_t music1_time[25] = {2,2,4,4,4,8,2,2,4,4,4,8,2,2,4,4,4,4,4,6,2,4,4,4,8};
const uint8_t music2_tone[25] = {4,15,8,4,7,6,8,4,7,4,8,7,4,7,11,9,7,8,5,10,10,9,8,8,7};
const uint8_t music2_time[25] = {8,2,8,4,4,8,8,2,4,8,4,8,2,2,4,8,4,8,4,6,2,4,8,4,8};
const uint8_t music3_tone[25] = {8,4,8,4,7,6,6,8,5,4,8,6,8,8,11,6,7,4,6,14,10,6,7,8,7};
const uint8_t music3_time[25] = {4,4,2,2,2,4,2,8,8,4,2,8,2,4,4,4,4,4,4,6,2,4,4,4,8};
const uint8_t music4_tone[25] = {16,2,8,3,7,6,4,7,5,8,8,7,4,4,11,9,6,6,6,10,18,9,7,8,7};
const uint8_t music4_time[25] = {4,2,4,5,4,8,2,2,7,4,6,8,2,4,2,2,2,8,8,6,2,4,4,4,8};
const uint8_t music5_tone[25] = {15,14,13,8,7,6,4,8,5,4,8,7,4,4,11,14,7,18,5,10,9,9,7,8,7};
const uint8_t music5_time[25] = {8,8,2,2,4,8,6,2,4,4,4,8,2,2,4,4,4,4,4,6,2,4,4,4,8};
const uint8_t music6_tone[25] = {4,4,8,4,7,6,4,18,5,4,16,7,4,18,11,9,7,6,5,10,10,9,7,8,7};
const uint8_t music6_time[25] = {2,6,4,2,2,8,2,2,4,2,8,8,2,2,4,4,4,4,4,6,2,4,4,4,8};
const uint8_t music7_tone[25] = {18,18,18,4,8,6,8,4,5,4,8,7,4,4,11,9,7,6,5,10,10,9,7,8,7};
const uint8_t music7_time[25] = {8,8,4,8,8,8,2,2,8,4,4,8,8,2,4,8,4,8,4,6,2,8,4,4,8};
int main(void)
{
uint8_t i;
/*模块初始化*/
PWM_Init();
PWM_SetCompare1(0);
Key_Init();
OLED_Init();
seg_init();
while (1)
{
KeyNum = Key_GetNum(); //获取按键键码
OLED_ShowNum(1,1,Num,1);
seg_display(Num);
if (KeyNum == 1) //按键1按下
{
Num++;
if(Num == 8)
Num = 0;
}
if (KeyNum == 2) //按键2按下
{
switch(Num)
{
case 1 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music1_tone[i]],tone[music1_tone[i]]/2);
Delay_ms(music1_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
case 2 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music2_tone[i]],tone[music2_tone[i]]/2);
Delay_ms(music2_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
case 3 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music3_tone[i]],tone[music3_tone[i]]/2);
Delay_ms(music3_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
case 4 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music4_tone[i]],tone[music4_tone[i]]/2);
Delay_ms(music4_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
case 5 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music5_tone[i]],tone[music5_tone[i]]/2);
Delay_ms(music5_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
case 6 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music6_tone[i]],tone[music6_tone[i]]/2);
Delay_ms(music6_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
case 7 :
{
for(i=0; i<25;i++)
Set_pwm(tone[music7_tone[i]],tone[music7_tone[i]]/2);
Delay_ms(music7_time[i]*62.5);
PWM_SetCompare1(0);
break;
}
}
}
}
}
24-32f-59