` OLED智能背光调节 【发帖汇总】
【1】作品介绍: 本作品项目名称为OLED智能背光调节器,主要实现的功能为通过外接IIC数字接口的光强信息传感器模块GY-30,实时采集OLED显示器周围光照功能,通过光强数据进行分级调节OLED的背光。同时使用开发板内置RTC实现了实时时钟功能,并可以通过串口进行时钟配置。 【2】作品图片:
主要显示界面如下: 【3】系统框图: 系统主要组成包括GD32F330主控开发板,GY-30光传感器模块和OLED显示屏四部分组成。以上传感器均采用模拟IIC与主控连接。
【4】原理介绍: OLED背光调节原理介绍:通过光强传感器BH1750采集周围环境实时光照强度,按光照强度大小分级,然后通过对OLED的背光寄存器写入相应的亮度值即可,其中OLED值的范围为00~FF分为256级。
【5】软件介绍: 系统流程图如下:
主函数代码如下:
- /*!
- rief main function
- param[in] none
- param[out] none
-
etval none
- */
- int main(void)
- {
- /* configure systick */
- systick_config();
-
- LED_Init();
- USART1_Init();
- OLED_Init();
- Init_BH1750();
- Init_RTC();
- Init_Key();
-
- PowerOn();
-
- while (1)
- {
-
- #if defined (GD32F330)
- TempCount++;
-
- /* check if RTC has aready been configured */
- if (BKP_VALUE != RTC_BKP0){
- rtc_setup();
- }else{
- /* detect the reset source */
- if (RESET != rcu_flag_get(RCU_FLAG_PORRST)){
- printf("power on reset occurred....
");
- }else if (RESET != rcu_flag_get(RCU_FLAG_EPRST)){
- printf("external reset occurred....
");
- }
- printf("no need to configure RTC....
");
- rtc_show_time();
- }
- rcu_all_reset_flag_clear();
-
- /* check whether the button is pressed */
- if(SET == gpio_input_bit_get(GPIOA, GPIO_PIN_0)){
- delay_1ms(100);
- /* check whether the button is pressed */
- if(SET == gpio_input_bit_get(GPIOA, GPIO_PIN_0)){
- menu_index++;
- if(menu_index == 3)
- menu_index = 1;
- OLED_Clear();
- }
- }
- if(TempCount == 15)
- {
- LED1_ON();
- LED2_OFF();
- }else if(TempCount == 30)
- {
- LED1_OFF();
- LED2_ON();
- TempCount = 0;
- }
-
- datalx = READ_BH1750() / 1.2; //根据手册读取的数据除以1.2就得到单位位lx的光强度检测值
-
- //根据实时光强调节OLED背光强度
- if(datalx > 0 && datalx < 600)
- {
- OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
- OLED_WR_Byte(0xFF,WRcmd); // Set SEG Output Current Brightness
- }else if(datalx > 600 && datalx < 1060)
- {
- OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
- OLED_WR_Byte(0x8F,WRcmd); // Set SEG Output Current Brightness
- }else if(datalx > 1060 && datalx < 1900)
- {
- OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
- OLED_WR_Byte(0x3F,WRcmd); // Set SEG Output Current Brightness
- }else if(datalx > 1900 && datalx < 5000)
- {
- OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
- OLED_WR_Byte(0x0F,WRcmd); // Set SEG Output Current Brightness
- }
-
- rtc_current_time_get(&rtc_info);
-
- switch(menu_index)
- {
- case 1:
- OLED_DisString(4u,0u,(uint8_t *)"GD32F330C-START");
- OLED_DisString(0u,2u,(uint8_t *)"OLED Dimmer V1.0");
- OLED_DisString(0u,4u,(uint8_t *)"Light:");
- OLED_DisString(110u,4u,(uint8_t *)"lx");
- OLED_DisNum(60u,4u,datalx,5,16,LineYes);
- OLED_DisString(0u,6u,(uint8_t *)"bbs.elecfans.com");
- break;
- case 2:
- OLED_DisBMP(48u,0u,80u,4u,(uint8_t *)CLOCK_logo);
- sprintf(outputstring,"Date:20%0.2x-%0.2x-%0.2x",rtc_info.rtc_year, rtc_info.rtc_month , rtc_info.rtc_date);
- OLED_DisString(4u,4u,(uint8_t *)outputstring);
- sprintf(outputstring,"Time:%0.2x:%0.2x:%0.2x",rtc_info.rtc_hour, rtc_info.rtc_minute, rtc_info.rtc_second);
- OLED_DisString(4u,6u,(uint8_t *)outputstring);
- break;
- default:
- OLED_DisString(4u,0u,(uint8_t *)"GD32F330C-START");
- OLED_DisString(0u,2u,(uint8_t *)"OLED Dimmer V1.0");
- OLED_DisString(0u,4u,(uint8_t *)"Light:");
- OLED_DisString(110u,4u,(uint8_t *)"lx");
- OLED_DisNum(60u,4u,datalx,5,16,LineYes);
- OLED_DisString(0u,6u,(uint8_t *)"bbs.elecfans.com");
- break;
- }
- #endif
复制代码
【6】作品展示:
`
|