This commit is contained in:
2024-12-24 11:11:39 +01:00
parent 08ce6c3ac2
commit ed598229df
+31 -11
View File
@@ -5,11 +5,15 @@
unsigned int sum = 0; // Suma liczb 8-bitowych, zapisana w zmiennej 16-bitowej
unsigned char rest = 0;
unsigned char result = 0;
unsigned char read[LENGTH] = {};
unsigned int result = 0;
unsigned int read[LENGTH] = {};
unsigned char isFull = 0;
unsigned char index = 0;
void readData(void);
void processData(void);
void resetIndex(void);
void isReadFull(void);
void config_ad(void);
void ad_go(void);
void oblicz(void);
@@ -18,22 +22,30 @@ void print_results(void);
void main(void) {
config_ad();
while(1) {
while(1) { // g?ówna p?tla programu
ad_go();
readData();
isReadFull();
resetIndex();
processData();
}
return;
}
void readData(void) {
while(ADCON0bits.GO)
{
read[index] = ADRES;
index++;
}
if(!isFull && index == LENGTH - 1) {
isFull = 1;
}
if(index == LENGTH - 1) {
index = 0;
}
void processData(void) {
if(isFull) {
oblicz();
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) {