2024-07-02 22:43:49 +00:00
|
|
|
#include <avr/io.h>
|
2024-07-02 22:27:57 +00:00
|
|
|
#include "load.h"
|
|
|
|
#include "ADC.h"
|
|
|
|
#include "RegEdit.h"
|
|
|
|
|
2024-07-02 22:43:49 +00:00
|
|
|
|
2024-07-02 22:27:57 +00:00
|
|
|
#define G1 1
|
|
|
|
#define G2 3
|
|
|
|
#define G3 2
|
|
|
|
|
|
|
|
#define SAMPLE_QTY 32
|
|
|
|
|
2024-07-03 00:16:53 +00:00
|
|
|
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
2024-07-02 22:27:57 +00:00
|
|
|
{
|
2024-07-03 00:16:53 +00:00
|
|
|
ADC_Init(adc_pin);
|
|
|
|
ADC_Enable(adc_pin);
|
|
|
|
uint16_t val;
|
|
|
|
for(int i = 0; i < 32; i++){
|
2024-07-15 19:12:53 +00:00
|
|
|
val = ADC_ReadValue(adc_pin);
|
2024-07-03 00:16:53 +00:00
|
|
|
}
|
2024-07-15 19:12:53 +00:00
|
|
|
|
2024-07-02 22:27:57 +00:00
|
|
|
ADC_Disable();
|
2024-07-03 00:16:53 +00:00
|
|
|
if(val < 527 || val > 1000){
|
|
|
|
RegEdit_ClearBit((void *) &PORTA.OUT, out_pin);
|
|
|
|
RegEdit_ClearBit((void *) &PORTA.DIR, out_pin);
|
|
|
|
}
|
2024-07-02 22:27:57 +00:00
|
|
|
}
|
|
|
|
|
2024-07-03 00:16:53 +00:00
|
|
|
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
2024-07-02 22:27:57 +00:00
|
|
|
{
|
2024-07-03 00:16:53 +00:00
|
|
|
ADC_Init(adc_pin);
|
|
|
|
ADC_Enable(adc_pin);
|
|
|
|
uint16_t val;
|
|
|
|
for(int i = 0; i < 32; i++){
|
|
|
|
val = ADC_ReadValue(adc_pin);
|
2024-07-02 22:27:57 +00:00
|
|
|
}
|
2024-07-03 00:16:53 +00:00
|
|
|
|
|
|
|
ADC_Disable();
|
|
|
|
if(val < 527 || val > 1000){
|
|
|
|
RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
|
|
|
|
RegEdit_ClearBit((void *) &PORTB.DIR, out_pin);
|
2024-07-02 22:27:57 +00:00
|
|
|
}
|
|
|
|
}
|