STMicroelectronics STM8 Manual page 114

Table of Contents

Advertisement

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
#define power_down
#define power_up
#define reset
#define cont_H_res_mode1
#define cont_H_res_mode2
#define cont_L_res_mode
#define one_time_H_res_mode1
#define one_time_H_res_mode2
#define one_time_L_res_mode
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);
}
0x46
0x00
0x01
0x07
0x10
0x11
0x13
0x20
0x21
0x23

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM8 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF