GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = LCD_SDA_Pin;
- GPIO_InitStruct.Pin = LCD_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LCD_SDA_GPIO_Port, &GPIO_InitStruct);
}
ht1622_delay_us(10);
if( ht1622_data_read() )
d |= 1<<i;
- ht1622_rd_clk_l(); //max 75K
+ ht1622_rd_clk_h(); //max 75K
ht1622_delay_us(10);
}
*data = d;
ht1622_delay_us(5);
ht1622_cs_h();
}
+void ht1622_ram_read( uint8_t addr, uint8_t *data_8b, uint8_t data_nr )
+{
+ ht1622_cs_h();
+ ht1622_data_dir_output();
+ ht1622_wr_clk_h();
+ ht1622_rd_clk_h();
+ ht1622_data_out_h();
+
+ ht1622_cs_l(); ht1622_delay_us(5);
+
+ ht1622_write_bits( MODE_ID_READ, 3, 1 );
+ ht1622_write_bits( addr, 6, 1 );
+
+ ht1622_delay_us(5);
+ ht1622_data_dir_input();
+ for( int i=0; i<data_nr; i++ ){
+ ht1622_read_bits( &data_8b[i], 8 );
+ }
+ ht1622_delay_us(5);
+ ht1622_data_dir_output();
+ ht1622_delay_us(5);
+ ht1622_cs_h();
+}
typedef struct{
osDelay( 500);
HAL_TIM_PWM_Stop( &htim13, TIM_CHANNEL_1 );
#endif
-
+
+#if 0
//有源蜂鸣器,配置为输出脚
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = PF8_PWM_SPK_TIM13_CH1_Pin;
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
osDelay(50);
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
-
+#else
+//PE0_LCM_EN 改成蜂鸣器
+//PF8_PWM_SPK_TIM13_CH1 改成背光控制 PWM
+ #define BEEP_CTRL_PIN LCM_EN_Pin //GPIO_PIN_0
+ #define BEEP_CTRL_PORT LCM_EN_GPIO_Port //GPIOE
+ #define BEEP_ON() HAL_GPIO_WritePin(BEEP_CTRL_PORT, LCM_EN_Pin, GPIO_PIN_SET)
+ #define BEEP_OFF() HAL_GPIO_WritePin(BEEP_CTRL_PORT, LCM_EN_Pin, GPIO_PIN_RESET)
+
+ BEEP_OFF();
+ GPIO_InitStruct.Pin = BEEP_CTRL_PIN;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(BEEP_CTRL_PORT, &GPIO_InitStruct);
+
+ BEEP_ON();
+ osDelay(50);
+ BEEP_OFF();
+
+#endif
+
//TODO: 实际使用有源, 待修改代码
while(1){
//TODO: 按需要增加提示音管理
if( g_dev.state & FLOWMETER_ERR ){
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ BEEP_ON();
osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ BEEP_OFF();
osDelay(1000);
}
if( g_dev.state & CURR_SENSOR_ERR ){
for( i=0; i<2; i++ ){
osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
- osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ BEEP_ON();
+ osDelay(100);
+ BEEP_OFF();
}
osDelay(1000);
}
if( g_dev.state & PRESSURE_SENSOR_ERR ){
for( i=0; i<3; i++ ){
osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
- osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ BEEP_ON();
+ osDelay(100);
+ BEEP_OFF();
}
osDelay(1000);
}
if( g_dev.state & VALVE_CTRL_ERR ){
for( i=0; i<4; i++ ){
osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
- osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ BEEP_ON();
+ osDelay(100);
+ BEEP_OFF();
}
osDelay(1000);
}
if( g_dev.state & TEMP_ERR ){
for( i=0; i<5; i++ ){
osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
- osDelay(100);
- HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ BEEP_ON();
+ osDelay(100);
+ BEEP_OFF();
}
osDelay(1000);
}
void lcd_power_on( void )
{
- HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_SET );
+// HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_SET );
}
void lcd_power_off( void )
{
- HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_RESET );
+// HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_RESET );
}
static uint32_t remote_update_cfg_flag = 0;
static uint8_t bl_level = 0; //0 - 10;
-
-extern void pwm_isr( void )
+static int32_t curr_bl = 0;
+uint32_t bl_compare[11] = {50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
+
+void lcd_bl( uint32_t level )
+{
+ if( level > 10 )
+ level = 10;
+ __HAL_TIM_SET_COMPARE(&htim13, TIM_CHANNEL_1, bl_compare[level] );
+}
+
+void lcd_bl_init( void )
{
- static uint8_t bl_timer_count = 0;
- HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, ( bl_timer_count < bl_level )?GPIO_PIN_SET:GPIO_PIN_RESET );
- if( bl_timer_count>= 9 )
- bl_timer_count = 0;
- else
- bl_timer_count++;
+ bl_level = 5;
+ curr_bl = 5;
+
+ HAL_TIM_PWM_Start( &htim13, TIM_CHANNEL_1 );
+ __HAL_TIM_SET_COMPARE(&htim13, TIM_CHANNEL_1, 500 );
+ lcd_bl( curr_bl );
}
#define DEV_MODE_WORK 0
HAL_GPIO_WritePin( PB3_LEDG_GPIO_Port, PB3_LEDG_Pin, GPIO_PIN_RESET );
HAL_GPIO_WritePin( PB3_LEDR_GPIO_Port, PB3_LEDR_Pin, (now%1000)<500?GPIO_PIN_SET:GPIO_PIN_RESET );
}
+ //backlight
+ {
+ if(curr_bl != bl_level ){ //bl 0--10
+ curr_bl = bl_level;
+ lcd_bl( curr_bl );
+ }
+ }
}
}
+
void lcd_init( void );
void user_ui_h3_task( void* unused )
{
tick = xTaskGetTickCount();
lcd_init();
+ lcd_bl_init();
while(1){
//dbg_t1 = TIM7->CNT;