- void Get_Sunlight_Value()
- {
- int dis_data=0;
- float temp;
- char i=0;
- unsigned int sd;
- Single_Write_BH1750(0x01);
- Single_Write_BH1750(0x10);
- Delay(180);
- Multiple_Read_BH1750();
- for(i=0;i<3;i++) dis_data=BUF[0];
- dis_data=(dis_data<<8)+BUF[1];
- temp=(float)dis_data/1.2;
- sd=temp;
- LCD_ShowNum(120,50,sd,5,YELLOW);
- }
显示光强检测与显示的主程序为:
- void main(void)
- {
- P0CON = 0xFF;
- P0PH = 0x00;
- P1CON = 0x00;
- P1PH = 0x00;
- P2CON = 0xFF;
- P2PH = 0x00;
- P3CON = 0xFF;
- P3PH = 0x00;
- P4CON = 0xFF;
- P4PH = 0x01;
- P5CON = 0xFF;
- P5PH = 0x00;
- GPIO_Init(GPIO0, GPIO_PIN_4 | GPIO_PIN_5 |GPIO_PIN_6, GPIO_MODE_OUT_PP);
- GPIO_Init(GPIO2, GPIO_PIN_2, GPIO_MODE_OUT_PP);
- GPIO_Init(GPIO5, GPIO_PIN_3, GPIO_MODE_OUT_PP);
- GPIO_Init(GPIO4, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5, GPIO_MODE_OUT_PP);
- Delay(100);
- Lcd_Init();
- LCD_Clear(RED);
- BACK_COLOR=RED;
- LCD_Picturea();
- LCD_ShowChinese(80,10,0,16,YELLOW);
- LCD_ShowChinese(96,10,1,16,YELLOW);
- LCD_ShowChar(112,10,':',0,YELLOW);
- LCD_ShowChinese(80,30,2,16,YELLOW);
- LCD_ShowChinese(96,30,3,16,YELLOW);
- LCD_ShowChar(112,30,':',0,YELLOW);
- LCD_ShowChinese(80,50,4,16,YELLOW);
- LCD_ShowChinese(96,50,5,16,YELLOW);
- LCD_ShowChar(112,50,':',0,YELLOW);
- while(1)
- {
- Get_Sunlight_Value();
- Delay(1000);
- }
- }
经程序的编译与下载,其运行效果如下图所示。
光强检测效果