msp430单片机模拟IIC总线读取MMA7660三轴加速度传感器
代码如下:
file1 : main.c
#include "msp430G2452.h"
#include "g2452uart.h"
#include "MMA7660FC.h"
#define SDA_DirOut
#define SDA_DirIn
#define SDA_0
#define SDA_1
#define SCL_1
#define SCL_0
#define Get_Bit( x,y) #define SDA_in void OSC_Init() { WDTCTL=WDTPW+WDTHOLD;//close whatchdog if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) //1Mhz } P2DIR |= BIT0+BIT1; SDA_1; SCL_1; while(k--) _nop(); SDA_1; SCL_1; delay_us(5); SDA_0; delay_us(5); SCL_0; SCL_1; SDA_0; delay_us(5); SDA_1; delay_us(5); SDA_0; SCL_1; delay_us(5); SCL_0; delay_us(5); SCL_1; delay_us(5); SCL_0; delay_us(5); unsigned char CY ; SDA_DirIn; void IIC_WriteByte(unsigned int { delay_us(5); SCL_0; delay_us (5); } unsigned char { unsigned char i ,data=0; SDA_DirIn; for (i=0;i<8;i++) { SCL_0; delay_us(5); SCL_1 ; data<=1; data|=SDA_in; delay_us(3); } SDA_DirOut; return data; } void WriteToAddr(unsigned char REG_addr, unsigned char REG_data ) { IIC_Start(); } { } void MMA7660_Init() { WriteToAddr(MMA7660_MODE,0x01); } void Read3axle(void) { X_value=ReadFromAddr(X_outAddr); Y_value=ReadFromAddr(Y_outAddr); Z_value=ReadFromAddr(X_outAddr); //将采集到的数据转换到-32~31之间 } //-----------主函数----------------------------------------------------------- void main(void) { OSC_Init(); Port_Init(); TimerA_UART_init(); MMA7660_Init(); __enable_interrupt(); TimerA_UART_print("All Initialization is OK!rn"); for (;;) { //__bis_SR_register(LPM0_bits); Read3axle(); if (X_value_final>0) P1OUT|= BIT0; else
msp430单片机模拟IIC总线MMA7660三轴加速度传感 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)