update
This commit is contained in:
60
main.c
60
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;
|
||||
|
||||
Reference in New Issue
Block a user