void calendar_set_alarm(void)//闹钟设置模式 { if(g_calendar.mode==2)//闹钟设置 { if(g_calendar.add==1) { g_calendar.add=0; switch(g_calendar.time_choice) { case 0: g_calendar.alarm_time[0]++; if((g_calendar.alarm_time[0]&0x0f)>9)g_calendar.alarm_time[0]+=6; if(g_calendar.alarm_time[0]>=0x60)g_calendar.alarm_time[0]=0; break; case 1: g_calendar.alarm_time[1]++; if((g_calendar.alarm_time[1]&0x0f)>9)g_calendar.alarm_time[1]+=6; if(g_calendar.alarm_time[1]>=0x24)g_calendar.alarm_time[1]=0; break; case 2: g_calendar.alarm=!g_calendar.alarm; break; case 3: g_calendar.time_choice=0; break; } } } }
时间: 2024-04-02 18:33:56 浏览: 22
这段代码实现了闹钟设置模式下的闹钟时间设置,通过按键选择需要调整的时间单位,然后每按一次增加对应的时间值,当时间值超过其最大值时,将其归零或者调整到最小值。除了闹钟时间的设置,还可以通过按键选择是否开启闹钟,以及退出闹钟设置模式。其中,闹钟时间的单位包括时、分等,而闹钟开关的设置则是通过将g_calendar.alarm变量取反来实现的。
相关问题
下面这一段代码的功能是什么void calendar_test(void) { u8 key_temp=0; lcd1602_init(); ds1302_init(); ds18b20_init(); time0_init();//定时器设置 while(1) { key_temp=key_scan(0); if(key_temp==KEY1_PRESS)//模式设置 { g_calendar.mode++; if(g_calendar.mode==3) g_calendar.mode=1; g_calendar.setok=0; g_calendar.time_choice=0; if(g_calendar.mode==2) { lcd1602_clear(); lcd1602_show_string(0,0,alarm_switch_str); } beep_alarm(200,20); } else if(key_temp==KEY2_PRESS)/进入设置模式时,对应位选择 { g_calendar.time_choice++; if(g_calendar.time_choice==7) g_calendar.time_choice=0; beep_alarm(200,20); } else if(key_temp==KEY3_PRESS)//进入设置模式时,对应数据加操作 { g_calendar.add=1; beep_alarm(200,20); } else if(key_temp==KEY4_PRESS)//设置完成,恢复正常显示模式 { g_calendar.setok=1; g_calendar.time_choice=0; g_calendar.mode=0; calendar_save_set_time(); beep_alarm(200,20); } if(g_calendar.mode==1)//模拟光标闪烁 { if(g_calendar.time_choice<3) lcd1602_show_string(7-g_calendar.time_choice*3,1," "); else if(g_calendar.time_choice>=3&&g_calendar.time_choice<4) lcd1602_show_string(14,0," "); else if(g_calendar.time_choice>=4&&g_calendar.time_choice<7) lcd1602_show_string(21-g_calendar.time_choice*3,0," "); } else if(g_calendar.mode==2)//模拟光标闪烁 { if(g_calendar.time_choice<2) lcd1602_show_string(4-g_calendar.time_choice*3,1," "); else if(g_calendar.time_choice==2) lcd1602_show_string(9,0," "); else if(g_calendar.time_choice==3) lcd1602_show_string(4,1," "); } calendar_set_time(); calendar_set_alarm(); calendar_show(); alarm_compareproc(); } }
这段代码是一个日历闹钟程序的主函数,主要功能如下:
1. 初始化LCD1602,DS1302,DS18B20以及定时器。
2. 循环执行以下操作:
a. 通过按键扫描获取按键值。
b. 根据按键值进行相应的操作,如进入/退出模式设置,选择需要设置的时间/日期,设置时间/日期,保存设置等。
c. 根据当前模式模拟光标闪烁,以提示用户当前选择的是哪个时间/日期。
d. 显示时间/日期以及闹钟开关状态。
e. 比较当前时间和闹钟设置的时间,若匹配则触发闹钟响铃。
//void IIC_Init(void) //{ // GPIO_InitTypeDef GPIO_InitStructure; // RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); //ʹÄÜGPIOBʱÖÓ // RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE ); // GPIO_InitStructure.Pin = GPIO_Pin_11|GPIO_Pin_12; // GPIO_InitStructure.Mode = GPIO_Mode_Out_PP ; //ÍÆÍìÊä³ö // GPIO_InitStructure.Speed = GPIO_Speed_50MHz; // GPIO_Init(GPIOA, &GPIO_InitStructure); // GPIO_SetBits(GPIOA,GPIO_Pin_11|GPIO_Pin_12); //PB6,PB7 Êä³ö¸ß // // GPIO_InitStructure.Pin = GPIO_Pin_7; // GPIO_InitStructure.Mode = GPIO_Mode_IN_FLOATING ; //¸¡¿ÕÊäÈë // GPIO_Init(GPIOA, &GPIO_InitStructure); //}改为stm32G030F6P6单片机的对应的初始化
请注意,`STM32G030F6P6`微控制器与`GPIOA`和`GPIOB`的引脚分布是不同的,因此需要根据具体型号进行适当的修改。以下是一个可能的修改版本:
```c
void IIC_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC->IOPENR |= RCC_IOPENR_GPIOAEN | RCC_IOPENR_GPIOBEN; // 使能GPIOA和GPIOB的时钟
GPIO_InitStructure.Pin = GPIO_PIN_9 | GPIO_PIN_10; // 选定PB6和PB7引脚
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD; // 设置为开漏输出
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; // 设置GPIO速度为50MHz
GPIO_InitStructure.Pull = GPIO_PULLUP; // 设置引脚上拉
GPIO_InitStructure.Alternate = GPIO_AF1_I2C1; // 选择I2C1的复用功能
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); // 初始化GPIOA
GPIO_InitStructure.Pin = GPIO_PIN_8; // 选定PA7引脚
GPIO_InitStructure.Mode = GPIO_MODE_INPUT; // 设置为输入模式
GPIO_InitStructure.Pull = GPIO_PULLUP; // 设置引脚上拉
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); // 初始化GPIOA
}
```
这段代码中使用了`GPIOA`作为GPIO的初始化对象,并选定了适当的引脚和模式。需要根据具体应用场景进行调整。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)