微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > msp430单片机模拟IIC总线读取MMA7660三轴加速度传感器

msp430单片机模拟IIC总线读取MMA7660三轴加速度传感器

时间:11-27 来源:互联网 点击:

if (X_value_final>

TimerA_UART_print("X_value---->

TimerA_UART_print("Z_value---->

----------------------------------------------------------

void TimerA_UART_print(char *string)

{

while (*string) {

TimerA_UART_tx(*string++);

}

}

void output(unsigned int num , int n )

{

char *p,pd[4];

p=pd;

pd[0]=num/1000 +48 ; //千位

pd[1]=num/100 +48 ;// 百位

pd[2]=num0/10 +48 ; //十位

pd[3]=num +48;//个位

while (n--)

TimerA_UART_tx((*p++));

}

//------------------------------------------------------------------------------

// Timer_A UART - Transmit Interrupt Handler

//------------------------------------------------------------------------------

#pragma vector = TIMER0_A0_VECTOR

__interrupt void Timer_A0_ISR(void)

{

static unsigned char txBitCnt = 10;

TACCR0 += UART_TBIT; // Add Offset to CCRx

if (txBitCnt == 0) { // All bits TXed?

TACCTL0 &= ~CCIE; // All bits TXed, disable interrupt

txBitCnt = 10; // Re-load bit counter

}

else {

if (txData & 0x01) {

TACCTL0 &= ~OUTMOD2; // TX Mark 1

}

else {

TACCTL0 |= OUTMOD2; // TX Space 0

}

txData >>= 1;

txBitCnt--;

}

}

//------------------------------------------------------------------------------

// Timer_A UART - Receive Interrupt Handler

//------------------------------------------------------------------------------

#pragma vector = TIMER0_A1_VECTOR

__interrupt void Timer_A1_ISR(void)

{

static unsigned char rxBitCnt = 8;

static unsigned char rxData = 0;

switch (__even_in_range(TA0IV, TA0IV_TAIFG)) { // Use calculated branching

case TA0IV_TACCR1: // TACCR1 CCIFG - UART RX

TACCR1 += UART_TBIT; // Add Offset to CCRx

if (TACCTL1 & CAP) { // Capture mode = start bit edge

TACCTL1 &= ~CAP; // Switch capture to compare mode

TACCR1 += UART_TBIT_div_2; // Point CCRx to middle of D0

}

else {

rxData >>= 1;

if (TACCTL1 & SCCI) { // Get bit waiting in receive latch

rxData |= 0x80;

}

rxBitCnt--;

if (rxBitCnt == 0) { // All bits RXed?

rxBuffer = rxData; // Store in global variable

rxBitCnt = 8; // Re-load bit counter

TACCTL1 |= CAP; // Switch compare to capture mode

//__bic_SR_register_on_exit(LPM0_bits); // Clear LPM0 bits from 0(SR)

}

}

break;

}

}

//----------------------华丽的分割线2--------------------------------------------------------

//file :MMA7660FC.h

#ifndef _MMA7660FC_H

#define _MMA7660FC_H

#define MMA7660FC_ADD 0x4C //Please contact the factory to request a different IIC address

#define MMA7660FC_MW_ADD 0x98 //master write address

#define MMA7660FC_MR_ADD 0x99 //master read address

#define SlaveAddress 0x98 //从机地址

#define X_outAddr 0x00

#define Y_outAddr 0x01

#define Z_outAddr 0x02

// IIC Register Address

#define MMA7660_XOUT 0x00

#define MMA7660_YOUT 0x01

#define MMA7660_ZOUT 0x02

#define MMA7660_TILT 0x03

#define MMA7660_SRST 0x04

#define MMA7660_SPCNT 0x05

#define MMA7660_INTSU 0x06

#define MMA7660_MODE 0x07

#define MMA7660_SR 0x08

#define MMA7660_PDET 0x09

#define MMA7660_PD 0x0A

#endif

////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\

//以上为所有程序源码!编译工具CCS V5.0

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top