/***********************************************************************************************\
* Freescale MMA8451,2,3Q Driver
*
* Filename: terminal.c
*
*
* (c) Copyright 2010, Freescale, Inc. All rights reserved.
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor.
*
\***********************************************************************************************/
#include "system.h"
/***********************************************************************************************\
* Private macros
\***********************************************************************************************/
/***********************************************************************************************\
* Private type definitions
\***********************************************************************************************/
/***********************************************************************************************\
* Private prototypes
\***********************************************************************************************/
byte ProcessHexInput (byte *in, byte *out);
void CopyXYZ (byte *ptr);
void CopyXYZ8 (byte *ptr);
void PrintXYZdec14 (void);
void PrintXYZdec12 (void);
void PrintXYZdec10(void);
void PrintXYZdec8 (void);
void PrintXYZfrac (void);
void ClearDataFlash (void);
void PrintBuffering (void);
void PrintFIFO (void);
void ReadDataFlashXYZ (void);
void WriteFlashBuffer (void);
/***********************************************************************************************\
* Private memory declarations
\***********************************************************************************************/
#pragma DATA_SEG __SHORT_SEG _DATA_ZEROPAGE
BIT_FIELD StreamMode; // stream mode control flags
extern BIT_FIELD RegisterFlag;
extern byte value[]; // working value result scratchpad
static byte temp; // byte variables
static byte index; // input character string index
static tword x_value; // 16-bit X accelerometer value
static tword y_value; // 16-bit Y accelerometer value
static tword z_value; // 16-bit Z accelerometer value
extern byte SlaveAddressIIC; // accelerometer slave I2C address
extern byte functional_block; // accelerometer function
extern byte address_in[3]; // Data Flash input address pointer
extern byte address_out[3]; // Data Flash output address pointer
#pragma DATA_SEG DEFAULT
extern tfifo_sample fifo_data[FIFO_BUFFER_SIZE]; // FIFO sample buffer
byte *const ODRvalues [] =
{
"800", "400", "200", "100", "50", "12.5", "6.25", "1.563"
};
byte *const HPvaluesN [] =
{
"16", "8", "4", "2", //800
"16", "8", "4", "2", //400
"8", "4", "2", "1", //200
"4", "2", "1", "0.5", //100
"2", "1", "0.5", "0.25", //50
"2", "1", "0.5", "0.25", //12.5
"2", "1", "0.5", "0.25", //6.25
"2", "1", "0.5", "0.25"
};
byte *const HPvaluesLNLP [] =
{
"16", "8", "4", "2",
"16", "8", "4", "2",
"8", "4", "2", "1",
"4", "2", "1", "0.5",
"2", "1", "0.5", "0.25",
"0.5", "0.25", "0.125", "0.063",
"0.25", "0.125", "0.063", "0.031",
"0.063", "0.031", "0.016", "0.008"
};
byte *const HPvaluesHiRes [] =
{
"16", "8", "4", "2"
};
byte *const HPvaluesLP [] =
{
"16", "8", "4", "2",
"8", "4", "2", "1",
"4", "2", "1", "0.5",
"2", "1", "0.5", "0.25",
"1", "0.5", "0.25", "0.125",
"0.25", "0.125", "0.063", "0.031",
"0.125", "0.063", "0.031", "0.016",
"0.031", "0.016", "0.008", "0.004"
};
byte *const GRange [] =
{
"2g", "4g", "8g"
};
/***********************************************************************************************\
* Public functions
\***********************************************************************************************/
/*********************************************************\
** Terminal Strings
\*********************************************************/
const byte string_Prompt [] = {"\r\nMMA845xQ> "};
const byte string_What [] = {" <-- what?"};
const byte string_Streaming [] = {" - Streaming XYZ data"};
const byte string_Counts [] = {" as signed counts\r\n"};
const byte string_Gs [] = {" as signed g's\r\n"};
const byte string_Interrupts [] = {" via Int Mode "};
const byte string_FIFO [] = {" via FIFO"};
/*********************************************************\
** Initialize Terminal Interface
\*********************************************************/
void TerminalInit (void)
{
SCISendString("\r\n\n** LONGQIU I.S.&T. **");
SCISendString ("\r\n** MMA845xQ Driver **");
SCISendString ("\r\n** using the MC9S08QE8 **");
SCISendString ("\r\n** **");
SCISendString ("\r\n** "__DATE__" "__TIME__" **\r\n\n");
/*
** Prepare Data Flash.
*/
DATAFLASH_Unprotect();
address_in[0] = 0;
address_in[1] = 0;
address_in[2] = 0;
address_out[0] = 0;
address_out[1] = 0;
address_out[2] = 0;
SPI_SS_SELECT;
SPI_ChrShift(0x01);
SPI_ChrShift(0x00);
SPI_SS_DESELECT;
functional_block = FBID_MAX;
StreamMode.Byte = 0;
}
/*********************************************************\
** Process Terminal Interface
\*********************************************************/
void ProcessTerminal (void)
{
/*
** Output command prompt if required.
*/
if (PROMPT_WAIT == FALSE)
{
SCISendString((byte*)string_Prompt);
PROMPT_WAIT = TRUE;
}
/*
** Get input from terminal.
*/
if (SCI_INPUT_READY == TRUE)
{
INPUT_ERROR = FALSE;
/*
** Use command line input if not streaming data
*/
if ((XYZ_STREAM == FALSE) && (INT_STREAM == FALSE))
{
PROMPT_WAIT = FALSE;
/*
** Get first input character - only uppercase
*/
switch (BufferRx[0])
{
/***************************************************************************************/
case '?':
/*
** Help : list valid commands
*/
SCISendString("\r\nMn : Mode 1= Standby; 2= 2g; 4= 4g; 8= 8g\r\n");
SCISendString("On : Oversampling 0=Normal 1=LNLP 2=HiRes 3=LP\r\n");
SCISendString("ROn : ODRHz 0=800; 1=400; 2=200; 3=100; 4=50; 5=12.5; 6=6.25; 7=1.56\r\n");
SCISendString("RRxx : Register xx Read\r\n");
SCISendString("RWxx=nn : Register xx Write value nn\r\n");
SCISendString("RHn : High Pass Filter 0 - 3\r\n");
SCISendString("RF : Report ODR speed, HP Filter freq and Mode\r\n");
/*SCISendString("Ca : Data signed counts a=L LPF data a=H HPF data \r\n");
//SCISendString("Ga : XYZ data as signed g's a=L LPF data a=H HPF data \r\n"); */
//SCISendString("Saa : Stream Data: aa CL=CountsLPF,CH=CountsHPF,GL=G'sLPF,GH=G'sHPF\r\n");
SCISendString("Iaan : Stream Data via Interrupts.\r\n");
SCISendString(" : aa CL=CountsLPF, CH=CountsHPF,GL=G'sLPF,GH=G'sHPF INTn\r\n");
SCISendString(" : n 1= INT1; 2= INT2\r\n");
if (deviceID==1)
{
SCISendString("Faaww : Stream 14-bit XYZ via FIFO\r\n");
SCISendString(" : aa CL=CountsLPF,CH=CountsHPF,GL=G'sLPF,GH=G'sHPF\r\n");
SCISendString(" : ww: Watermark= 1 to 31\r\n");
}
break;
/***
没有合适的资源?快使用搜索试试~ 我知道了~
MMA8452加速度传感器测试代码
共45个文件
cmd:13个
c:8个
h:8个
4星 · 超过85%的资源 需积分: 23 153 下载量 109 浏览量
2011-09-12
14:26:18
上传
评论 2
收藏 114KB RAR 举报
温馨提示
加速度传感器开发源代码,包含C51,ARM的测试代码,可以用于加速度、倾角的测量
资源推荐
资源详情
资源评论
收起资源包目录
MMA8452加速度传感器测试源码.rar (45个子文件)
LQ845X_ExampleCode
BDM_P&E_Multilink_CyclonePro.ini 3KB
bin
Project.abs 148KB
Project.map 119KB
Project.abs.s19 19KB
Project.sx 19KB
LQ845X_ExampleCode.mcp 71KB
Sources
terminal.h 2KB
main.c 13KB
system.h 24KB
spi.h 7KB
data_flash.h 2KB
mma845x.h 20KB
iic.h 8KB
terminal.c 55KB
sci.c 16KB
iic.c 8KB
data_flash.c 8KB
Start08.c 10KB
derivative.h 422B
mma845x.c 3KB
spi.c 3KB
sci.h 10KB
C_Layout.hwl 856B
Default.mem 161B
prm
Project.prm 2KB
Project.old1.prm 2KB
burner.bbl 140B
Copy of Driver.prm 4KB
Project.old0.prm 2KB
Driver.prm 4KB
HCS08_OpenSourceBDM.ini 982B
HCS08_Full_Chip_Simulator.ini 2KB
cmd
HCS08_OpenSourceBDM_Preload.cmd 60B
HCS08_OpenSourceBDM_Erase_Unsecure.cmd 3KB
HCS08_OpenSourceBDM_Reset.cmd 60B
HCS08_Full_Chip_Simulator_Reset.cmd 60B
BDM_P&E_Multilink_CyclonePro_Startup.cmd 59B
HCS08_Full_Chip_Simulator_Startup.cmd 59B
HCS08_OpenSourceBDM_Startup.cmd 59B
BDM_P&E_Multilink_CyclonePro_Reset.cmd 60B
BDM_P&E_Multilink_CyclonePro_Preload.cmd 60B
HCS08_Full_Chip_Simulator_Preload.cmd 60B
HCS08_OpenSourceBDM_Postload.cmd 59B
BDM_P&E_Multilink_CyclonePro_Postload.cmd 59B
HCS08_Full_Chip_Simulator_Postload.cmd 59B
共 45 条
- 1
我要下东东
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页