接上文【CW32饭盒派开发板试用体验】+开箱+软件
光耦中间继电器控制加热设备: 实操1
武汉芯源半导体有限公司技术提供有大量中文标注的 实验例程和固件库,在此基础上很容易编程制作产品。
准备利用厂家提供 实验例程\7 实验例程\实验九 AD电位器实验为基础(系统时钟配置为64M,AD电位器所用IO口:PB0,OLED屏幕显示AD电压值,V为单位),变更OLED屏幕显示内容,先增加RTOS,KEY,LED和UART输出调试信息。
1. 增加RTOS
void thread_LED_App(void *argument);
void thread_Start_App(void *argument);
osThreadId_t threadID_Start_Thread = NULL;
osThreadId_t threadID_LED_Thread = NULL;
osStatus_t check_Status;
const osThreadAttr_t thread_LED_Attr =
{
.name = "LED_App",
.attr_bits = osThreadJoinable,
.priority = osPriorityLow,
.stack_size = 512,
};
const osThreadAttr_t thread_Start_Attr =
{
.name = "Start_App",
.attr_bits = osThreadJoinable,
.priority = osPriorityHigh4,
.stack_size = 256,
};
osKernelInitialize();
threadID_Start_Thread = osThreadNew(thread_Start_App, NULL, &thread_Start_Attr);
osKernelStart();
2. 增加KEY,LED
` GPIO_InitTypeDef GPIO_InitStruct;
__RCC_GPIOB_CLK_ENABLE();
__RCC_GPIOC_CLK_ENABLE();
__RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.IT = GPIO_IT_NONE; //KEY1 KEY2 KEY3
GPIO_InitStruct.Mode = GPIO_MODE_INPUT_PULLUP;
GPIO_InitStruct.Pins = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.IT = GPIO_IT_NONE; //LED2 LED3
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pins = GPIO_PIN_7|GPIO_PIN_8;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pins = GPIO_PIN_13
GPIO_Init(CW_GPIOC, &GPIO_InitStruct);
GPIO_WritePin(CW_GPIOB,GPIO_PIN_7|GPIO_PIN_8,GPIO_Pin_RESET);
GPIO_WritePin(CW_GPIOC,GPIO_PIN_13,GPIO_Pin_RESET);
3. 增加UART
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
``````UART_init();
void UART_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APBPeriphClk_Enable1(RCC_APB1_PERIPH_UART3, ENABLE);
RCC_AHBPeriphClk_Enable( RCC_AHB_PERIPH_GPIOA, ENABLE);
PUTCHAR_PROTOTYPE
{
USART_SendData_8bit(CW_UART3, (uint8_t)ch);
while (USART_GetFlagStatus(CW_UART3, USART_FLAG_TXE) == RESET);
return ch;
}
PA09_AFx_UART1RXD();
PA09_AFx_UART1RXD();
PA09_AFx_UART3TXD();
PA10_AFx_UART3RXD() ;
GPIO_InitStructure.Pins = GPIO_PIN_9;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_10;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT_PULLUP;
GPIO_Init(CW_GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_Over = USART_Over_16;
USART_InitStructure.USART_Source = USART_Source_PCLK;
USART_InitStructure.USART_UclkFreq = 64000000;
USART_InitStructure.USART_StartBit = USART_StartBit_FE;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(CW_UART3, &USART_InitStructure);
}
build:
Program Size: Code=17260 RO-data=7464 RW-data=5684 ZI-data=1844
FromELF: creating hex file...
".\Objects\GPIO.axf" - 0 Error(s), 1 Warning(s).
Build Time Elapsed: 00:00:06
**运行com口:**
CW32F030 UART Printf Example
Creating RTX5 object.
CW32F030 UART Printf Example
Creating RTX5 object.
Start App going to exit.
RTOS 状态
达到预期。
图片视频