打印

关于c语言与处理头文件

[复制链接]
1983|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ke2525|  楼主 | 2011-10-20 13:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
预处理头文件有错是什么情况?
如下面代码:
/*-----------------------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
    }
   }
  }
}
}

相关帖子

沙发
yewuyi| | 2011-10-20 13:35 | 只看该作者
哎。。。

建议你别忙写代码,先去学习一下C语言和编译、连接等的基础知识。

使用特权

评论回复
板凳
dong_abc| | 2011-10-20 14:05 | 只看该作者
顶LS

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

1

粉丝