接上文| 【CW32饭盒派开发板试用体验】光耦中间继电器控制加热设备: 实操1 |
| --------------------------------------------------------------------------------------------------------------- |
光耦中间继电器控制加热设备: 实操2
武汉芯源半导体有限公司技术提供有大量中文标注的 实验例程和固件库,在此基础上很容易编程制作产品。
准备利用【CW32饭盒派开发板试用体验】光耦中间继电器控制加热设备: 实操1为基础(系统时钟配置为64M,AD电位器所用IO口:PB0,OLED屏幕显示AD电压值,V为单位,RTOS,KEY,LED和UART)。增加RTC,KEY,输入输出调试信息。
1. 增加RTC
在RCC_Configuration(void)中增加
RCC_LSI_Enable();
RCC_LSE_Enable(RCC_LSE_MODE_OSC, RCC_LSE_AMP_NORMAL, RCC_LSE_DRIVER_NORMAL);
RCC_APBPeriphClk_Enable1(RCC_APB1_PERIPH_RTC, ENABLE);
程序中增加初始化及中断程序
UART_init();
/* USER CODE BEGIN 2 */
printf("RTC Init...\r\n");
printf(" (RTC CR0:%04x,CR1:%04x,CR2:%04x,RESET FLAG:0x%08x)\r\n",CW_RTC->CR0,CW_RTC->CR1,CW_RTC->CR2,CW_SYSCTRL->RESETFLAG);
//RCC_HSE_Enable(RCC_HSE_MODE_OSC, RCC_HSE_FREQ_GT24M,RCC_HSE_DRIVER_NORMAL, RCC_HSE_FLT_CLOSE); //Ñ¡ÔñHSEΪRTCʱÖÓ
RCC_LSE_Enable(RCC_LSE_MODE_OSC, RCC_LSE_AMP_NORMAL, RCC_LSE_DRIVER_NORMAL); // Ñ¡ÔñLSEΪRTCʱÖÓ
//RCC_LSI_Enable(); // Ñ¡ÔñLSIΪRTCʱÖÓ
// RTC_InitStruct.DateStruct.Day = 0x21; //ÉèÖÃÈÕÆÚ£¬DAY¡¢MONTH¡¢YEAR±ØÐëΪBCD·½Ê½£¬ÐÇÆÚΪ0~6£¬´ú±íÐÇÆÚÈÕ£¬ÐÇÆÚÒ»ÖÁÐÇÆÚÁù
RTC_InitStruct.DateStruct.Year = 0x23;
RTC_InitStruct.DateStruct.Month = RTC_Month_June;
RTC_InitStruct.DateStruct.Day = 0x09;
RTC_InitStruct.DateStruct.Week = RTC_Weekday_Friday;
printf("-------Set Date as 20%x/%x/%x\r\n", RTC_InitStruct.DateStruct.Year,RTC_InitStruct.DateStruct.Month,RTC_InitStruct.DateStruct.Day);
RTC_InitStruct.TimeStruct.Hour = 0x9; //ÉèÖÃʱ¼ä£¬HOUR¡¢MINIUTE¡¢SECOND±ØÐëΪBCD·½Ê½£¬Óû§Ðë±£Ö¤HOUR¡¢AMPM¡¢H24Ö®¼äµÄ¹ØÁªÕýÈ·ÐÔ
RTC_InitStruct.TimeStruct.Minute = 0x58;
RTC_InitStruct.TimeStruct.Second = 0x59;
RTC_InitStruct.TimeStruct.AMPM = 1;
RTC_InitStruct.TimeStruct.H24 = 0;
printf("-------Set Time as %02x:%02x:%02x\r\n", RTC_InitStruct.TimeStruct.Hour,RTC_InitStruct.TimeStruct.Minute,RTC_InitStruct.TimeStruct.Second);
RTC_InitStruct.RTC_ClockSource = RTC_RTCCLK_FROM_LSE;
RTC_Init(&RTC_InitStruct); // Óû§ÐèÑ¡¶¨ÐèҪʹÓõÄʱÖÓÔ´
printf("=====Set interval period as 0.5s...\r\n");
RTC_SetInterval(RTC_INTERVAL_EVERY_1M);//RTC_INTERVAL_EVERY_0_5S
/* ÉèÖÃÄÖÖÓΪ¹¤×÷ÈÕÉÏÎçµÄ6£º45 */
printf("=====Set AlarmA at 6:45 on workday...\r\n");
RTC_AlarmStruct.RTC_AlarmMask = RTC_AlarmMask_WeekMON | RTC_AlarmMask_WeekTUE |
RTC_AlarmMask_WeekWED | RTC_AlarmMask_WeekTHU |
RTC_AlarmMask_WeekFRI;
RTC_AlarmStruct.RTC_AlarmTime.Hour = 6;
RTC_AlarmStruct.RTC_AlarmTime.Minute = 0x45;
RTC_AlarmStruct.RTC_AlarmTime.Second = 0;
RTC_SetAlarm(RTC_Alarm_A, &RTC_AlarmStruct);
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
printf("=====Enable ALRAMA and INTERVAL IT...\r\n");
RTC_ITConfig(RTC_IT_ALARMA | RTC_IT_INTERVAL, ENABLE);
__disable_irq();
NVIC_EnableIRQ(RTC_IRQn);
__enable_irq();
void ShowTime(void)
{
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
static uint8_t *WeekdayStr[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
static uint8_t *H12AMPMStr[2][2]={{"AM","PM"},{"",""}};
RTC_GetDate(&RTC_DateStruct);
RTC_GetTime(&RTC_TimeStruct);
printf(".Date is 20%02x/%02x/%02x(%s).Time is %02x%s:%02x:%02x\r\n", RTC_DateStruct.Year, RTC_DateStruct.Month, RTC_DateStruct.Day, WeekdayStr[RTC_DateStruct.Week], RTC_TimeStruct.Hour, H12AMPMStr[RTC_TimeStruct.H24][RTC_TimeStruct.AMPM],RTC_TimeStruct.Minute, RTC_TimeStruct.Second);
}
void RTC_IRQHandler(void)
{
if (RTC_GetITState(RTC_IT_ALARMA))
{
RTC_ClearITPendingBit(RTC_IT_ALARMA);
printf("*********Alarm!!!!\r\n");
}
if (RTC_GetITState(RTC_IT_INTERVAL))
{
RTC_ClearITPendingBit(RTC_IT_INTERVAL);
ShowTime();
}
}
2. 增加KEY,输入输出调试信息。
**
UART3输入信息部分增加scanf 解析
#define DEBUG_USING_UART3
typedef struct
{
boolean_t recv_flag;
uint8_t data;
} uart_recv_t;
uart_recv_t uart3_recv_sta;
#ifdef DEBUG_USING_UART1
USART_Init(CW_UART1, &USART_InitStructure);
#elif defined DEBUG_USING_UART2
USART_Init(CW_UART2, &USART_InitStructure);
#elif defined DEBUG_USING_UART3
USART_Init(CW_UART3, &USART_InitStructure);
USART_ITConfig(CW_UART3, USART_IT_RC, ENABLE);
NVIC_SetPriority(UART3_IRQn, 0);
NVIC_EnableIRQ(UART3_IRQn);
#endif
void UART3_IRQHandler(void)
{
if(USART_GetITStatus(CW_UART3, USART_IT_RC) != RESET)
{
USART_ClearITPendingBit(CW_UART3, USART_IT_RC);
uart3_recv_sta.data = USART_ReceiveData_8bit(CW_UART3);
uart3_recv_sta.recv_flag = TRUE;
}
}
int fgetc(FILE *f)
{
(void)f;
while (FALSE == uart3_recv_sta.recv_flag) {};
uart3_recv_sta.recv_flag = FALSE;
return (int)uart3_recv_sta.data;
}
3. 变更显示内容
Gui_DrawFont_GBK16(10,47,BLACK,GRAY0,"³ÌÐò");
Gui_DrawFont_GBK16(45,47,BLACK,GRAY0,"( )");
Gui_DrawFont_GBK16(0,70,WHITE,RED,"¡æTEST:\n");
Gui_DrawFont_GBK16(0,95,WHITE,RED,"µçѹVOL:");
temp=(float)adcvalue*(3.3/4096); //µçѹֵ»»Ëã
sprintf(temp_buff1,"%0.2f V ",temp);
Gui_DrawFont_GBK16(80,95,WHITE,RED,temp_buff1);
sprintf(temp_buff1,"%02x/%02x", RTC_DateStruct.Month, RTC_DateStruct.Day);
Gui_DrawFont_GBK16(4,115,WHITE,RED,temp_buff1);
sprintf(temp_buff1,"%02x:%02x:%02x",RTC_TimeStruct.Hour, RTC_TimeStruct.Minute, RTC_TimeStruct.Second);
Gui_DrawFont_GBK16(65,115,WHITE,RED,temp_buff1);
编译**
Build started: Project: GPIO
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'H:\c51\UV4\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling LCD_calculate.c...
compiling Lcd_Driver.c...
compiling MAIN.c...
USER\MAIN.c(483): warning: #550-D: variable "os_Status" was set but never used
osStatus_t os_Status;
USER\MAIN.c: 1 warning, 0 errors
linking...
Program Size: Code=24892 RO-data=7500 RW-data=5884 ZI-data=1772
FromELF: creating hex file...
".\Objects\GPIO.axf" - 0 Error(s), 1 Warning(s).
Build Time Elapsed: 00:00:01
Load "H:\\武汉芯源CW32饭盒派\\7 实验例程\\7 实验例程\\实验九 AD电位器实验 - 副本\\Objects\\GPIO.axf"
Erase Done.
Programming Done.
Verify OK.
Application running ...
Flash Load finished at 16:54:35
调试**
com
RTC Init...
(RTC CR0:0000,CR1:0000,CR2:0000,RESET FLAG:0x00000200)
-------Set Date as 2023/6/9
-------Set Time as 09:58:59
=====Set interval period as 0.5s...
=====Set AlarmA at 6:45 on workday...
=====Enable ALRAMA and INTERVAL IT...
CW32F030 RTX5内核初始化Start
Creating RTX5 object.
.Date is 2023/06/10(SAT).Time is 02AM:41:00
get Space : 15
Get No the message is 0 .
get Space : 8
Get the 1st message is 73 .
Get the 2nd message is 3A .
Get the 3 message is 23 year.
Get the 4 message is 6 Month.
Get the 5 message is 14 Day.
Get the 6 message is 17 Hour.
Get the 7 message is
59 Minute.
Get the 8 message is 0 Second.
--UART-Set Date as 2023/6/14
---UART-Set Time as 17:59:00
Get No the message is 0 .
.Date is 2023/06/14(FRI).Time is 18:00:00
.Date is 2023/06/14(FRI).Time is 18:01:00
.Date is 2023/06/14(FRI).Time is 18:02:00
.Date is 2023/06/14(FRI).Time is 18:03:00
.Date is 2023/06/14(FRI).Time is 18:04:00
.Date is 2023/06/14(FRI).Time is 18:05:00
.Date is 2023/06/14(FRI).Time is 18:06:00
RTOS 状态
图片视频
达到预期。