本文主要是介绍【TB作品】msp430g2553单片机,读取GY-30光强,串口发送,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
硬件
//GY-30
//SCL–P1.4
//SDA–P1.5
//VCC–3.3V
//GND–GND
//ADDR–不接
部分程序
#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 settingsBCSCTL1 = CALBC1_1MHZ; // Set rangeDCOCTL = 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);}
}
全部程序
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
这篇关于【TB作品】msp430g2553单片机,读取GY-30光强,串口发送的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!