📄 main.c
字号:
//********************************************************************
// File name: main.c
//
// Copyright 2004 Texas Instruments Inc as an unpublished work.
//
// Author: Rick Downs (based on code from Gebhard Haug & Michael Ashton)
// Revision History:
// 2004.09.23: first build
//
// Compiler: msp430-gcc
//
// Module Description:
// Main program to exercise an ADS1241 on the HPA449
// reads data and sends it over a serial port to PC
// use a terminal program to view data - 115200, 8-bit, No Parity
// 1 stop-bit.
//
//
//********************************************************************
// Include section
// Add all #includes here
# include "legal.c" //Texas Instruments, Inc. copyright and liability
#include <msp430x44x.h>
#include "hpa449lib.h"
#include "sblcd.h"
#include <signal.h>
#include "ADS1240.h"
#include "eeprom.h"
// Defines section
// Add all #defines here
#define PROGRAM_VERSION "01.00"
static char HexTable[] =
{
'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'
};
/*
******************************************************************************
** [function]
** Output24BitASCII
** [purpose]
** sends 24-bit number as hex number in ASCII over serial port
** [parameters]
** Data, 24-bit long
** [returns]
** -
*/
void Output24BitASCII(long Data)
{
unsigned char Buffer[6];
int i;
for (i=5; i>=0; i--)
{
Buffer[i] = HexTable[Data & 0x0000000f];
Data >>= 4;
}
// display data on HPA449 screen
sblcd_lg_showstr(Buffer);
SendBytes(Buffer, 6);
}
/*
******************************************************************************
** [function]
** Init
** [purpose]
** performs all initaizations
** [parameters]
** -
** [returns]
** -
*/
void Init(void)
{
// run on 4.91... MHz
SCFI0 |= FN_4;
SCFQCTL = 74; // (74+1)*32768*2 = ca 4.91 MHz
FLL_CTL0 = DCOPLUS + XCAP18PF;
P1DIR &= ~SWITCH_2_BIT;
P1SEL &= ~SWITCH_2_BIT;
// initialize the LCD display
sblcd_init();
// we use I2C, so we have to initialize it
I2C_Init();
// our DUT is supposed to be on Site A
I2C_SetSite(SITE_A);
// initialize the ADS1240
ADS1240Init();
// initialize the communication port
UART1_Init(42, 0x6b); // sets baud rate to 115.2k
// enable interrupts (out buffered serial routine uses them)
_EINT();
}
/*
******************************************************************************
*/
int main(void)
{
int i;
long Data;
unsigned ACRVal;
int pga;
int dr;
int chan;
int step;
unsigned char chdisp[3];
// do all initialization
Init();
// display on the LCD which part we are testing
sblcd_sm_showstr("1241");
sblcd_lg_showstr(PROGRAM_VERSION);
// wait for user to push SW2 to start program running
WaitForSwitch2();
ADS1240SendResetCommand();
step = 0;
// begin with PGA = 1
// input starts at AIN0 referenced to AINCOM (single-ended)
chan = 0;
chdisp[0] = 'c';
chdisp[1] = 'h';
chdisp[2] = ' ';
chdisp[3] = '0';
sblcd_sm_showstr(chdisp);
SendString("Channel 0 data:\r\n");
// Set the gain and multiplexer
ADS1240SetGain(ADS1240_GAIN_1);
ADS1240SetChannel(chan | ADS1240_MUXN_AINCOM);
// data rate = 15Hz (4.91MHz, SPEED = 1)
ACRVal = SPEED_BIT;
ADS1240WriteRegister(ADS1240_ACR_REGISTER, 1, &ACRVal);
// do an internal self cal
ADS1240AssertCS(1);
ADS1240SendByte(ADS1240_CMD_SELFCAL);
ADS1240AssertCS(0);
for (i=0; i<4; i++)
ADS1240WaitForDataReady(0);
// main loop
// this acquires data and displays it on the HPA449 LCD and
// sends it to the serial port. When SW2 is pushed, the
// channels AIN0-AIN7 are stepped through.
while (1)
{
// acquire data
Data = ADS1240ReadData(1);
// send hex value of data to HPA449 screen and to serial port
Output24BitASCII(Data);
SendString("\r\n");
if (!(P1IN & SWITCH_2_BIT)){
while (!(P1IN & SWITCH_2_BIT));
chan++;
if (chan == 8){
chan = 0;
}
chdisp[3] = HexTable[chan];
//display current channel on small LCD and serial port
sblcd_sm_showstr(chdisp);
SendString(chdisp);
SendString(" data:\r\n");
ADS1240SetChannel((chan*0x10) | ADS1240_MUXN_AINCOM);
// do an internal self cal
ADS1240AssertCS(1);
ADS1240SendByte(ADS1240_CMD_SELFCAL);
ADS1240AssertCS(0);
for (i=0; i<4; i++)
ADS1240WaitForDataReady(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -