//GY-30
//SCL--P1.4
//SDA--P1.5
//VCC--3.3V
//GND--GND
//ADDR--不接
cpp展开代码#include <msp430.h>
#include "gy30.h"
void Send_Byte(char data)
{
    while (!(IFG2 & UCA0TXIFG))
        ;                // USCI_A0 TX buffer ready?
    UCA0TXBUF = data;                    // TX -> RXed character
}
void Print_Str(char *s)
{
    while (*s != '\0')
    {
        Send_Byte(*s++);
        delay_ms(5);
    }
}
int lx;
int main(void)
{
    char SENDSTR[20];
    WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */
    if (CALBC1_1MHZ == 0xFF)                  // If calibration constant erased
    {
        while (1)
            ;                               // do not load, trap CPU!!
    }
    DCOCTL = 0;                          // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ;                    // Set range
    DCOCTL = CALDCO_1MHZ;                     // Set DCO step + modulation */
    while (1)
    {
        lx = (int)get_lightpower();
        Print_Str("GY30:");
        SENDSTR[0] = lx % 100000 / 10000 + '0';
        SENDSTR[1] = lx % 10000 / 1000 + '0';
        SENDSTR[2] = lx % 1000 / 100 + '0';
        SENDSTR[3] = lx % 100 / 10 + '0';
        SENDSTR[4] = lx % 10 + '0';
        SENDSTR[5] = 0;
        Print_Str (SENDSTR);                   //原始数据
        Print_Str("\r\n");
        delay_ms(200);
    }
}
cpp展开代码https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2


本文作者:Dong
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!