fg004_a1/load.c

43 lines
921 B
C

#include <avr/io.h>
#include "load.h"
#include "ADC.h"
#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;
for(int i = 0; i < 32; i++){
val += ADC_ReadValue(adc_pin);
}
val /= 32;
ADC_Disable();
if(val < 527 || val > 1000){
RegEdit_ClearBit((void *) &PORTA.OUT, out_pin);
RegEdit_ClearBit((void *) &PORTA.DIR, out_pin);
}
}
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
{
ADC_Init(adc_pin);
ADC_Enable(adc_pin);
uint16_t val;
for(int i = 0; i < 32; i++){
val = ADC_ReadValue(adc_pin);
}
ADC_Disable();
if(val < 527 || val > 1000){
RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
RegEdit_ClearBit((void *) &PORTB.DIR, out_pin);
}
}