Sei sulla pagina 1di 2

/*

* File: mainLab.c
* Author: Glath
*
* Created on 25 de septiembre de 2014, 04:09 PM
*/
#include "headerLab.h"
#include <math.h>
/*
* CONTROL DE LEDS
S: encender el LED.
C: apagar el LED.
1.
2.
3.
4.
Ingrese

Led 1
Led 2
Led 3
Led 4
el comando:

*
*/
const char title[] = "Test Uart: eco ";
const char note1[] = ".";
const char note2[] = "..";
float RMS(int N, int *P);
int A[10];
char B[6];
int retardo,J,ValorRMS,*P1,U,D;
void printMsg();
unsigned int channel_0;
// conversion result as read from result buffer
unsigned int channel_11;
// conversion result as read from result buffer
unsigned int offset;
// buffer offset to point to the base of the idle buffer
int main(void) {
uint32_t number;
uint8_t inCharU2;
init();
printMsg();
number = 1500000;
retardo = 1000000;
P1 = &A[0];
J=0;
EnableADC10();
while ( ! mAD1GetIntFlag() ) { } // wait for the first conversion to complet
e so there will be vaild data in ADC result registers
while (1){

offset = 8 * ((~ReadActiveBufferADC10() & 0x01)); // determine which bu


ffer is idle and create an offset
channel_0 = ReadADC10(offset);
conversion from the idle buffer
channel_11 = ReadADC10(offset + 1);
conversion from the idle buffer

// read the result of channel 4


// read the result of channel 5

channel_0 = (3.3*channel_0)/1024;
*(P1+J) = channel_0;
J++;
if(J==9){
ValorRMS = RMS(10,&A[0]);
P1=&A[0];
J=0;
}
B[0]
B[1]
B[2]
B[3]
B[4]
B[5]

=
=
=
=
=
=

(((channel_0%1000)%100)%10);
';';
((channel_0%100)%10);
channel_0/100;
0x0D;
NULL;

B[0]
B[1]
B[2]
B[3]

=
=
=
=

B[0]
B[1]
B[2]
B[3]

|
|
|
|

0x30 ; //ValorRMS/10;
0x30; //ValorRMS%10;
0x30;
0x30;

putsUart(UART2, B);
}
return (EXIT_SUCCESS);
}
void printMsg(){
putsUart(UART2, (char*)title);
putsUart(UART2, (char*)note1);
putsUart(UART2, (char*)note2);
}
float RMS(int N,int *P){
int C, D, i;
for(i=0;i<N;i++){
C = C + ((*(P+i))*(*(P+i)));
}
D = sqrt(C/N);
return( D );
}

UARTSendDataByte(UART2, 0x0D);
UARTSendDataByte(UART2, 0x0D);
UARTSendDataByte(UART2, 0x0D);

Potrebbero piacerti anche