【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
相关推荐
FreakStudio10 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
✎ ﹏梦醒͜ღ҉繁华落℘16 天前
单片机基础知识---stm32单片机的优先级
stm32·单片机·mongodb
zd84510150016 天前
RS485 总线详解
单片机·嵌入式硬件
✎ ﹏梦醒͜ღ҉繁华落℘16 天前
编程基础 --高内聚,低耦合
c语言·单片机
科芯创展16 天前
1A,1MHz,30VIN,XZ4115,降压恒流LED驱动芯片
单片机·嵌入式硬件
集芯微电科技有限公司16 天前
四通道2A输出集成功率电感降压模块专为紧凑型方案设计
人工智能·单片机·嵌入式硬件·生成对抗网络·计算机外设
踏着七彩祥云的小丑16 天前
嵌入式测试学习第 37 天:异常场景测试:断电、拔插、干扰、非法指令
单片机·嵌入式硬件·学习
意法半导体STM3216 天前
【官方原创】如何为STM32CubeMX2配置Visual Studio Code配置方案
vscode·stm32·单片机·嵌入式硬件·策略模式·stm32cubemx·嵌入式开发
雾削木16 天前
B语言经典教程现代化重构
java·前端·stm32·单片机·嵌入式硬件
Hello-FPGA16 天前
Camera Link 与 CoaXPress 技术对比 如何选择你的相机接口
单片机·嵌入式硬件