预处理头文件有错是什么情况?
如下面代码:
/*-----------------------ADI Show Three Axis Acceleration Reference Design Source Code--------------------
Author: ADI CAST (China Application Support Team)
Date: 2008-02-18
Rev: V1.2
Description: Realize Show Three Axis Acceleration Algorithm,Use ADuC7026 as MCU,
Use ADXL345 as Acceleration Sensor,Development Tool: KEIL C
---------------------------------------------------------------------------------------------------------*/
#include <ADuC7026.h>
#include "XL345.h"
#include "XL345_IO.h"
//Three Axis Acceleration Flag
#define X_CHANNEL 0
#define Y_CHANNEL 1
#define Z_CHANNEL 2
unsigned char IsStart = 0; //Start Flag
unsigned char iTemp = 0; //Temp Variable
unsigned char Calculate_Sign = 0; //Flag for Data Ready
unsigned int Acceleration[3] = {0,0,0}; //Three Axis Acceleration Value
//Reigster for ADXL345
unsigned char DataX_High, DataX_Low; //High Byte and Low Byte of Data Register for X
unsigned char DataY_High, DataY_Low; //High Byte and Low Byte of Data Register for Y
unsigned char DataZ_High, DataZ_Low; //High Byte and Low Byte of Data Register for Z
unsigned char INT_Source, Dev_ID; //Register for Interrupt Source and Device ID
unsigned char UartDataReceived; //Received Data
unsigned char UartInterrupt; //Interrupt Status
union{unsigned int ui;unsigned char uc[4];}un;
unsigned char buf[8];
void putchar(unsigned char ch)/* Write character to Serial Port */
{
COMTX = ch; //COMTX is an 8-bit transmit register.
while(!(0x020==(COMSTA0 & 0x020)))
{;}
}
void IRQ_Handler() __irq
{
if(0 != (IRQSTA & SPM5_IO_BIT)) //External IRQ3 (IRQ3->INT2 pin of ADXL345)
{
Calculate_Sign = 1; //Set flag
xl345Read(6, XL345_DATAX0, buf); //Read DATAX/Y/Z registers
DataX_Low = buf[0];
DataX_High = buf[1];
DataX_High &= 0x1F;
DataY_Low = buf[2];
DataY_High = buf[3];
DataY_High &= 0x1F;
DataZ_Low = buf[4];
DataZ_High = buf[5];
DataZ_High &= 0x1F;
}
else if(0 != (IRQSTA & UART_BIT)) //UART Interrupt
{
UartInterrupt = COMIID0 ;
if(0x04 == UartInterrupt) //Has Received a Data
{
UartDataReceived = COMRX; //Get Received Data
if(0xAA == UartDataReceived) //Test Communication By Sending Device ID
{
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = Dev_ID; //COMTX is an 8-bit Transmit Register.
}
if(0x55 == UartDataReceived) //Start Command
{
IsStart = 0x01;
}
if(0xA5 == UartDataReceived) //Stop Command
{
IsStart = 0x00;
}
}
}
}
void ADuC7026_Initiate(void)
{
//Clock Initial
POWKEY1 = 0x01; //Start PLL Setting
POWCON = 0x00; //Set PLL Active Mode With CD = 0 CPU CLOCK DIVIDER = 41.78MHz
POWKEY2 = 0xF4; //Finish PLL Setting
GP1CON = 0x00002211; //PIN set up for I2C and UART
GP2DAT = GP2DAT | 0x04040000; //Disable LCD;
GP0DAT = GP0DAT | 0x02020000; //Disable LED;
GP4DAT = GP4DAT | 0x01000000; //Grouding the SDO, I2C address for writing and reading is 0xA6 and 0xA7
// GP4DAT = GP4DAT | 0x01010000; //Highing the SDO, I2C address for writing and reading is 0x3A and 0x3B
//UART Initial,Baud Rate = 9600
COMCON0 = 0x080;
COMDIV0 = 0x088;
COMDIV1 = 0x000;
COMCON0 = 0x007;
//I2C Initial
I2C1CFG = 0x00000082; // Master Enable & Enable Generation of Master Clock
I2C1DIV = 0x3232; // 0x3232 = 400kHz 0xCFCF = 100kHz
//Interrupt Set Up
FIQEN = SM_MASTER1_BIT; //I2C1 Master Interrupt
}
//ADXL345 initialization, register configuration
void ADXL345_Initiate()
{
/* buf[0] = 0xFF;//OFSX offer offset adjustments in twos compliment form with a scale factor of 15.6 mg/LSB
xl345Write(1, XL345_OFSX, buf);
buf[0] = 0xFF;//OFSY offer offset adjustments in twos compliment form with a scale factor of 15.6 mg/LSB
xl345Write(1, XL345_OFSY, buf);*/
/*
buf[0] = 0x0D;//OFSZ offer offset adjustments in twos compliment form with a scale factor of 15.6 mg/LSB
xl345Write(1, XL345_OFSZ, buf);
*/
buf[0] = XL345_RATE_50; //Output Data Rate: 50Hz
xl345Write(1, XL345_BW_RATE, buf);
buf[0] = XL345_FULL_RESOLUTION | XL345_RANGE_16G;//Data Format: +/-16g range, right justified, 256->1g
xl345Write(1, XL345_DATA_FORMAT, buf);
buf[0] = XL345_DATAREADY; //INT_Enable: Data Ready
xl345Write(1, XL345_INT_ENABLE, buf);
buf[0] = XL345_DATAREADY; //INT_Map: Data Ready interrupt to the INT2 pin
xl345Write(1, XL345_INT_MAP, buf);
}
void main(void)
{
ADuC7026_Initiate(); //ADuC7026 Initialization
ADXL345_Initiate(); //ADXL345 Initialization
IsStart = 0x00; //Variables initialization
xl345Read(1,XL345_DEVID,buf); //Get Device ID
Dev_ID = buf[0];
COMIEN0 = 0x01; //Enable Receive Buffer Full Interrupt
IRQEN = UART_BIT | SPM5_IO_BIT; //Enable UART and IRQ3 Interrupt (IRQ3->INT2 pin of ADXL345)
buf[0] = XL345_MEASURE; //Power CTL: Measure mode
xl345Write(1, XL345_POWER_CTL, buf);
while(1)
{
if(0x01 == IsStart) // Start
{
if(1 == Calculate_Sign)
{
Calculate_Sign = 0;
Acceleration[X_CHANNEL] = DataX_High;
Acceleration[X_CHANNEL] = (Acceleration[X_CHANNEL]<<8) | DataX_Low;
Acceleration[Y_CHANNEL] = DataY_High;
Acceleration[Y_CHANNEL] = (Acceleration[Y_CHANNEL]<<8) | DataY_Low;
Acceleration[Z_CHANNEL] = DataZ_High;
Acceleration[Z_CHANNEL] = (Acceleration[Z_CHANNEL]<<8) | DataZ_Low;
//Translate the twos complement to true binary code (256+4096)->1g, (4096-256)->(-1)g
for(iTemp=X_CHANNEL;iTemp<=Z_CHANNEL;iTemp++)
{
if(Acceleration[iTemp] < 4096)
{
Acceleration[iTemp] = Acceleration[iTemp] + 4096;
}
else if(Acceleration[iTemp] >= 4096)
{
Acceleration[iTemp] = Acceleration[iTemp] - 4096;
}
un.ui = Acceleration[iTemp];
putchar(un.uc[1]);//High Bit
putchar(un.uc[0]);//Low bit
}
}
}
}
} |