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

📄 adcseries.c

📁 CC2430芯片点对点通讯
💻 C
字号:
/******************************************************************************
*                                                                             *
*        **********                                                           *
*       ************                                                          *
*      ***        ***                                                         *
*     ***    ++    ***                                                        *
*     ***   +  +   ***                      CHIPCON                           *
*     ***   +                                                                 *
*     ***   +  +   ***                                                        *
*     ***    ++    ***                                                        *
*      ***        ***                                                         *
*       ************                                                          *
*        **********                                                           *
*                                                                             *
*******************************************************************************

Filename:     adcSeries.c
Target:       cc2430
Author:       EFU
Revised:      16/12-2005
Revision:     1.0

Description:
    This example prints the pot-meter voltage versus time on the LCD.
    The sampling instant is set by timer 1 and the converted data is transferred
    using DMA. The data is then converted to be printed on the LCD.

******************************************************************************/
#include "app_ex.h"
#include <string.h>


// Prototypes
void initAdc(void);
void adc_main(void);
void updateVoltageLCD(INT8 potVoltage, INT8 adc_value);
void updateJoystickDirectionLCD(JOYSTICK_DIRECTION direction);
void updateCounter(INT8 delay);
INT8 scaleValue(INT8 adc_value);



#define NUMBER_OF_SAMPLES 42//cywu 40
#define NUMBER_OF_SYMBOLS 84//cywu 16

__code const unsigned short graphElement[16] = {0x8000, 0x4000, 0x2000, 0x1000,
                                                0x0800, 0x0400, 0x0200, 0x0100,
                                                0x0080, 0x0040, 0x0020, 0x0010,
                                                0x0008, 0x0004, 0x0002, 0x0001};

void shiftValues(INT8* values, BYTE length);
//void graphElement(INT8 values[], SYMBOL *height, BYTE length);//cywu
void adc_series_main(void);


/******************************************************************************
* @fn  adc_series_main
*
* @brief
*      Main function for ADC series conversion application example
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void adc_series_main(void){
#else
void main(void){
#endif

   DMA_DESC dmaAdc;
   unsigned char graphHeight[NUMBER_OF_SYMBOLS];
   INT8 i;
   INT8 k;
   INT8 adcValues[NUMBER_OF_SAMPLES];
   INT8 temp;

   DISABLE_ALL_INTERRUPTS();

   memset(graphHeight, 0, sizeof(graphHeight));
   memset(adcValues, 0, sizeof(adcValues));

   SET_MAIN_CLOCK_SOURCE(CRYSTAL);
   CLKCON &= ~0x38;


   initLcd();

   INIT_GLED();
   INIT_YLED();

   lcdUpdate((char*)"Turn Potmeter",(char*)"");
   halWait(0xFF);
   halWait(0xFF);
   halWait(0xFF);

   // Setting up the DMA
   SET_WORD(dmaAdc.SRCADDRH, dmaAdc.SRCADDRL,   &X_ADCH);
   SET_WORD(dmaAdc.DESTADDRH, dmaAdc.DESTADDRL, &adcValues);
   SET_WORD(dmaAdc.LENH, dmaAdc.LENL, 1);
   dmaAdc.VLEN          = VLEN_USE_LEN;
   dmaAdc.PRIORITY      = PRI_HIGH;
   dmaAdc.M8            = M8_USE_8_BITS;
   dmaAdc.IRQMASK       = FALSE;
   dmaAdc.DESTINC       = DESTINC_0;
   dmaAdc.SRCINC        = SRCINC_0;
   dmaAdc.TRIG          = 28;
   dmaAdc.TMODE         = TMODE_SINGLE_REPEATED;
   dmaAdc.WORDSIZE      = WORDSIZE_BYTE;


   // Setting the descriptor pointer and arming the DMA. Using DMA channel 0
   DMA_SET_ADDR_DESC0(&dmaAdc);
   DMA_ARM_CHANNEL(0);


   // Setting up timer 1 to generate sampling commands to the ADC.
   TIMER1_INIT();
   halSetTimer1Period(40000);
   T1CCTL0 = 0x24;


   // Setting up the ADC to sample from channel 7 (pin P0.7 pot meter)
   ADC_ENABLE_CHANNEL(7);
   ADC_SEQUENCE_SETUP(ADC_REF_AVDD | ADC_14_BIT | ADC_AIN7);
   ADC_TRIGGER_FROM_TIMER1();


   //strcpy(lcdData[0], (char*)"3.3V ");//cywu
   //strcpy(lcdData[1], (char*)"0.0V ");//cywu

   //lcdUpdate(lcdData[0], lcdData[1]);//cywu
   lcdUpdate("3.3V ", "0.0V ");
   lcdUpdateSymbol(LINE1, 4, 128);
   lcdUpdateSymbol(LINE2, 4, 129);


   // Starting timer 1
   TIMER1_RUN(TRUE);

   while(!stopApplication())//TRUE)
   {
      ADC_TRIGGER_FROM_TIMER1();

      halWait(50);

      // Checking if a DMA transfer has been performed.
      if(DMAIRQ & DMA_CHANNEL_0)
      {
         DMAIRQ &= ~DMA_CHANNEL_0;

         // Converting the new sample to "LCD-format"
         for(i = NUMBER_OF_SAMPLES-1, k = 0; i >= 0; i--, k++)
         {
            temp = adcValues[i];
            temp /= 8;
            graphHeight[k] = graphElement[temp];
            graphHeight[NUMBER_OF_SAMPLES+k] = graphElement[temp]>>8;
         }
         //Draw the sample values on the LCD
         LCD_draw_bmp_pixel(30,LINE1,graphHeight, NUMBER_OF_SAMPLES,16);
         // Shifting the converted values
         shiftValues(adcValues, NUMBER_OF_SAMPLES);
      }

   }
}


/******************************************************************************
* @fn  shiftValues
*
* @brief
*      Right-shift of INT8 vectors
*
* Parameters:
*
* @param  INT8* values
*
*         BYTE length
*
* @return void
*
******************************************************************************/
void shiftValues(INT8* values, BYTE length)
{
   length--;

   while(length)
   {
      values[length] = values[length-1];
      length--;
   }
}


/******************************************************************************
* @fn  adc_series_init
*
* @brief
*      Initializes ADC application example.
*
* Parameters:
*
* @param  APPLICATION  *a
*         Main application
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void adc_series_init(APPLICATION *a){
   a->menuText = (char*)"ADC Series";
   a->description = (char*)"T1 and DMA";
   a->main_func = adc_series_main;
}
#endif

⌨️ 快捷键说明

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