int main(void)
{
u8 XYZ_Value[3];
u8 temp;
LED_Init();
USART1_Init();
I2C1_Configuration();
MMA7455_Init();
NVIC_Configuration();
//读取MMA7455的IIC器件地址,应为0x1D,0x1D<<1 即为0x3A(发送时的数据),请注意。
MMA7455_BufferRead(&temp, I2CAD, 1);
if((temp&0x7F) == 0x1D)
{
GPIO_SetBits(LED_PORT , LED1);
}else
{
GPIO_SetBits(LED_PORT , LED2);
}
printf(" IIC Device Address = 0x%x\r\n",temp); //16进制显示
delayms(1000);
temp = 0;
while(1)
{
//轮流点亮LED1和LED2
if(temp%2)
{
GPIO_SetBits(LED_PORT , LED2);
GPIO_ResetBits(LED_PORT , LED1);
}else
{
GPIO_SetBits(LED_PORT , LED1);
GPIO_ResetBits(LED_PORT , LED2);
}
//直接显示16进制的三轴加速度值,因为没有经过校准,此数据不具备精确参考价值,因此没有转换成对应的g值
MMA7455_BufferRead(XYZ_Value,XOUT8,3); //读取XYZ三轴加速度值,8位
printf(" X = 0x%x\r\n",XYZ_Value[0]); //16进制显示
printf(" Y = 0x%x\r\n",XYZ_Value[1]); //16进制显示
printf(" Z = 0x%x\r\n",XYZ_Value[2]); //16进制显示
delayms(1000);
temp++;
if(temp>10)
{
temp=1;
}
}
}
代码演示
最新推荐文章于 2023-06-20 15:09:43 发布