From ed598229df2c6cb516002ac1b550a3525ffa2f51 Mon Sep 17 00:00:00 2001 From: hamx Date: Tue, 24 Dec 2024 11:11:39 +0100 Subject: [PATCH] update --- main.c | 60 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index afe14c9..179df53 100644 --- a/main.c +++ b/main.c @@ -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,33 +22,49 @@ void print_results(void); void main(void) { config_ad(); - while(1) { + while(1) { // g?ówna p?tla programu ad_go(); - while(ADCON0bits.GO) - { - read[index] = ADRES; - index++; - } - if(!isFull && index == LENGTH - 1) { - isFull = 1; - } + readData(); - if(index == LENGTH - 1) { - index = 0; - } + isReadFull(); - if(isFull) { - oblicz(); - print_results(); - isFull = 0; - } + resetIndex(); + + processData(); } - return; } +void readData(void) { + while(ADCON0bits.GO) + { + read[index] = ADRES; + index++; + } +} + +void processData(void) { + if(isFull) { + oblicz(); + print_results(); + isFull = 0; + } +} + +void resetIndex(void) { + if(index == LENGTH - 1) { + index = 0; + } +} + +void isReadFull(void) { + if(!isFull && index == LENGTH - 1) { + isFull = 1; + } +} + void config_ad(void) { ADCON0 = 0; ADCON1bits.PCFG = 0b100;