ADXL345直接输出角度值C51程序(国外英文资料).doc
文本预览下载声明
ADXL345直接输出角度值C51程序(国外英文资料)
, * * * * * * * * * *
/ / GY - 29 ADXL345 IIC test program
/ / use STC89C51
/ / vibrate: 11.0592 M
/ / display: LCD1602
/ / compile environment Keil uVision2
/ / reference macros 24c04 communication program
/ / time: March 1, 2011
/ / QQ: 531389319
* * * * * * * * *
# include reg5.h
Include math.h / / Keil library
Include stdio. H / / Keil library
# include INTRINS. H
# define uchar unsigned char
Pound sign define uint unsigned int
# define DataPort P0 / / LCD1602 data port
Sbit SCL P1 = ^ 0; / / IIC clock is defined
Sbit SDA P1 = ^ 1; / / IIC data pins definition
Sbit LCM_RS = P2 ^ 0; / / LCD1602 command port
Sbit LCM_RW = P2 ^ 1; / / LCD1602 command port
Sbit LCM_EN = P2 ^ 2; / / LCD1602 command port
The # define SlaveAddress 0xA6 / / defines the ADDRESS in the IIC bus, which is modified by ALT ADDRESS ADDRESS
/ / ALT ADDRESS the ADDRESS is 0xA6 when the ground is ground, and the ADDRESS is 0x3A when the power is plugged in
Typedef unsigned char BYTE;
Typedef unsigned short WORD;
BYTE BUF [8]. / / receive the data cache area
Uchar ge, shi, bai, qian, wan; / / display variable
Int dis_data; / / variable
Int data_xyz [3];
Void delay (unsigned int k);
Void InitLcd (); / / initializes the lcd1602
Void Init_ADXL345 (void); / / initialize ADXL345
Void WriteDataLCM (uchar dataW);
Void WriteCommandLCM (uchar CMD, uchar Attribc);
Void DisplayOneChar (uchar X, uchar Y, uchar DData);
Void conversion (uint temp_data);
Void Single_Write_ADXL345 (uchar REG_Address, uchar REG_data); / / a single write data
Uchar Single_Read_ADXL345 (uchar REG_Address); / / a single reading of internal register data
Void Multiple_Read_ADXL345 (); / / continuously read internal register data
I dont know what Im going to do
Void Delay5us ();
Void Delay5ms ();
Void ADXL345_Start ();
Void ADXL345_Stop ();
Void ADXL345_SendACK (bit ack);
Bit ADXL345_RecvACK ()
Void ADXL345_SendByte (BYTE dat);
BYTE ADXL345_RecvByte ();
Void ADXL345_ReadPage ();
Void ADXL345_WritePag
显示全部