功能
msp430g2553单片机,读取gy-30的光照强度,oled显示光照强度,依据光照强度调节小灯亮度。
硬件
gy-30
0.96寸 iic oled
//gy-30
//SCL--P1.4
//SDA--P1.5
//VCC--3.3V
//GND--GND
//ADDR--GND//oled
//SCL--P2.0
//SDA--P2.1
//VCC--3.3V
//GND--GND
部分程序
#include <msp430.h>
#include "gy30.h"
#include "oled.h"float lx;
int main(void)
{int lx_int;unsigned char dis[10];WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */OLED_Init();OLED_ShowCHinese(16 * 2, 0, 0);OLED_ShowCHinese(16 * 3, 0, 1);OLED_ShowCHinese(16 * 4, 0, 2);OLED_ShowCHinese(16 * 5, 0, 3);while (1){lx_int = (int) get_lightpower();CCR1 = lx_int/10; // PWM 高电平时间dis[0] = lx_int / 10000 + '0';dis[1] = lx_int % 10000 / 1000 + '0';dis[2] = lx_int % 1000 / 100 + '0';dis[3] = lx_int % 100 / 10 + '0';dis[4] = lx_int % 10 + '0';dis[5] = 'L';dis[6] = 'x';dis[7] = 0;OLED_ShowString(8 * 3, 2, dis);delay_ms(200);}
}
全部程序
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2