EasyManua.ls Logo

STMicroelectronics STM8 - Page 114

STMicroelectronics STM8
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
void I2C_setup(void)
{
I2C_DeInit();
I2C_Init(100000,
BH1750_addr,
I2C_DUTYCYCLE_2,
I2C_ACK_CURR,
I2C_ADDMODE_7BIT,
(CLK_GetClockFreq() / 1000000));
I2C_Cmd(ENABLE);
}
void lcd_print(unsigned char x_pos, unsigned char y_pos, unsigned int value)
{
char tmp[5] = {0x20, 0x20, 0x20, 0x20, 0x20} ;
tmp[0] = ((value / 10000) + 0x30);
tmp[1] = (((value / 1000) % 10) + 0x30);
tmp[2] = (((value / 100) % 10) + 0x30);
tmp[3] = (((value / 10) % 10) + 0x30);
tmp[4] = ((value % 10) + 0x30);
LCD_goto(x_pos, y_pos);
LCD_putstr(tmp);
}
BH1750.h
#include "STM8S.h"
#define BH1750_addr 0x46
#define power_down 0x00
#define power_up 0x01
#define reset 0x07
#define cont_H_res_mode1 0x10
#define cont_H_res_mode2 0x11
#define cont_L_res_mode 0x13
#define one_time_H_res_mode1 0x20
#define one_time_H_res_mode2 0x21
#define one_time_L_res_mode 0x23
void BH1750_init(void);
void BH1750_write(unsigned char cmd);
unsigned int BH1750_read_word(void);
unsigned int get_lux_value(unsigned char mode, unsigned int delay_time);
BH1750.c
#include "BH1750.h"
void BH1750_init(void)
{
delay_ms(10);
BH1750_write(power_down);
}

Related product manuals