GigaDevice GD32 MCU
直播中

赵俊涛

10年用户 173经验值
擅长:嵌入式技术 模拟技术 接口/总线/驱动
私信 关注
[经验]

【GD32330C-START开发板试用体验】OLED智能背光调节作品提交

`
OLED智能背光调节
【发帖汇总】

【1】作品介绍:
       本作品项目名称为OLED智能背光调节器,主要实现的功能为通过外接IIC数字接口的光强信息传感器模块GY-30,实时采集OLED显示器周围光照功能,通过光强数据进行分级调节OLED的背光。同时使用开发板内置RTC实现了实时时钟功能,并可以通过串口进行时钟配置。
【2】作品图片:
作品图片.jpg
主要显示界面如下:
【3】系统框图:
       系统主要组成包括GD32F330主控开发板,GY-30光传感器模块和OLED显示屏四部分组成。以上传感器均采用模拟IIC与主控连接。
系统框图.png
【4】原理介绍:
OLED背光调节原理介绍:通过光强传感器BH1750采集周围环境实时光照强度,按光照强度大小分级,然后通过对OLED的背光寄存器写入相应的亮度值即可,其中OLED值的范围为00~FF分为256级。
OLED.png
【5】软件介绍:
系统流程图如下:
系统流程图.png
主函数代码如下:
  1. /*!
  2.     rief      main function
  3.     param[in]  none
  4.     param[out] none
  5.    
    etval     none
  6. */
  7. int main(void)
  8. {
  9.     /* configure systick */
  10.     systick_config();
  11.         
  12.                 LED_Init();
  13.                 USART1_Init();
  14.                 OLED_Init();
  15.                 Init_BH1750();
  16.                 Init_RTC();
  17.                 Init_Key();
  18.         
  19.                 PowerOn();
  20.                
  21.     while (1)
  22.                 {
  23.                         
  24. #if defined (GD32F330)
  25.                         TempCount++;
  26.                         
  27.                         /* check if RTC has aready been configured */
  28.                         if (BKP_VALUE != RTC_BKP0){   
  29.                                         rtc_setup();
  30.                         }else{
  31.                                         /* detect the reset source */
  32.                                         if (RESET != rcu_flag_get(RCU_FLAG_PORRST)){
  33.                                                         printf("power on reset occurred....

  34. ");
  35.                                         }else if (RESET != rcu_flag_get(RCU_FLAG_EPRST)){
  36.                                                         printf("external reset occurred....

  37. ");
  38.                                         }
  39.                                         printf("no need to configure RTC....

  40. ");

  41.                                         rtc_show_time();
  42.                         }
  43.                         rcu_all_reset_flag_clear();
  44.                         
  45.                         /* check whether the button is pressed */
  46.                         if(SET == gpio_input_bit_get(GPIOA, GPIO_PIN_0)){
  47.                                         delay_1ms(100);
  48.                                         /* check whether the button is pressed */
  49.                                         if(SET == gpio_input_bit_get(GPIOA, GPIO_PIN_0)){
  50.                                                         menu_index++;
  51.                                                         if(menu_index == 3)
  52.                                                                 menu_index = 1;
  53.                                                   OLED_Clear();
  54.                                         }
  55.                         }

  56.                         if(TempCount == 15)
  57.                         {
  58.                                 LED1_ON();
  59.                                 LED2_OFF();
  60.                         }else if(TempCount == 30)
  61.                         {
  62.                                 LED1_OFF();
  63.                                 LED2_ON();
  64.                                 TempCount = 0;
  65.                         }
  66.                         
  67.                         datalx = READ_BH1750() / 1.2; //根据手册读取的数据除以1.2就得到单位位lx的光强度检测值
  68.                         
  69.                         //根据实时光强调节OLED背光强度
  70.                         if(datalx > 0 && datalx < 600)
  71.                         {
  72.                                 OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  73.                                 OLED_WR_Byte(0xFF,WRcmd); // Set SEG Output Current Brightness
  74.                         }else if(datalx > 600 && datalx < 1060)
  75.                         {
  76.                                 OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  77.                                 OLED_WR_Byte(0x8F,WRcmd); // Set SEG Output Current Brightness
  78.                         }else if(datalx > 1060 && datalx < 1900)
  79.                         {
  80.                                 OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  81.                                 OLED_WR_Byte(0x3F,WRcmd); // Set SEG Output Current Brightness
  82.                         }else if(datalx > 1900 && datalx < 5000)
  83.                         {
  84.                                 OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  85.                                 OLED_WR_Byte(0x0F,WRcmd); // Set SEG Output Current Brightness
  86.                         }
  87.                         
  88.                         rtc_current_time_get(&rtc_info);
  89.                         
  90.                         switch(menu_index)
  91.                         {
  92.                                 case 1:
  93.                                         OLED_DisString(4u,0u,(uint8_t *)"GD32F330C-START");
  94.                                   OLED_DisString(0u,2u,(uint8_t *)"OLED Dimmer V1.0");
  95.                                         OLED_DisString(0u,4u,(uint8_t *)"Light:");
  96.                                         OLED_DisString(110u,4u,(uint8_t *)"lx");
  97.                                         OLED_DisNum(60u,4u,datalx,5,16,LineYes);
  98.                                         OLED_DisString(0u,6u,(uint8_t *)"bbs.elecfans.com");
  99.                                 break;
  100.                                 case 2:
  101.                                         OLED_DisBMP(48u,0u,80u,4u,(uint8_t *)CLOCK_logo);
  102.                                         sprintf(outputstring,"Date:20%0.2x-%0.2x-%0.2x",rtc_info.rtc_year, rtc_info.rtc_month , rtc_info.rtc_date);
  103.                                         OLED_DisString(4u,4u,(uint8_t *)outputstring);
  104.                                         sprintf(outputstring,"Time:%0.2x:%0.2x:%0.2x",rtc_info.rtc_hour, rtc_info.rtc_minute, rtc_info.rtc_second);
  105.                                         OLED_DisString(4u,6u,(uint8_t *)outputstring);
  106.                                 break;
  107.                                 default:
  108.                                         OLED_DisString(4u,0u,(uint8_t *)"GD32F330C-START");
  109.                                   OLED_DisString(0u,2u,(uint8_t *)"OLED Dimmer V1.0");
  110.                                         OLED_DisString(0u,4u,(uint8_t *)"Light:");
  111.                                         OLED_DisString(110u,4u,(uint8_t *)"lx");
  112.                                         OLED_DisNum(60u,4u,datalx,5,16,LineYes);
  113.                                         OLED_DisString(0u,6u,(uint8_t *)"bbs.elecfans.com");
  114.                                 break;
  115.                         }

  116. #endif        

【6】作品展示:
[media]http://v.youku.com/v_show/id_XMzg0MDY0MzI4NA==.html?spm=a2h3j.8428770.3416059.1[/media]



` OLED1_副本.jpg

更多回帖

发帖
×
20
完善资料,
赚取积分