blob: 6ce4ee03f99eeda8f94e19ee6aa960f010d2fdf5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "xc.h"
#include "circBuffer.h"
#define SIZE 1024
volatile unsigned long buffer[SIZE];
int buffSize = 0;
void initBuffer(){
int i;
for (i=0; i<SIZE; i++) {
buffer[i]=0;
}
buffSize = 0;
}
void putVal(long newValue){
buffer[buffSize++] = newValue;
if (buffSize > SIZE)
buffSize = 0;
}
long getAvg(){
int i, sum = 0;
for (i=0; i<SIZE; i++) {
sum += buffer[i];
} return sum / SIZE;
}
|