setdate.c

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #include <stdio.h>
#include <dos.h>

void main(void)
 {
   struct date desired_date;

   desired_date.da_mon = 10;
   desired_date.da_day = 31;
   desired_date.da_year = 1997;

   setdate(&desired_date);
 }

#include "rtc.h" #include "oled.h" #include "delay.h" #include "stm32f10x_rtc.h" typedef struct { uint8_t hour; uint8_t minute; uint8_t second; uint8_t enabled; } Alarm_TypeDef; Alarm_TypeDef Alarm = {0}; // 初始化闹钟结构体 // RTC初始化 void RTC_Init(void) { // 使能PWR和BKP时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // 允许访问BKP域 PWR_BackupAccessCmd(ENABLE); // 检查是否需要初始化RTC if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { // 复位BKP域 BKP_DeInit(); // 使能LSE RCC_LSEConfig(RCC_LSE_ON); // 等待LSE准备就绪 while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { OLED_ShowString(0, 0, "Waiting for LSE...", 12); delay_ms(100); } // 选择LSE作为RTC时钟源 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // 使能RTC时钟 RCC_RTCCLKCmd(ENABLE); // 等待RTC寄存器同步 RTC_WaitForSynchro(); // 等待最近一次对RTC寄存器的写操作完成 RTC_WaitForLastTask(); // 设置RTC预分频器 RTC_SetPrescaler(32767); RTC_WaitForLastTask(); // 设置初始时间(改用具名变量初始化) RTC_TimeTypeDef rtcTime = {0, 0, 0}; RTC_SetTime(RTC_Format_BIN, &rtcTime); RTC_WaitForLastTask(); // 设置初始日期(改用具名变量初始化) RTC_DateTypeDef rtcDate = {23, 1, 1, RTC_Weekday_Monday}; RTC_SetDate(RTC_Format_BIN, &rtcDate); RTC_WaitForLastTask(); // 存储标志以指示RTC已初始化 BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { // 等待RTC寄存器同步 RTC_WaitForSynchro(); // 等待最近一次对RTC寄存器的写操作完成 RTC_WaitForLastTask(); } } // 设置时间 void RTC_SetCurrentTime(u8 hour, u8 minute, u8 second) { RTC_TimeTypeDef RTC_TimeStructure; RTC_TimeStructure.RTC_Hours = hour; RTC_TimeStructure.RTC_Minutes = minute; RTC_TimeStructure.RTC_Seconds = second; RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure); RTC_WaitForLastTask(); } // 设置日期 void RTC_SetCurrentDate(u8 year, u8 month, u8 date, u8 weekday) { RTC_DateTypeDef RTC_DateStructure; RTC_DateStructure.RTC_Year = year; RTC_DateStructure.RTC_Month = month; RTC_DateStructure.RTC_Date = date; RTC_DateStructure.RTC_WeekDay = weekday; RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure); RTC_WaitForLastTask(); } // 设置闹钟时间 void RTC_SetAlarmTime(u8 hour, u8 minute, u8 second) { Alarm.hour = hour; Alarm.minute = minute; Alarm.second = second; Alarm.enabled = 1; } // 检查闹钟是否触发 u8 RTC_CheckAlarm(void) { RTC_TimeTypeDef currentTime; RTC_GetTime(RTC_Format_BIN, &currentTime); return (Alarm.enabled && currentTime.RTC_Hours == Alarm.hour && currentTime.RTC_Minutes == Alarm.minute && currentTime.RTC_Seconds == 0); } 这是我的rtc.c文件。遇到了报错,帮我排查一下。报错信息如下:*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\app\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f10x_md.s... compiling stm32f10x_adc.c... compiling stm32f10x_dac.c... compiling stm32f10x_cec.c... compiling stm32f10x_can.c... compiling misc.c... compiling stm32f10x_bkp.c... compiling system_stm32f10x.c... compiling stm32f10x_crc.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_dma.c... compiling stm32f10x_exti.c... compiling core_cm3.c... compiling stm32f10x_flash.c... compiling stm32f10x_fsmc.c... compiling stm32f10x_gpio.c... compiling stm32f10x_i2c.c... compiling stm32f10x_iwdg.c... compiling stm32f10x_pwr.c... compiling stm32f10x_sdio.c... compiling stm32f10x_rtc.c... compiling stm32f10x_rcc.c... compiling stm32f10x_spi.c... compiling stm32f10x_tim.c... compiling stm32f10x_usart.c... compiling stm32f10x_wwdg.c... compiling buzzer.c... Hardwore\buzzer.c(71): warning: #223-D: function "TIM_SetPrescaler" declared implicitly TIM_SetPrescaler(BUZZER_TIM, prescaler); Hardwore\buzzer.c: 1 warning, 0 errors compiling delay.c... compiling key.c... Hardwore\key.c(9): error: #20: identifier "Alarm_TypeDef" is undefined extern Alarm_TypeDef Alarm; Hardwore\key.c(54): warning: #223-D: function "Buzzer_Play" declared implicitly Buzzer_Play(1); Hardwore\key.c(59): warning: #223-D: function "Buzzer_Stop" declared implicitly Buzzer_Stop(); Hardwore\key.c: 2 warnings, 1 error compiling mpu6050.c... Hardwore\mpu6050.c(50): warning: #223-D: function "MPU6050_Write_Byte" declared implicitly MPU6050_Write_Byte(PWR_MGMT_1, 0x80); Hardwore\mpu6050.c(73): warning: #223-D: function "MPU6050_Read_Byte" declared implicitly if(MPU6050_Read_Byte(0x75) != 0x68) Hardwore\mpu6050.c(80): error: #159: declaration is incompatible with previous "MPU6050_Write_Byte" (declared at line 50) void MPU6050_Write_Byte(u8 reg, u8 data) Hardwore\mpu6050.c(100): error: #159: declaration is incompatible with previous "MPU6050_Read_Byte" (declared at line 73) u8 MPU6050_Read_Byte(u8 reg) Hardwore\mpu6050.c: 2 warnings, 2 errors compiling rtc.c... Hardwore\rtc.c(58): error: #20: identifier "RTC_TimeTypeDef" is undefined RTC_TimeTypeDef rtcTime = {0, 0, 0}; Hardwore\rtc.c(59): warning: #223-D: function "RTC_SetTime" declared implicitly RTC_SetTime(RTC_Format_BIN, &rtcTime); Hardwore\rtc.c(59): error: #20: identifier "RTC_Format_BIN" is undefined RTC_SetTime(RTC_Format_BIN, &rtcTime); Hardwore\rtc.c(63): error: #20: identifier "RTC_DateTypeDef" is undefined RTC_DateTypeDef rtcDate = {23, 1, 1, RTC_Weekday_Monday}; Hardwore\rtc.c(63): error: #20: identifier "RTC_Weekday_Monday" is undefined RTC_DateTypeDef rtcDate = {23, 1, 1, RTC_Weekday_Monday}; Hardwore\rtc.c(64): warning: #223-D: function "RTC_SetDate" declared implicitly RTC_SetDate(RTC_Format_BIN, &rtcDate); Hardwore\rtc.c(83): error: #20: identifier "RTC_TimeTypeDef" is undefined RTC_TimeTypeDef RTC_TimeStructure; Hardwore\rtc.c(89): warning: #223-D: function "RTC_SetTime" declared implicitly RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure); Hardwore\rtc.c(89): error: #20: identifier "RTC_Format_BIN" is undefined RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure); Hardwore\rtc.c(96): error: #20: identifier "RTC_DateTypeDef" is undefined RTC_DateTypeDef RTC_DateStructure; Hardwore\rtc.c(103): warning: #223-D: function "RTC_SetDate" declared implicitly RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure); Hardwore\rtc.c(103): error: #20: identifier "RTC_Format_BIN" is undefined RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure); Hardwore\rtc.c(119): error: #20: identifier "RTC_TimeTypeDef" is undefined RTC_TimeTypeDef currentTime; Hardwore\rtc.c(121): warning: #223-D: function "RTC_GetTime" declared implicitly RTC_GetTime(RTC_Format_BIN, &currentTime); Hardwore\rtc.c(121): error: #20: identifier "RTC_Format_BIN" is undefined RTC_GetTime(RTC_Format_BIN, &currentTime); Hardwore\rtc.c: 5 warnings, 10 errors compiling stm32f10x_it.c... compiling ultrasonic.c... compiling main.c... User\main.c(13): error: #20: identifier "RTC_TimeTypeDef" is undefined RTC_TimeTypeDef RTC_TimeStruct; User\main.c(14): error: #20: identifier "RTC_DateTypeDef" is undefined RTC_DateTypeDef RTC_DateStruct; User\main.c(15): error: #20: identifier "Alarm_TypeDef" is undefined Alarm_TypeDef Alarm; User\main.c(41): warning: #223-D: function "RTC_GetTime" declared implicitly RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct); User\main.c(41): error: #20: identifier "RTC_Format_BIN" is undefined RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct); User\main.c(42): warning: #223-D: function "RTC_GetDate" declared implicitly RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct); User\main.c: 2 warnings, 4 errors compiling oled.c... ".\Objects\Project.axf" - 17 Error(s), 12 Warning(s). Target not created. Build Time Elapsed: 00:00:06
07-09
compiling stm32f0xx_hal_msp.c... compiling power.c... ../Core/Inc/power.h(16): error: #20: identifier "u16" is undefined extern u16 time_ecu_start; ../Core/Inc/power.h(17): error: #20: identifier "u16" is undefined extern u16 time_ecu_sleep; ..\Core\Src\power.c(57): error: #20: identifier "stage_pedal" is undefined if(stage_pedal==0) // ..\Core\Src\power.c(70): error: #20: identifier "flag_alarm_wakeup" is undefined if(flag_alarm_wakeup==true) //如果是闹钟唤醒 ..\Core\Src\power.c(75): error: #20: identifier "flag_exti_wakeup" is undefined if(flag_ecu_sleep==true && flag_exti_wakeup==true) ..\Core\Src\power.c(85): error: #20: identifier "POW_CON" is undefined POW_CON=1; ..\Core\Src\power.c(86): error: #20: identifier "LED1" is undefined LED1=1; LED2=1; ..\Core\Src\power.c(86): error: #20: identifier "LED2" is undefined LED1=1; LED2=1; ..\Core\Src\power.c(87): error: #20: identifier "JDA" is undefined JDA=0; JDB=0; ..\Core\Src\power.c(87): error: #20: identifier "JDB" is undefined JDA=0; JDB=0; ..\Core\Src\power.c(89): error: #20: identifier "htim1" is undefined HAL_TIM_PWM_Stop(&htim1,TIM_CHANNEL_1); //deint不会关pwm,所以在这里确保一定关 ..\Core\Src\power.c(90): error: #20: identifier "htim3" is undefined HAL_TIM_Base_Stop_IT(&htim3); ..\Core\Src\power.c(97): warning: #223-D: function "GPIO_Sleep_Config" declared implicitly GPIO_Sleep_Config(); //全部配置为模拟输入 ..\Core\Src\power.c(99): error: #20: identifier "flag_exti_wakeup" is undefined flag_exti_wakeup=false; ..\Core\Src\power.c(100): error: #20: identifier "flag_alarm_wakeup" is undefined flag_alarm_wakeup=false; ..\Core\Src\power.c(102): warning: #223-D: function "MX_RTC_Init" declared implicitly MX_RTC_Init(); ..\Core\Src\power.c(103): warning: #223-D: function "HAL_IWDG_Refresh" declared implicitly HAL_IWDG_Refresh(&hiwdg); //喂狗 ..\Core\Src\power.c(103): error: #20: identifier "hiwdg" is undefined HAL_IWDG_Refresh(&hiwdg); //喂狗 ..\Core\Src\power.c(115): warning: #223-D: function "GPIO_WakeUp_Config" declared implicitly GPIO_WakeUp_Config(); ..\Core\Src\power.c(116): warning: #223-D: function "MX_ADC_Init" declared implicitly MX_ADC_Init(); ..\Core\Src\power.c(117): warning: #223-D: function "MX_IWDG_Init" declared implicitly MX_IWDG_Init(); ..\Core\Src\power.c(119): warning: #223-D: function "MX_TIM1_Init" declared implicitly MX_TIM1_Init(); ..\Core\Src\power.c(123): error: #20: identifier "htim1" is undefined HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1); //使能TIM1的PWM Channel1 输出 ..\Core\Src\power.c(124): error: #20: identifier "htim3" is undefined HAL_TIM_Base_Start_IT(&htim3); ..\Core\Src\power.c(126): error: #20: identifier "POW_CON" is undefined POW_CON=0; ..\Core\Src\power.c(127): error: #20: identifier "LED1" is undefined LED1=1; LED2=0; ..\Core\Src\power.c(127): error: #20: identifier "LED2" is undefined LED1=1; LED2=0; ..\Core\Src\power.c: 7 warnings, 20 errors compiling rtc.c... ../Core/Inc/rtc.h(35): error: #20: identifier "RTC_HandleTypeDef" is undefined extern RTC_HandleTypeDef hrtc; ../Core/Inc/rtc.h(44): error: #20: identifier "bool" is undefined extern bool flag_alarm_wakeup; ..\Core\Src\rtc.c(27): error: #20: identifier "RTC_HandleTypeDef" is undefined RTC_HandleTypeDef hrtc; ..\Core\Src\rtc.c(37): error: #20: identifier "RTC_TimeTypeDef" is undefined RTC_TimeTypeDef sTime = {0}; ..\Core\Src\rtc.c(38): error: #20: identifier "RTC_DateTypeDef" is undefined RTC_DateTypeDef sDate = {0}; ..\Core\Src\rtc.c(39): error: #20: identifier "RTC_AlarmTypeDef" is undefined RTC_AlarmTypeDef sAlarm = {0}; ..\Core\Src\rtc.c(48): error: #20: identifier "RTC_HOURFORMAT_24" is undefined hrtc.Init.HourFormat = RTC_HOURFORMAT_24; ..\Core\Src\rtc.c(51): error: #20: identifier "RTC_OUTPUT_DISABLE" is undefined hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; ..\Core\Src\rtc.c(52): error: #20: identifier "RTC_OUTPUT_POLARITY_HIGH" is undefined hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; ..\Core\Src\rtc.c(53): error: #20: identifier "RTC_OUTPUT_TYPE_OPENDRAIN" is undefined hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; ..\Core\Src\rtc.c(54): warning: #223-D: function "HAL_RTC_Init" declared implicitly if (HAL_RTC_Init(&hrtc) != HAL_OK) ..\Core\Src\rtc.c(68): error: #20: identifier "RTC_DAYLIGHTSAVING_NONE" is undefined sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; ..\Core\Src\rtc.c(69): error: #20: identifier "RTC_STOREOPERATION_RESET" is undefined sTime.StoreOperation = RTC_STOREOPERATION_RESET; ..\Core\Src\rtc.c(70): warning: #223-D: function "HAL_RTC_SetTime" declared implicitly if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) ..\Core\Src\rtc.c(70): error: #20: identifier "RTC_FORMAT_BCD" is undefined if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) ..\Core\Src\rtc.c(74): error: #20: identifier "RTC_WEEKDAY_MONDAY" is undefined sDate.WeekDay = RTC_WEEKDAY_MONDAY; ..\Core\Src\rtc.c(75): error: #20: identifier "RTC_MONTH_JANUARY" is undefined sDate.Month = RTC_MONTH_JANUARY; ..\Core\Src\rtc.c(79): warning: #223-D: function "HAL_RTC_SetDate" declared implicitly if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) ..\Core\Src\rtc.c(79): error: #20: identifier "RTC_FORMAT_BCD" is undefined if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) ..\Core\Src\rtc.c(92): error: #20: identifier "RTC_ALARMMASK_DATEWEEKDAY" is undefined sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY; ..\Core\Src\rtc.c(93): error: #20: identifier "RTC_ALARMSUBSECONDMASK_ALL" is undefined sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; ..\Core\Src\rtc.c(94): error: #20: identifier "RTC_ALARMDATEWEEKDAYSEL_DATE" is undefined sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; ..\Core\Src\rtc.c(96): error: #20: identifier "RTC_ALARM_A" is undefined sAlarm.Alarm = RTC_ALARM_A; ..\Core\Src\rtc.c(97): warning: #223-D: function "HAL_RTC_SetAlarm_IT" declared implicitly if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK) ..\Core\Src\rtc.c(97): error: #20: identifier "RTC_FORMAT_BCD" is undefined if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK) ..\Core\Src\rtc.c(107): error: #20: identifier "RTC_HandleTypeDef" is undefined void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) ..\Core\Src\rtc.c(127): error: #20: identifier "RTC_HandleTypeDef" is undefined void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle) ..\Core\Src\rtc.c(147): error: #20: identifier "bool" is undefined bool flag_alarm_wakeup=false; //休眠唤醒标志位 ..\Core\Src\rtc.c(147): error: #20: identifier "false" is undefined bool flag_alarm_wakeup=false; //休眠唤醒标志位 ..\Core\Src\rtc.c(149): error: #20: identifier "RTC_HandleTypeDef" is undefined void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) ..\Core\Src\rtc.c(152): error: #20: identifier "flag_ecu_sleep" is undefined if(flag_ecu_sleep==true) ..\Core\Src\rtc.c(152): error: #20: identifier "true" is undefined if(flag_ecu_sleep==true)
11-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值