⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ads834x.c

📁 ADS8344.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************/
/* FILENAME: main.c                            		        */
/* DESCRIPTION: This program uses the MSP430F449 to read 100 	*/
/*    samples from the ADS8344 16-bit, 8CH, 100KSPS ADC.        */  
/*    The samples are stored in the buffer adc_data.            */
/*    Refer to the .map file created by the compiler for the    */  
/*    address in memory for adc_data.                           */
/*    AUTHOR: Tom Hendrick, Data Acquisition Products,          */  
/*            Dallas Texas                                      */
/*    CREATED 2004(C) BY TEXAS INSTRUMENTS INCORPORATED.  	*/
/*    VERSION: 1.0 						*/
/****************************************************************/
#include <msp430x44x.h>
#include "SBLCDA2.h"
#include "ADS834x.h"

#define Resonator (0)  // 0=No Resonator, 1=Resonator installed at X4 on HPA449
#define Samples 100
#define UD_P1_C            (0xD1)  // For four digit display on HPA449 
#define UD_P2_H            (0x76)  // For four digit display on HPA449
/**************** Function prototypes ***********************************/
/*                                                                      */
void init_sys(void);                /* MSP430 Initialisation routine    */
void init_adc(void);                /* adc initialisation routine       */  
void delay(int);                   /* Software delay                    */
void adc_convert(int);             /* Do the adc conversion             */

/**************** HPA449 Function prototypes ****************************/
/*                                                                      */
void timer(void);
void display(void);                 
void InitializeLCD( void );
void clearDisplay( void );
void clearMajor( void );
void sortMajor( unsigned int );
void displaySpecial( long int );
void displayMinor( int, int );
void displayHPA449(void);
void displayTest();	
void setupClock(int);
/*                                                                      */            
/************************************************************************/

/************************************************************************/
/*                                                                      */
/* Global variable declarations                                         */
/*                                                                      */
/************************************************************************/

int adc_Data[Samples];        // Storage for converted data
int i= 0, CH = 0, DispType = 0;
short    FRST7, NEXT8, LAST1, JUNK;  

/************************************************************************/
/*                                                                      */
/* main() variable declarations                                         */
/*                                                                      */
/************************************************************************/
// Note: ADS8344 EVM Loaded on J9 and J7 - Serial_A Connections
// Corresponds to J9, J12 and J7 - Serial Site A
  #define   CONVERT           0x20   //p3.5
  #define   ADC_CS            0x80   //p3.7
  #define   CONV_CLK          0x10   //p1.4


void main(void)
{
  init_sys();                     // Initialise the MSP430       
  init_adc();

  InitializeLCD();       
  clearDisplay();
  displaySpecial(SoftBaugh|AL|AR|AU|AD);                               

      do {
       for(i=0; i<Samples; i++)
        {
         adc_convert(i);            // Do conversions from each channel
         displaySpecial(SoftBaugh);
         displayTest(DispType);     // Display the Channel under test and conversion results
        }
         clearMajor();              // Clears the major digits in LCD        
     } 
     
     while (1);              // 
}			      	

/************************************************************/
/* Prototype - init_sys                                     */
/*                                                          */
/* !NA init_sys                                             */
/* !LA ANSI C                                               */
/* !PI *                                                    */
/* !PO *                                                    */
/* !LV *                                                    */
/*  Description                                             */
/*  This prototype initialises the MSP430F149               */
/************************************************************/
void init_sys(void)
{
void setupports(void);  /* Local function prototype         */
void setupSPI(void);    /* Local function prototype         */    

setupports();
setupSPI();
setupClock(Resonator);
//SetupInterrupts
P1IFG |= 0x00;
P1IES |= 0x40;
P1IE |= 0x40;
  _EINT();
}
/************************************************************/
/* Prototype - setupClock                                     */
/*                                                          */
/*  Description                                             */
/*  This prototype sets-up the XT2 oscillator and tests     */
/*  that it has settled before moving on                    */
/************************************************************/      
void setupClock (int RES)
{
    switch (RES)
    {
        case  0:
          { WDTCTL = WDTPW + WDTHOLD;
            /* D=2, N=121, no mod */
            SCFQCTL=121;
            // SCFI0 = 0100 0100
            SCFI0=0x44;
            // DCOPLUS=1, XTS_FLL=0
            // XCAPXPF=00
            FLL_CTL0=0x80;
            // SMCLK=0, XT2OFF=1, SELMX=00, SELS=0, FLL_DIVX=10
            // FLL_CTL1= 0010 0010
            FLL_CTL1=0x22;
          }
          break;        
        case  1:
          { WDTCTL = WDTPW + WDTHOLD;           // Stop watchdog timer  
            FLL_CTL0&=XT2OFF;                    // Switch on the XT2 osc.
            FLL_CTL1|=SELM_XT2+SELS;                // Select XT2 osc. for 
            // Test the osc. flag bit
            do {
                IFG1 &= ~OFIFG;            // Clear the OFIFG bit
                } while (OFIFG&IFG1);      //
          }

          break;
    }    
}

/************************************************************/
/* Prototype - setupports                                   */
/*                                                          */
/* !NA setupports                                           */
/* !LA ANSI C                                               */
/* !PI *                                                    */
/* !PO *                                                    */
/* !LV *                                                    */
/*  Description                                             */
/*  This prototype sets-up the GPIO ports as appropriate    */
/************************************************************/      
void setupports (void)
{
//SetupPort3                                             
P3SEL = BIT3 + BIT2 + BIT1;           // Bits 3, 2 & 1 are assigned as SPI specific pins
P3DIR |= CONVERT + ADC_CS ;           // Set the output bits
P3OUT = CONVERT + ADC_CS;             // Set the output pins high
}

/************************************************************/
/* Prototype - setupSPI                                     */
/*                                                          */
/* !NA setupSPI                                             */
/* !LA ANSI C                                               */
/* !PI *                                                    */
/* !PO *                                                    */
/* !LV *                                                    */
/*  Description                                             */
/*  This prototype sets-up the P3 for communication via SPI */
/************************************************************/      
void setupSPI (void)
{    
ME1 |= USPIE0;                      // Module Enable - SPI
U0CTL &= ~SWRST;                    // Make sure the RESET bit is off                                   
U0CTL |= CHAR + SYNC + MM;          // USART0 module operation
                                    // CHAR = 1 => 8-bit data 
                                    // SYNC = 1 => SPI selected
                                    // MM = 1 => master mode,
                                    //     MSP is the master

U0TCTL |= SSEL0 + SSEL1 + STC;      // USART0 Tranmit control register
                                    // SSEL0 = 1 & SSEL1 = 1
                                    // => SMCLK is used for baud-rate generation
                                    // STC = 1 => 3-pin SPI mode selected
U0BR0  = 0x02;                      // Divide SMCLK by 4 => transfer clock

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -