【上海航芯 ACM32F070开发板】第二篇点亮LCD屏和触控按键功能操作,串口,ADC。
[复制链接]
本帖最后由 meiyao 于 2022-11-3 00:24 编辑
这个是上一篇的【上海航芯 ACM32F070开发板】点亮LCD屏和触控按键功能操作,驱动蜂鸣器测评
https://bbs.eeworld.com.cn/forum.php?mod=viewthread&tid=1223373&page=1&extra=#pid3185232
串口原理连接:
串口连接是通过YTPE C接口与PC连接,板载上与ACH512再经过SED这个排针端子,再接到MCU PA2(TX2) PA3(RX2).
温湿度传感器:SHT3这个传感器是接的MCU的PD6和PD7
SHT30的温度精度是正负0.3摄氏度,湿度是正负2%。采用IIC通信,通信的速度可以达到1MHZ,这个模块有两个地址。
功能引用:3脚ALERT是警示输出脚;
6脚是复位。
2脚是地址脚,如果是上拉地址就是0x45,如果是下拉就是0X44;
下面继续更新LCD屏的显示操作:
继续上这个函数代码:
void LCD_DisplayNum_YR1618A(uint32_t Num)
{
uint32_t ram_buff[4];
ram_buff[0]=0;
ram_buff[1]=0;
ram_buff[2]=0;
ram_buff[3]=0;
// ram_buff[4]=0;
if(Num>9999) Num=9999;//4位数,最大显示9999
Get_RAM_NUM_DATA(ram_buff,Num,Num);
HAL_LCD_Write(&lcdhandle_YR1618A,0,ram_buff[0]);
HAL_LCD_Write(&lcdhandle_YR1618A,1,ram_buff[1]);
HAL_LCD_Write(&lcdhandle_YR1618A,2,ram_buff[2]);
HAL_LCD_Write(&lcdhandle_YR1618A,3,ram_buff[3]);
// HAL_LCD_Write(&lcdhandle_YR1618A,4,ram_buff[4]);
}
再While中:
Num1++;
System_Delay_MS(500);
LCD_DisplayNum_YR1618A(Num1);
这个代码的意思是增加变量来显示数字的增加。
下面上IIC代码:
void I2C_Init(void)
{
I2C_Handle.Instance = I2C2;
I2C_Handle.Init.I2C_Mode = I2C_MODE_MASTER;
I2C_Handle.Init.Tx_Auto_En = TX_AUTO_EN_ENABLE;
I2C_Handle.Init.Clock_Speed = CLOCK_SPEED_STANDARD;
I2C_Handle.Init.No_Stretch_Mode = NO_STRETCH_MODE_NOSTRETCH;
HAL_I2C_Init(&I2C_Handle);
}
下面是脚位定义:
#define SHT30_I2C I2C2
//-----------------SHT30 IIC端口定义----------------
#define SHT30_SCL_PIN GPIOD6
#define SHT30_SCL_PIN_AF GPIOD6_AF_I2C2_SCL
#define SHT30_SDA_PIN GPIOD7
#define SHT30_SDA_PIN_AF GPIOD7_AF_I2C2_SDA
下面是获取值:
uint8_t SHT30_Reset(I2C_HandleTypeDef I2C_Handle)
{
HAL_StatusTypeDef Status;
uint8_t cmd_buffer[2];
cmd_buffer[0] = SOFT_RESET_CMD >> 8;
cmd_buffer[1] = SOFT_RESET_CMD & 0XFF;
Status=HAL_I2C_Master_Transmit(&I2C_Handle, SHT30_SLAVE_ADDRESS, cmd_buffer, 2,100);
System_Delay_MS(500);
cmd_buffer[0] = CLEAR_STATES_CMD >> 8;
cmd_buffer[1] = CLEAR_STATES_CMD & 0XFF;
Status=HAL_I2C_Master_Transmit(&I2C_Handle, SHT30_SLAVE_ADDRESS, cmd_buffer, 2,100);
System_Delay_MS(200);
return Status;
}
这个是通过IIC采集温湿度的值,显示在LCD屏上。
串口:
void Uart_Init(uint32_t fu32_Baudrate)
{
UART2_Handle.Instance = UART2;
UART2_Handle.Init.BaudRate = fu32_Baudrate;
UART2_Handle.Init.WordLength = UART_WORDLENGTH_8B;
UART2_Handle.Init.StopBits = UART_STOPBITS_1;
UART2_Handle.Init.Parity = UART_PARITY_NONE;
UART2_Handle.Init.Mode = UART_MODE_TX_RX_DEBUG;
UART2_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
HAL_UART_Init(&UART2_Handle);
/* UART_DEBUG_ENABLE control printfS */
}
打印MCU的相关信息:
printfS("MCU is running, HCLK=%dHz, PCLK=%dHz\n", System_Get_SystemClock(), System_Get_APBClock());
打印触摸按下的键:
ret = TouchKey_Init();
if(ret)
{
printfS("TouchKey_Init is Fail!\r\n");
}
else
{
printfS("TouchKey_Init is Success!\r\n");
}
printfS("TK_%d\r\n", fu8_Tkey_state);
利用串口打印出是哪一个按键被按下,反馈出来。
下面是操作视频:
4631981b77c5c7d21bee2759d48f404e
0667bda907833dff81d63dc3c1473521
|