You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include "bh1750.h"
|
|
|
|
|
#include "sys.h"
|
|
|
|
|
|
|
|
|
|
//д<EFBFBD><EFBFBD>
|
|
|
|
|
void Single_Write_BH1750(unsigned char REG_Address)
|
|
|
|
|
{
|
|
|
|
|
MYIIC1_Start();
|
|
|
|
|
MYIIC1_Send_Byte(BHAddWrite);
|
|
|
|
|
MYIIC1_Send_Byte(REG_Address);
|
|
|
|
|
MYIIC1_Stop();
|
|
|
|
|
}
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void bh_data_send(u8 command)
|
|
|
|
|
{
|
|
|
|
|
do{
|
|
|
|
|
MYIIC1_Start();
|
|
|
|
|
MYIIC1_Send_Byte(BHAddWrite);
|
|
|
|
|
}while(MYIIC1_Wait_Ack());
|
|
|
|
|
MYIIC1_Send_Byte(command);
|
|
|
|
|
MYIIC1_Wait_Ack();
|
|
|
|
|
MYIIC1_Stop();
|
|
|
|
|
}
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
u16 bh_data_read(void)
|
|
|
|
|
{
|
|
|
|
|
u16 buf;
|
|
|
|
|
u8 a;
|
|
|
|
|
u8 b;
|
|
|
|
|
MYIIC1_Start();
|
|
|
|
|
MYIIC1_Send_Byte(BHAddRead);
|
|
|
|
|
MYIIC1_Wait_Ack();
|
|
|
|
|
b=MYIIC1_Read_Byte(1);
|
|
|
|
|
a=MYIIC1_Read_Byte(0);
|
|
|
|
|
buf=b*256+a;
|
|
|
|
|
MYIIC1_Stop();
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|
|
|
|
void Init_BH1750(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, ENABLE);
|
|
|
|
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
|
|
|
|
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
|
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(GPIOB,&GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
|
|
|
|
|
GPIO_Init(GPIOA,&GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
Single_Write_BH1750(0x01);
|
|
|
|
|
delay_ms(180);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|