本文主要是介绍【TB作品】MSP430F149,ADC采集,光强GY-30,DS18B20温度采集,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
功能
读取了GY-30 DS18B20 P6.0ADC P6.1ADC
显示到了LCD12864
硬件
//GY30
//SCL–P1.0
//SDA–P1.1
//VCC–3.3V
//GND–GND
//ADDR–不接
//DS18B20
//DATA–P1.6
//VCC–3.3V
//GND–GND
//ADC
//DATA–P1.6
//P6.0 P6.1 ADC输入口
部分程序
#include <msp430.h>
#include "lcd12864.h"
#include "gy30.h"unsigned int temp_value = 0; /* 温度 */
unsigned int ADCresults[2]; //ADC结果
unsigned char dis[15]; //显示数组
float lx; //光强//***********************************************************************
// 系统时钟初始化,外部8M晶振
//***********************************************************************
void Clock_Init(void)
{unsigned char i;BCSCTL1 &= ~XT2OFF; //打开XT2振荡器BCSCTL2 |= SELM1 + SELS; //MCLK为8MHZ,SMCLK为8MHZdo{IFG1 &= ~OFIFG; //清楚振荡器错误标志for (i = 0; i < 100; i++)_NOP();}while ((IFG1 & OFIFG) != 0); //如果标志位1,则继续循环等待IFG1 &= ~OFIFG;
}void main(void)
{WDTCTL = WDTPW | WDTHOLD; // stop watchdog timerClock_Init();LCD_init();initADC();_EINT();while (1){ADC12CTL0 |= ADC12SC; // Start conversionLPM0;temp_value = get_one_temperature(); //读取温度dis[0] = temp_value % 1000 / 100 + '0';dis[1] = temp_value % 100 / 10 + '0';dis[2] = '.';dis[3] = temp_value % 10 + '0';dis[4] = 'C';dis[5] = 0;DisplayCgrom(0x80, dis); //第一行显示lx = get_lightpower(); //读取光强dis[0] = (int) lx % 100000 / 10000 + '0';dis[1] = (int) lx % 10000 / 1000 + '0';dis[2] = (int) lx % 1000 / 100 + '0';dis[3] = (int) lx % 100 / 10 + '0';dis[4] = (int) lx % 10 + '0';dis[5] = 'L';dis[6] = 'x';dis[7] = 0;DisplayCgrom(0x90, dis); //第2行显示dis[0] = 'A';dis[1] = 'D';dis[2] = '0';dis[3] = ':';dis[4] = (int) ADCresults[0] % 10000 / 1000 + '0';dis[5] = (int) ADCresults[0] % 1000 / 100 + '0';dis[6] = (int) ADCresults[0] % 100 / 10 + '0';dis[7] = (int) ADCresults[0] % 10 + '0';dis[8] = 0;DisplayCgrom(0x88, dis); //第3行显示dis[0] = 'A';dis[1] = 'D';dis[2] = '1';dis[3] = ':';dis[4] = (int) ADCresults[1] % 10000 / 1000 + '0';dis[5] = (int) ADCresults[1] % 1000 / 100 + '0';dis[6] = (int) ADCresults[1] % 100 / 10 + '0';dis[7] = (int) ADCresults[1] % 10 + '0';dis[8] = 0;DisplayCgrom(0x98, dis); //第4行显示}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{ADCresults[0] = ADC12MEM0; // Move A0 results, IFG is clearedADCresults[1] = ADC12MEM1; // Move A1 results, IFG is clearedLPM0_EXIT;
}
全部程序
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
这篇关于【TB作品】MSP430F149,ADC采集,光强GY-30,DS18B20温度采集的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!