This commit is contained in:
2024-12-24 11:11:39 +01:00
parent 08ce6c3ac2
commit ed598229df

42
main.c
View File

@@ -5,11 +5,15 @@
unsigned int sum = 0; // Suma liczb 8-bitowych, zapisana w zmiennej 16-bitowej unsigned int sum = 0; // Suma liczb 8-bitowych, zapisana w zmiennej 16-bitowej
unsigned char rest = 0; unsigned char rest = 0;
unsigned char result = 0; unsigned int result = 0;
unsigned char read[LENGTH] = {}; unsigned int read[LENGTH] = {};
unsigned char isFull = 0; unsigned char isFull = 0;
unsigned char index = 0; unsigned char index = 0;
void readData(void);
void processData(void);
void resetIndex(void);
void isReadFull(void);
void config_ad(void); void config_ad(void);
void ad_go(void); void ad_go(void);
void oblicz(void); void oblicz(void);
@@ -18,22 +22,30 @@ void print_results(void);
void main(void) { void main(void) {
config_ad(); config_ad();
while(1) { while(1) { // g?ówna p?tla programu
ad_go(); ad_go();
readData();
isReadFull();
resetIndex();
processData();
}
return;
}
void readData(void) {
while(ADCON0bits.GO) while(ADCON0bits.GO)
{ {
read[index] = ADRES; read[index] = ADRES;
index++; index++;
} }
if(!isFull && index == LENGTH - 1) {
isFull = 1;
}
if(index == LENGTH - 1) {
index = 0;
} }
void processData(void) {
if(isFull) { if(isFull) {
oblicz(); oblicz();
print_results(); print_results();
@@ -41,8 +53,16 @@ void main(void) {
} }
} }
void resetIndex(void) {
if(index == LENGTH - 1) {
index = 0;
}
}
return; void isReadFull(void) {
if(!isFull && index == LENGTH - 1) {
isFull = 1;
}
} }
void config_ad(void) { void config_ad(void) {