update
This commit is contained in:
4
adc.h
4
adc.h
@@ -2,8 +2,8 @@
|
|||||||
#define ADC_H_QWERTY
|
#define ADC_H_QWERTY
|
||||||
|
|
||||||
#define ACD_CHANELL0 0x00
|
#define ACD_CHANELL0 0x00
|
||||||
#define ACD_CHANELL2 0x01
|
#define ACD_CHANELL1 0x01
|
||||||
#define ACD_CHANELL3 0x02
|
#define ACD_CHANELL2 0x02
|
||||||
#define ACD_CHANELL3 0x03
|
#define ACD_CHANELL3 0x03
|
||||||
#define ACD_CHANELL4 0x04
|
#define ACD_CHANELL4 0x04
|
||||||
#define ACD_CHANELL5 0x05
|
#define ACD_CHANELL5 0x05
|
||||||
|
|||||||
68
contr.c
68
contr.c
@@ -11,13 +11,15 @@
|
|||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#include <tool.h>
|
||||||
#include <eeprom.h>
|
#include <eeprom.h>
|
||||||
#include <disp.h>
|
#include <disp.h>
|
||||||
#include <tool.h>
|
|
||||||
#include <uart.h>
|
#include <uart.h>
|
||||||
#include <temp.h>
|
#include <temp.h>
|
||||||
#include <relay.h>
|
#include <relay.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
|
#include <adc.h>
|
||||||
|
|
||||||
|
|
||||||
#include <contr.h>
|
#include <contr.h>
|
||||||
|
|
||||||
@@ -87,12 +89,6 @@ void contr_init(void) {
|
|||||||
|
|
||||||
void contr_setup(void) {
|
void contr_setup(void) {
|
||||||
contr_read_band();
|
contr_read_band();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
contr_key_init();
|
|
||||||
adc_init();
|
|
||||||
timer0_init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -251,22 +247,10 @@ void contr_main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void contr_vcc_measure(void) {
|
void contr_vcc_measure(void) {
|
||||||
REG_SETUP_BIT(ADMUX, MUX0);
|
|
||||||
REG_SETUP_BIT(ADMUX, MUX1);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX2);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX3);
|
|
||||||
|
|
||||||
REG_SETUP_BIT(ADCSRA, ADSC);
|
|
||||||
while (ADCSRA & BIT(ADSC));
|
|
||||||
uint16_t lval = (uint16_t)ADCL;
|
|
||||||
uint16_t hval = (uint16_t)ADCH;
|
|
||||||
hval = (hval << 8) & 0xFF00;
|
|
||||||
lval = lval & 0x00FF;
|
|
||||||
|
|
||||||
if (++contr.vcc_pos > VCC_SIZE) {
|
if (++contr.vcc_pos > VCC_SIZE) {
|
||||||
contr.vcc_pos = 0;
|
contr.vcc_pos = 0;
|
||||||
}
|
}
|
||||||
contr.vcc[contr.vcc_pos] = (hval | lval);
|
contr.vcc[contr.vcc_pos] = adc_read(ACD_CHANELL3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CONTR_VCC_SCALE 2673.0F
|
#define CONTR_VCC_SCALE 2673.0F
|
||||||
@@ -289,22 +273,10 @@ float contr_vcc_calc(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void contr_fwd_measure(void) {
|
void contr_fwd_measure(void) {
|
||||||
REG_SETUP_BIT(ADMUX, MUX0);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX1);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX2);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX3);
|
|
||||||
|
|
||||||
REG_SETUP_BIT(ADCSRA, ADSC);
|
|
||||||
while (ADCSRA & BIT(ADSC));
|
|
||||||
uint16_t lval = (uint16_t)ADCL;
|
|
||||||
uint16_t hval = (uint16_t)ADCH;
|
|
||||||
hval = (hval << 8) & 0xFF00;
|
|
||||||
lval = lval & 0x00FF;
|
|
||||||
|
|
||||||
if (++contr.fwd_pos > FWD_SIZE) {
|
if (++contr.fwd_pos > FWD_SIZE) {
|
||||||
contr.fwd_pos = 0;
|
contr.fwd_pos = 0;
|
||||||
}
|
}
|
||||||
contr.fwd[contr.fwd_pos] = (hval | lval);
|
contr.fwd[contr.fwd_pos] = adc_read(ACD_CHANELL1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float contr_fwd_calc(void) {
|
float contr_fwd_calc(void) {
|
||||||
@@ -319,22 +291,10 @@ float contr_fwd_calc(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void contr_rev_measure(void) {
|
void contr_rev_measure(void) {
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX0);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX1);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX2);
|
|
||||||
REG_SETDOWN_BIT(ADMUX, MUX3);
|
|
||||||
|
|
||||||
REG_SETUP_BIT(ADCSRA, ADSC);
|
|
||||||
while (ADCSRA & BIT(ADSC));
|
|
||||||
uint16_t lval = (uint16_t)ADCL;
|
|
||||||
uint16_t hval = (uint16_t)ADCH;
|
|
||||||
hval = (hval << 8) & 0xFF00;
|
|
||||||
lval = lval & 0x00FF;
|
|
||||||
|
|
||||||
if (++contr.rev_pos > REV_SIZE) {
|
if (++contr.rev_pos > REV_SIZE) {
|
||||||
contr.rev_pos = 0;
|
contr.rev_pos = 0;
|
||||||
}
|
}
|
||||||
contr.rev[contr.rev_pos] = (hval | lval);
|
contr.rev[contr.rev_pos] = adc_read(ACD_CHANELL0);;
|
||||||
}
|
}
|
||||||
|
|
||||||
float contr_rev_calc(void) {
|
float contr_rev_calc(void) {
|
||||||
@@ -356,18 +316,6 @@ void contr_read_band(void) {
|
|||||||
eeprom_read_bytes(0x00, &contr.band, sizeof(contr.band));
|
eeprom_read_bytes(0x00, &contr.band, sizeof(contr.band));
|
||||||
}
|
}
|
||||||
|
|
||||||
void contr_key_init(void) {
|
|
||||||
/* D3 PD3: Set key input */
|
|
||||||
REG_SETDOWN_BIT(DDRD, PD3);
|
|
||||||
REG_SETUP_BIT(PORTD, PD3);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool contr_key_is_pressed(void) {
|
|
||||||
if (REG_BIT_VALUE(PIND, PD3)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CONTR_KEY_CNTINPRESS 100
|
#define CONTR_KEY_CNTINPRESS 100
|
||||||
#define CONTR_KEY_CNTRELEASE 100
|
#define CONTR_KEY_CNTRELEASE 100
|
||||||
@@ -377,7 +325,7 @@ bool contr_key_is_pressed(void) {
|
|||||||
|
|
||||||
void contr_key_handle(void) {
|
void contr_key_handle(void) {
|
||||||
if (!contr.key_was_pressed) {
|
if (!contr.key_was_pressed) {
|
||||||
if (contr_key_is_pressed()) {
|
if (button_is_pressed()) {
|
||||||
contr.key_time_counter++;
|
contr.key_time_counter++;
|
||||||
contr.key_time_untap++;
|
contr.key_time_untap++;
|
||||||
}
|
}
|
||||||
@@ -386,7 +334,7 @@ void contr_key_handle(void) {
|
|||||||
contr.key_was_pressed = true;
|
contr.key_was_pressed = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!contr_key_is_pressed()) {
|
if (!button_is_pressed()) {
|
||||||
contr.key_time_counter++;
|
contr.key_time_counter++;
|
||||||
}
|
}
|
||||||
if (contr.key_time_counter > CONTR_KEY_CNTRELEASE) {
|
if (contr.key_time_counter > CONTR_KEY_CNTRELEASE) {
|
||||||
|
|||||||
7
main.c
7
main.c
@@ -10,11 +10,12 @@
|
|||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
#include <tool.h>
|
|
||||||
#include <uart.h>
|
#include <uart.h>
|
||||||
#include <i2c.h>
|
#include <i2c.h>
|
||||||
|
#include <adc.h>
|
||||||
#include <disp.h>
|
#include <disp.h>
|
||||||
#include <relay.h>
|
#include <relay.h>
|
||||||
|
#include <timer.h>
|
||||||
|
|
||||||
#include <contr.h>
|
#include <contr.h>
|
||||||
|
|
||||||
@@ -24,6 +25,9 @@ int main(void) {
|
|||||||
uartio_init();
|
uartio_init();
|
||||||
disp_init();
|
disp_init();
|
||||||
|
|
||||||
|
adc_init();
|
||||||
|
timer0_init();
|
||||||
|
|
||||||
atten_init();
|
atten_init();
|
||||||
relaytx_init();
|
relaytx_init();
|
||||||
relay10m_init();
|
relay10m_init();
|
||||||
@@ -32,6 +36,7 @@ int main(void) {
|
|||||||
relay80m_init();
|
relay80m_init();
|
||||||
buzzer_init();
|
buzzer_init();
|
||||||
fan_init();
|
fan_init();
|
||||||
|
button_init();
|
||||||
|
|
||||||
relaytx_off();
|
relaytx_off();
|
||||||
atten_off();
|
atten_off();
|
||||||
|
|||||||
17
relay.c
17
relay.c
@@ -10,10 +10,19 @@
|
|||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
#include <tool.h>
|
#include <tool.h>
|
||||||
//#include <uart.h>
|
|
||||||
//#include <i2c.h>
|
void button_init(void) {
|
||||||
//#include <disp.h>
|
/* D3 PD3: Set key input */
|
||||||
//#include <timer.h>
|
REG_SETDOWN_BIT(DDRD, PD3);
|
||||||
|
REG_SETUP_BIT(PORTD, PD3);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool button_is_pressed(void) {
|
||||||
|
if (REG_BIT_VALUE(PIND, PD3)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* D4 PD4: Set input relay 5 output */
|
/* D4 PD4: Set input relay 5 output */
|
||||||
void relaytx_init(void) {
|
void relaytx_init(void) {
|
||||||
|
|||||||
3
relay.h
3
relay.h
@@ -2,6 +2,9 @@
|
|||||||
#ifndef CONTR_RELAY_H_QWERTY
|
#ifndef CONTR_RELAY_H_QWERTY
|
||||||
#define CONTR_RELAY_H_QWERTY
|
#define CONTR_RELAY_H_QWERTY
|
||||||
|
|
||||||
|
void button_init(void);
|
||||||
|
bool button_is_pressed(void);
|
||||||
|
|
||||||
void relaytx_init(void);
|
void relaytx_init(void);
|
||||||
void relaytx_on(void);
|
void relaytx_on(void);
|
||||||
void relaytx_off(void);
|
void relaytx_off(void);
|
||||||
|
|||||||
12
timer.h
12
timer.h
@@ -1,18 +1,6 @@
|
|||||||
#ifndef CONTR_INIT_H_QWERTY
|
#ifndef CONTR_INIT_H_QWERTY
|
||||||
#define CONTR_INIT_H_QWERTY
|
#define CONTR_INIT_H_QWERTY
|
||||||
|
|
||||||
#define ACD_CHANELL0 0x00
|
|
||||||
#define ACD_CHANELL1 0x01
|
|
||||||
#define ACD_CHANELL2 0x02
|
|
||||||
#define ACD_CHANELL3 0x03
|
|
||||||
#define ACD_CHANELL4 0x04
|
|
||||||
#define ACD_CHANELL5 0x05
|
|
||||||
#define ACD_CHANELL6 0x06
|
|
||||||
#define ACD_CHANELL7 0x07
|
|
||||||
|
|
||||||
void adc_init(void);
|
|
||||||
uint16_t adc_read(uint8_t channel);
|
|
||||||
|
|
||||||
void timer0_init(void);
|
void timer0_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user