mbed开发指南


1 新建工程文件夹,作为工作目录
2 进入工程文件夹,运行
mbed new .
3 设定目标板
mbed target NUCLEO_WB55RG
4 设定编译器
mbed toolchain GCC_ARM
5 创建程序main.cpp
6 编译并下载
mbed compile --flash 

案例1:
#include <mbed.h>

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);

int main() {
  int i = 1;
  pc.printf("Hello World !\n");
  while(1) {
      wait(1);
      pc.printf("Hello MyWorld !\n");
      wait(1);
      pc.printf("This program runs since %d seconds.\n", i++);
      myled = !myled;
  }
}


案例2:

#include "mbed.h"
 
I2C i2c(I2C_SDA , I2C_SCL ); 
Serial pc(USBTX, USBRX); // tx, rx
 
const int addr =0x76 <<1 ;// define the correct I2C Address     寄存器地址
 
int main() 
{
    char regaddr[1];
    char readdata[8]; // room for length and 7 databytes    
    char writedata[9]; // room for reg address, length and 7 databytes
    while (1) 
    {
        //write ......     写操作
        regaddr[0] = 0xF4;        
        writedata[0] = regaddr[0];  // register address
        writedata[1] = 0x15; // data
        writedata[2] = 1; // length of data

        // write the data
        i2c.write(addr, writedata, 3); // select the register, 
                                       // write the length, write 1 databytes      
        wait(1);    
        
        // read ....  读操作
        regaddr[0] = 0xF4;
        i2c.write(addr, regaddr, 1, false);  // select the register, no I2C Stop
        i2c.read(addr, readdata, 8);        // read the length byte and the 8 databytes
        
        wait (1);
 
        // print the data to the screen
        pc.printf("Register 0x%x =  0x%x  0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\r\n",
                  regaddr[0],
                  readdata[0],readdata[1], readdata[2], readdata[3], readdata[4],
                  readdata[5], readdata[6], readdata[7] );
        wait(1);        
    

    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值