#define Num_of_Results 4
//volatile unsigned int A0results[Num_of_Results];
//volatile unsigned int A1results[Num_of_Results];
volatile unsigned int A2results[Num_of_Results];
volatile unsigned int A3results[Num_of_Results];
unsigned char index=0,i=0,j=0,ok=0;
unsigned int k=0,q=0;
unsigned int Current[1205],Voltage[1205];
unsigned char Voltage_Buffer[6];
unsigned char Current_Buffer[6];
unsigned char Send_num=0;
unsigned char Send_num_buffer[4];
unsigned int Volt=0;
signed char yes=0;
unsigned long int time_num=0;
unsigned char time_num_Buffer[3];
void Clock_Init(void);
void AD_init();
void UART_init();
void USCI_A0_PutChar(char Chr);
char USCI_A0_GetChar(void);
void Uart_Send(unsigned char *s);
void Timer(void);
void main(void)
{
WDTCTL = WDTPW+WDTHOLD;
Clock_Init();
AD_init();
UART_init();
Timer();
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, Enable interrupts
__no_operation(); // For debugger
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: break; // Vector 6: ADC12IFG0
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12:
{
// A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared
// A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared
A2results[index] = ADC12MEM2; // Move A0 results, IFG is cleared
A3results[index] = ADC12MEM3; // Move A1 results, IFG is cleared
index++; // Increment results index, modulo; Set Breakpoint1 here
//
// Current[k]=A2results[0];
// Voltage[k]=A3results[0];
if (index == 2)
{
index = 0;
Voltage[k]=0;
Current[k]=0;
for(i=0;i<2;i++)
{
Current[k]+=A3results;
Voltage[k]+=A2results;
}
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // Select DCO range 24MHz operation
UCSCTL2 = FLLD_1 + 374; // Set DCO Multiplier for 12MHz
// (N + 1) * FLLRef = Fdco
// (374 + 1) * 32768 = 12MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop
// Worst-case settling time for the DCO when the DCO range bits have been
// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization.
// 32 x 32 x 12 MHz / 32,768 Hz = 375000 = MCLK cycles for DCO to settle
__delay_cycles(375000);
// Loop until XT1,XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
}