文章目录
实物
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