removed manual looping in favor of hardware flags
This commit is contained in:
parent
246cb36ad5
commit
a123d917d3
|
@ -4,25 +4,20 @@
|
|||
#include "RegEdit.h"
|
||||
|
||||
|
||||
#define G1 1
|
||||
#define G2 3
|
||||
#define G3 2
|
||||
|
||||
#define SAMPLE_QTY 32
|
||||
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable(adc_pin);
|
||||
uint16_t val = 0;
|
||||
for(int i = 0; i < 32; i++){
|
||||
val += ADC_ReadValue(adc_pin);
|
||||
}
|
||||
val /= 32;
|
||||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
if(val < 527 || val > 1000){
|
||||
if(val > 527 || val < 1000){
|
||||
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
||||
}
|
||||
else{
|
||||
RegEdit_ClearBit((void *) &PORTA.OUT, out_pin);
|
||||
RegEdit_ClearBit((void *) &PORTA.DIR, out_pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,14 +25,15 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
|||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable(adc_pin);
|
||||
uint16_t val = 0;
|
||||
for(int i = 0; i < 32; i++){
|
||||
val = ADC_ReadValue(adc_pin);
|
||||
}
|
||||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
if(val < 527 || val > 1000){
|
||||
if(val > 527 || val < 1000){
|
||||
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
||||
}
|
||||
else{
|
||||
RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
|
||||
RegEdit_ClearBit((void *) &PORTB.DIR, out_pin);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue