功能
读取了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为8MHZ
do
{
IFG1 &= ~OFIFG; //清楚振荡器错误标志
for (i = 0; i < 100; i++)
_NOP();
}
while ((IFG1 & OFIFG) != 0); //如果标志位1,则继续循环等待
IFG1 &= ~OFIFG;
}
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
Clock_Init();
LCD_init();
initADC();
_EINT();
while (1)
{
ADC12CTL0 |= ADC12SC; // Start conversion
LPM0;
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 cleared
ADCresults[1] = ADC12MEM1; // Move A1 results, IFG is cleared
LPM0_EXIT;
}
全部程序
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2