15. STC15W408AS MCU drives BH1750FVI light intensity sensor

Publisher:BlossomWhisperLatest update time:2022-08-03 Source: csdnKeywords:STC15W408AS Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the previous article, we introduced IIC driving OLED display. This article is about IIC driving BH1750FVI light intensity sensor. In fact, I also wrote about BH1750FVI light intensity sensor in the previous Raspberry Pi series 17. Raspberry Pi 3B+ driving BH1750FVI light intensity sensor


Here is an IIC bus with two IIC slave devices mounted on it.


product description


BH1750FVI is a digital light intensity sensor IC for two-wire serial bus interface. This IC can adjust the brightness of LCD or keyboard backlight according to the collected light intensity data. Its high resolution can detect a wide range of light intensity changes. (1lx-65535lx)


Features


1. Support I2C BUS interface (f/s Mode Support).


2. Spectral sensitivity characteristics close to visual sensitivity (peak sensitivity wavelength typical value: 560nm).


3. Output the digital value corresponding to the brightness.


4. Corresponds to a wide range of input light (equivalent to 1-65535lx).


5. Realize low current by reducing power function.


6. Stable measurement is achieved through 50Hz/60Hz optical noise removal function. 7. Supports 1.8V logic input interface.


8. No other external parts are required.


9. Weak dependence on light sources (incandescent lamp, fluorescent lamp, halogen lamp, white light LED, fluorescent lamp).


10. There are two optional I2C slave addresses.


11. The factor that has the greatest impact on the adjustable measurement results is the size of the light entrance.


12. Using this function, the range from 1.1 lx to 100000 lx max/min can be calculated.


13. The minimum error variation is ±20%.


14. Little affected by infrared rays.


Applications


Mobile phones, LCD TVs, laptops, portable game consoles, digital cameras, digital video cameras, car positioning systems, LCD monitors.


Chip Block Diagram

picture

describe:

・PD Photo diode with approximately human eye response. 


・AMP Integrated operational amplifier: Converts PD current to PD voltage.


・ADC analog-to-digital conversion obtains 16-bit digital data.


・Logic + IC Interface Light intensity calculation and I2C bus interface, including the following registers: Data register → light intensity data storage. The initial value is: "0000_0000_0000_0000". Measurement time register → time measurement data storage. The initial value is: "0100_0101".


・OSC Internal oscillator (clock frequency typical value: 320kHz). This clock is the internal logic clock.


It can also be seen from this block diagram that the internal modules of this chip are relatively simple and the actual use is not complicated.


Measurement procedure steps

picture

Instruction set structure

picture

Example of measurement sequence from "writing instruction" to "reading measurement results"

picture

#define IIC_SCL P10 // Clock

#define IIC_SDA P11 // data

This is the connection between IIC and microcontroller IO port.


Driver code


#include "bh1750fvi.h"

#include "iic.h"

 

#define BH1750FVI_SlaveAddress 0x46 // Device address

#define BH1750FVI_DOWN 0x00 // Power off instruction

#define BH1750FVI_ON 0x01 // Power-on command

#define BH1750FVI_RESEET 0x07 // Reset

 

#define BH1750FVI_CON_H 0x10 // Continuous resolution mode, 1lx, 120ms

#define BH1750FVI_CON_H2 0x11 // Continuous resolution mode, 0.5lx, 120ms

#define BH1750FVI_CON_L 0x13 // Continuous low resolution mode, 4lx, 16ms

#define BH1750FVI_ONE_H 0x20 // One time high resolution mode, 1lx, 120ms

#define BH1750FVI_ONE_H2 0x21 // One time high resolution mode, 0.5lx, 120ms

#define BH1750FVI_ONE_L 0x23 // One time low resolution mode, 4lx, 16ms 

 

// Write data to BH1750FVI

void BH1750FVI_Write_Reg(u8 reg)

{

  IIC_Start();

  IIC_Write_Byte(BH1750FVI_SlaveAddress);

  IIC_Write_Byte(reg);

  IIC_Stop();

 

}

// Read 1 byte of data

u8 BH1750FVI_Read_Reg(u8 reg)

{

  u8 that;

  IIC_Start();

  IIC_Write_Byte(BH1750FVI_SlaveAddress);

  IIC_Write_Byte(reg);

  IIC_Start();

  IIC_Write_Byte(BH1750FVI_SlaveAddress + 1);

  dat = IIC_Read_Byte();

  IIC_Stop();

  return that;

}

u16 BH1750FVI_Read_all()

{

  u8 i;

  u8 BUF[8];

  u16 that;

  IIC_Start();

  IIC_Write_Byte(BH1750FVI_SlaveAddress + 1);

  for(i = 0; i < 2; i++)

  {

    BUF[i] = IIC_Read_Byte();

    if(i == 2){

      IIC_Send_Ack(1);

    }else{

      IIC_Send_Ack(0);

    }

  }

  IIC_Stop();

  that = BUF[0]<<8 + BUF[1];

  return that;

}

 

u16 BH1750FVI_Measure()

{

  BH1750FVI_Write_Reg(BH1750FVI_ON);

  BH1750FVI_Write_Reg(BH1750FVI_CON_H);

  return BH1750FVI_Read_all();

}

 

void BH1750FVI_Init()

{

  BH1750FVI_Write_Reg(BH1750FVI_DOWN);

  BH1750FVI_Write_Reg(BH1750FVI_ON);

}


 


main.c


#include "stc15.h"

#include "delay.h"

#include "bh1750fvi.h"

#include "oled.h"

 

u8 num[] = {'0','1','2','3','4','5','6','7','8','9'};

 

void main()

{

  u16 result;

  BH1750FVI_Heat();

  OLED_Init(); //Initialize OLED  

  OLED_Clear()    ; 

  while (1)

  {

    result = BH1750FVI_Measure();

    OLED_ShowChar(0,0,num[result/10000],1); // 10,000

    OLED_ShowChar(10,0,num[result%10000/1000],1); // Thousands

    OLED_ShowChar(20,0,num[result%10000%1000/100],1); // Hundred

    OLED_ShowChar(30,0,num[result%10000%1000%100/10],1);// ten  

    OLED_ShowChar(40,0,num[result%10],1); //

    delayms(2000);

  }

}


Display effect diagram

picture

Keywords:STC15W408AS Reference address:15. STC15W408AS MCU drives BH1750FVI light intensity sensor

Previous article:16.STC15W408AS MCU obtains DS18B20 temperature
Next article:14. STC15W408AS MCU IIC drives OLED

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号