【TB作品】MSP430单片机读取大气压强传感器BMP180

文章目录

实物

main

csharp 复制代码
#include <msp430.h>
#include "stdio.h"
#include "OLED.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// P2.2 oled scl
// P2.3 oled sda

// p1.0 bmp180 scl
// p1.1 bmp180 sda
// vcc 3.3v
// gnd gnd

#include "bmp180.h"

unsigned char disp[16];
unsigned char cnt = 0;


int main(void) {
    uchar test = 0;
    WDTCTL = WDTPW + WDTHOLD;
    if (CALBC1_8MHZ == 0xFF) {
        while (1);
    }
    DCOCTL = 0;
    BCSCTL1 = CALBC1_8MHZ;
    DCOCTL = CALDCO_8MHZ;


    OLED_Init();

    delay_ms(400);

    OLED_Init();

    BMP085_IIC_IOinit;
    delay_ms(50);                           //上电延时
    Init_BMP085();                //初始化BMP085

    test = Single_Read(0xd0);

    _EINT();
    while (1) {
        bmp085Convert();
        OLED_ShowString(0, 0, "BMP180:", 0);
        if (temperature >= 0) { //不满足这个条件的话,说明是负数,有可能是干扰
            cnt = 0;
            disp[cnt++] = temperature % 1000000 / 100000 + '0';
            disp[cnt++] = temperature % 100000 / 10000 + '0';
            disp[cnt++] = temperature % 10000 / 1000 + '0';
            disp[cnt++] = temperature % 1000 / 100 + '0';
            disp[cnt++] = temperature % 100 / 10 + '0';
            disp[cnt++] = temperature % 10 + '0';
            disp[cnt++] = 'C';
            disp[cnt++] = 0;
            OLED_ShowString(0, 2, disp, 0);
            cnt = 0;
            disp[cnt++] = pressure % 10000000 / 1000000 + '0';
            disp[cnt++] = pressure % 1000000 / 100000 + '0';
            disp[cnt++] = pressure % 100000 / 10000 + '0';
            disp[cnt++] = pressure % 10000 / 1000 + '0';
            disp[cnt++] = pressure % 1000 / 100 + '0';
            disp[cnt++] = pressure % 100 / 10 + '0';
            disp[cnt++] = pressure % 10 + '0';
            disp[cnt++] = 'P';
            disp[cnt++] = 'a';
            disp[cnt++] = 0;
            OLED_ShowString(0, 4, disp, 0);
        }
        delay_ms(200);
        delay_ms(200);
        delay_ms(200);
        delay_ms(200);
        delay_ms(200);
    }
}

所有代码

这里获取:

csharp 复制代码
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
相关推荐
国科安芯7 小时前
抗辐照MCU在精密时频系统中的单粒子效应评估与可靠性验证
单片机·嵌入式硬件·架构·制造·安全性测试
czhaii8 小时前
单片机最佳入门多线程示例讲解
c语言·单片机
BackCatK Chen17 小时前
第 8 篇:TMC2240 电机正反转实现|DIR 引脚控制 + 代码优化(稳定不抖动)
stm32·单片机·嵌入式硬件·保姆级教程·电机正反转·tmc2240·dir引脚控制
星马梦缘18 小时前
EDA彩灯电路绘制
单片机·嵌入式硬件·物联网·pcb·eda·嘉立创
Forsete20 小时前
LINUX驱动开发#9——定时器
linux·驱动开发·单片机
Hello_Embed1 天前
libmodbus 移植 STM32(USB 串口后端篇)
笔记·stm32·单片机·嵌入式·freertos·libmodbus
来自晴朗的明天1 天前
14、光耦隔离电路(EL3H7)
单片机·嵌入式硬件·硬件工程
G***技1 天前
杰和IB3-272:以低功耗高性能打造新一代工业智能交互核心
单片机·嵌入式硬件·物联网
czhaii1 天前
STC AI8052U单片机特点
单片机
MAR-Sky1 天前
keil5中数据的不同定义和单片机(以stc8为例)里的对应关系(idata,xdata,data,code)
单片机·嵌入式硬件