freedomhit

利用单片机计算复杂运算——算法优化

最近在用ADI单片机ADuC7026做一个程序,程序中涉及到大量的计算,以及数据的不断更新。利用中断10毫秒,然后对采集的数据进行结算,因为涉及到了正弦、余弦、正切、反余弦、反正切、大量的除法计算,这就不能保证在这个中断10毫秒之内完成这些计算,从而不能实现功能。

利用ADuC7026,ADXL345通讯主程序

#include#include"XL345.h"#include"Common.h"voiddelay(inti){while(i)i--;}voidputchar(unsignedcharch)/*WritecharactertoSerialPort*/{COMTX=ch;//COMTXisan8-bittransmitregister.while(!(0x020==(COMSTA0&0x020))){;}}voidIRQ_Hand

12864和ADuC7026显示配置

#ifndef__OCM12864#define__OCM12864//#include"../main.h"typedefunsignedcharuchar;typedefunsignedintuint;/****#definelcddata_outP3OUT#definelcddata_inP3IN#defineLCD_DOUT_ENP3DIR=0XFF#defineLCD_DIN_ENP3DIR=0x00#defineset_rs()(P2DIR|=BIT0

计步器主函数

#include"main.h"#include"IIC.h"intValueX,ValueY,ValueZ;intXAPP,YAPP,ZAPP;intXavarage,Yavarage,Zavarage;ucharputA0[6],putA1[6],putB0[6],putB1[6],putC0[6],putC1[6],putz[6];//将计算所的的整形数转变成字符数组以便在液晶输出voidco

计步器通讯程序

#include#include"IIC.h"#include"OCM12864.h"#defineslave0xA6#definetime10000#definecount5//读取字节数=count+1;inti;unsignedcharAspeed[6];//从ADXL345寄存器中读出来的6个值组成的数组externunsignedintValueX,ValueY,ValueZ;//对取

I2C从机程序

#includevoidIRQ_Handler()__irq;inti=0,dat[9];intmain(){//I2ConP1.0andP1.1GP1CON=0x22;IRQEN=0x200;//I2C0SlaveInteruptI2C0CFG=0x01;//SlaveEnableI2C0ID0=0xA0;//SlaveIDI2C0STX=0x77;while(1){};return0;}voidIRQ_Handler()__irq{//SlaveRecieveif((I2C0SS

I2C主机程序

#includevoiddelay(int);voidIRQ_Handler()__irq;#definecount0x4;//Numberofbytestoberecieved-1inti=0,dat[5];//Sizeofdatshouldbe(count+1)intmain(){GP1CON=0x22;//I2ConP1.0andP1.1I2C0CFG=0x82;//MasterEnable&EnableGenerationofMasterClock//I2C-Mast

SPI从机程序

#includevoidIRQ_Handler(void)__irq;//IRQFuntionPrototypechari;charreceived_data[30];intmain(void){GP4DAT=0x04000000;//P4.2configuredasanoutput.LEDisturnedonIRQEN=SPI_SLAVE_BIT;GP1CON=0x22220000;//configureSPIonSPMSPICON=0x1409;//enableSPIslavem

SPI主机程序

#includevoidIRQ_Handler(void)__irq;//IRQFuntionPrototypeinti=0;intmain(void){GP4DAT=0x04000000;//P4.2configuredasanoutput.LEDisturnedonIRQEN=SPI_MASTER_BIT;GP1CON=0x22220000;//configureSPIonSPMSPIDIV=0xCC;//setSPIclock40960000/(2x(1+SPIDIV))//0

7026uart接口

ADI公司在夏令营中要用到数据传输的实验,那我就把一些7026关于数据传输的程序写给大家看看吧#include#defineCR0x0Dintputchar(intch);chargetchar2(void);intwrite(char*ptr,intlen);charoutput1[65];intmain(void){unsignedcharjchar=0x30;inti;GP1CON=0x011;CO