/* *********************** BMP085******************************* */
// 调试环境:时钟为DCO的时钟;频率4.00MHz
// 串行接口:P2.6 ------>SDA
// P2.7 ------>SCL
// P3.0 ------>wp256
// P3.0 ------>wpc02
// 测试器件:ATMEL AT24C256
// 测试时间:2004-12-06
//
/* *********************************************************************** */
#include"msp430x43x.h"
//#include "print.h"
#define SDA_IN P4DIR &=~BIT5 // P2.6 IN
#define SDA_OUT P4DIR |= BIT5 // P2.6 OUT
#define SDA_LOW P4OUT &=~BIT5 // sda=0
#define SDA_HIGH P4OUT |= BIT5 // sda=1
#define SCL_IN P4DIR &=~BIT3 // P2.7 IN
#define SCL_OUT P4DIR |= BIT3 // P2.7 OUT
#define SCL_LOW P4OUT &=~BIT3
#define SCL_HIGH P4OUT |= BIT3
#define XCLR_IN P4DIR &=~BIT6 // P2.7 IN
#define XCLR_OUT P4DIR |= BIT6 // P2.7 OUT
#define XCLR_LOW P4OUT &=~BIT6
#define XCLR_HIGH P4OUT |= BIT6
#define WP256_LOW P3OUT &=~BIT0 // P3.0
#define WP256_HIGH P3OUT |= BIT0 // P3.0
#define WPC02_LOW P3OUT &=~BIT0
#define WPC02_HIGH P3OUT |= BIT0
unsigned char DATA_R,DATA_R1;
//#define REC_DATA P2IN&BIT5
void delay(unsigned int m)
{
while(m--);
}
void IIC_START (void)
{ SDA_OUT;
SDA_HIGH;
SCL_HIGH;
delay(5);
SDA_LOW;
delay(5);
SCL_LOW;
delay(5);
}
void IIC_RESTART (void)
{ SDA_OUT;
SDA_HIGH;
SCL_HIGH;
delay(1);
SDA_LOW;
delay(1);
SCL_LOW;
delay(1);
}
void IIC_STOP (void)
{ SDA_OUT;
SDA_LOW;
delay(1);
SCL_HIGH;
delay(1);
SDA_HIGH;
delay(1);
}
void IIC_ACK (void)
{ SDA_OUT;
SDA_LOW;
delay(1);
SCL_HIGH;
delay(1);
SCL_LOW;
delay(1);
}
void IIC_TX_DATA (unsigned char DATA)
{ unsigned char Rn=8,RR=0x80;
SDA_OUT;
delay(5);
for (;Rn!=0;Rn--)
{
if ((DATA&RR)!=0)
SDA_HIGH;
else
SDA_LOW;
delay(5);
SCL_HIGH;
delay(5);
SCL_LOW;
delay(5);
RR>>=1;
}
/*SDA_HIGH;
delay(5);
SCL_HIGH;
delay(5);
SCL_LOW;
delay(5);*/
}
unsigned char IIC_RX_DATA (void)
{unsigned int Rn=8,DATA=0,RR=0x80;
SDA_IN; // 端口为输入
delay(5);
for (;Rn!=0;Rn--)
{
SCL_HIGH;
delay(5);
if ((P4IN&BIT5)!=0)
DATA|=RR;
else
DATA&=~RR;
RR>>=1;
SCL_LOW;
delay(5);
}
return DATA;
}
unsigned char READC256N_BYTE ()
{ /*XCLR_OUT;
XCLR_HIGH;
XCLR_LOW;
delay(1);
XCLR_HIGH;
*/
IIC_START ();
IIC_TX_DATA (0xEE);
IIC_ACK ();
IIC_TX_DATA (0xF4);
IIC_ACK ();
IIC_TX_DATA (0x2E);
IIC_ACK ();
IIC_STOP ();
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
IIC_START ();
IIC_TX_DATA (0xEE);
IIC_ACK ();
IIC_TX_DATA (0xF6);
IIC_ACK ();
IIC_RESTART ();
IIC_TX_DATA (0xEF);
IIC_ACK ();
DATA_R=IIC_RX_DATA();
IIC_ACK ();
DATA_R1=IIC_RX_DATA();
IIC_ACK ();
IIC_STOP ();
IIC_TX_DATA (0xEE);
IIC_ACK ();
IIC_TX_DATA (0xF4);
IIC_ACK ();
IIC_TX_DATA (0x34);
IIC_ACK ();
IIC_STOP ();
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
delay(10000);
IIC_START ();
IIC_TX_DATA (0xEE);
IIC_ACK ();
IIC_TX_DATA (0xF6);
IIC_ACK ();
IIC_RESTART ();
IIC_TX_DATA (0xEF);
IIC_ACK ();
DATA_R=IIC_RX_DATA();
IIC_ACK ();
DATA_R1=IIC_RX_DATA();
IIC_ACK ();
IIC_STOP ();
return DATA_R;
} |