📄 adc_v1.1.7.c
字号:
/*=============================================================================
// File : ADC_V1.1.C //
// //
// Abstract: This Source file containing the source code for initialisation//
// of ADC and conversion //
// Compiler : IAR Embedded Work Bench //
// //
// Author : Kuberappa.M.Sajjan //
// E-mail : kuber@unifiest.com //
// //
// //
=============================================================================*/
/*---------------------------- Preprocessor Directives ----------------------*/
#include "datatypes_v1.1.h" // Contains the Basic Datatypes for Appl
#include "adc_v1.1.7.h" // Contains the basic function prototype and
// definition for ADC
#include "io430.h" // The Header File
#include "intrinsics.h"
/*--------------------------- Macros and Constants --------------------------*/
#define INT_DELAY {UCHAR int_delay;for(int_delay = 0;int_delay<25;\
int_delay++);}
#pragma codeseg=MY_SEGMENT
UINT myBuffer[10]; /*__no_init*/
#pragma dataseg=default
/*-------------------------- Global Variable Declarations -------------------*/
//static ULONG buffer = 0;
static UINT cnt,adc_avg_data;
static ULONG average;
/*-------------------------- Function Prototypes ----------------------------*/
/*=============================================================================
= FUNCTION_NAME: =
= system_initialisation() =
= =
= Design Description: This function Initialises the system and its Perls =
= Inut Parameters : None =
= Return Type: None =
= =
=============================================================================*/
void system_initialisation(void)
{
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ; // The DCO is configured for 1MHz
lcd_initialisation(); // Initialise the LCD
adc_initialisation(); // Init ADC and configure
// Pins for ADC
}
/*=============================================================================
= FUNCTION_NAME: =
= adc_initialisation() =
= =
= Design Description: This function Initialises the adc Peripheral =
= Inut Parameters : None =
= Return Type: None =
= =
=============================================================================*/
void adc_initialisation(void)
{
SD16CTL|= SD16XDIV_0|SD16DIV_0\
|SD16REFON|SD16SSEL_1; // Enable the SMCLK, Reference on
SD16CCTL0|= SD16DF|SD16IE\
|SD16OSR_1024|SD16SNGL;// The Int enable and Single onversion
SD16AE|= SD16AE1|SD16AE0\
|SD16AE2|SD16AE3; //Configure the ADC pins for CH0 and CH1
}
/*=============================================================================
= FUNCTION_NAME: =
= adc_conversion() =
= =
= Design Description: This function Converts the I/P adc data =
= Inut Parameters : UINT =
= Return Type: None =
= =
=============================================================================*/
UINT adc_conversion_channel0(UCHAR channel_name,const UCHAR count)
{
cnt = 0; // Reinitialise the count for Zero
average = 0; // Reinitialise the average var
while(cnt<count)
{
SD16INCTL0= SD16GAIN_1|SD16INTDLY_0|channel_name; // conf the channel
SD16CCTL0_bit.SD16SC = SET; // Start the conv
}
adc_avg_data = average/count; // Cal Average Value
return (adc_avg_data); // Send the Average Value
}
/*=============================================================================
= FUNCTION_NAME: =
= adc_interrupt() =
= =
= Design Description: This is the interrupt routine it will give the =
= service to the ADC Peripheral =
= Inut Parameters : NONE =
= Return Type: None =
= =
=============================================================================*/
#pragma vector = SD16_VECTOR
__interrupt void adc_isr (void)
{
__disable_interrupt(); // Disable the interrupt
myBuffer[cnt]= SD16MEM0; // Read the ADC Data Register
average+=myBuffer[cnt++]; // Increment the counter
__enable_interrupt(); // Disable Interrupt
}
/*------------------------------------------------------------------------------
Configurtions for OSR Bit, LSBACC, UNI bit
The XOSR = 1
//OSR=1024, LSBACC=1, SD16UNI=1
//SD16XOSR|SD16OSR_1024|SD16LSBACC|SD16UNI;
//OSR=1024, LSBACC=0, SD16UNI=1
//SD16OSR_1024|SD16UNI;
//OSR=1024, LSBACC=1, SD16UNI=0
//SD16OSR_1024|SD16LSBACC;
//OSR=1024, LSBACC=0, SD16UNI=0
//SD16OSR_1024;
//OSR=512, LSBACC=1, SD16UNI=1
//SD16OSR_512|SD16LSBACC|SD16UNI;
//OSR=512, LSBACC=0, SD16UNI=1
//SD16OSR_512|SD16UNI;
OSR=512, LSBACC=1, SD16UNI=0
SD16OSR_512|SD16LSBACC
OSR=512, LSBACC=0, SD16UNI=0
SD16OSR_512
The XOSR bit = 0
OSR=256, LSBACC=1, SD16UNI=1
SD16OSR_256|SD16LSBACC|SD16UNI
OSR=256, LSBACC=0, SD16UNI=1
SD16OSR_256|SD16UNI
OSR=256, LSBACC=1, SD16UNI=0
SD16OSR_256|SD16LSBACC
OSR=256, LSBACC=0, SD16UNI=0
SD16OSR_256
OSR=128, LSBACC=1, SD16UNI=1
SD16OSR_128|SD16LSBACC|SD16UNI
OSR=128, LSBACC=0, SD16UNI=1
SD16OSR_128|SD16UNI
OSR=128, LSBACC=1, SD16UNI=0
SD16OSR_128|SD16LSBACC
OSR=128, LSBACC=0, SD16UNI=0
SD16OSR_128
OSR=64, LSBACC=1, SD16UNI=1
SD16OSR_64|SD16LSBACC|SD16UNI
OSR=64, LSBACC=0, SD16UNI=1
SD16OSR_64|SD16UNI
OSR=64, LSBACC=1, SD16UNI=0
SD16OSR_64|SD16LSBACC
OSR=64, LSBACC=0, SD16UNI=0
SD16OSR_64
OSR=32, LSBACC=x, SD16UNI=1
SD16OSR_32|SD16UNI
OSR=32, LSBACC=x, SD16UNI=0
SD16OSR_32
------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
// SD16CTL|= SD16REFON|SD16SSEL_1; // Reference on 1.2V and SMCLK src
// The Clock from the SMCLK, Internal reference on, No Division
// SD16INCTL0|= SD16INCH_0;//channel_name; // Channel 0
// SD16CCTL0|= SD16OSR_256|SD16UNI;
//SD16CCTL0|= SD16IE|SD16OSR_1024|SD16SNGL;
// SD16INCTL0|= SD16GAIN_1|SD16INTDLY_0;
// SD16INCTL0= SD16GAIN_1|SD16INTDLY_0|SD16INCH_7;
//SD16CCTL0|= SD16SC;
//while(CLR == flags.flag0); // Check for i.nterrupt genewrated
//flags.flag0 = CLR;
//SD16CCTL0_bit.SD16SC= 0; // Start the Conversion
//SD16CCTL0_bit.SD16SC= 0;
------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -