This commit is contained in:
Олег Бородин
2024-08-21 10:10:42 +02:00
parent c34684e106
commit 0f7f34c1f9
9 changed files with 90 additions and 36 deletions

View File

@@ -15,9 +15,10 @@ LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
MAIN_OBJS += main.o
MAIN_OBJS += contr_main.o
MAIN_OBJS += contr.o
MAIN_OBJS += relay.o
MAIN_OBJS += contr_init.o
MAIN_OBJS += timer.o
MAIN_OBJS += adc.o
MAIN_OBJS += eeprom.o
MAIN_OBJS += i2c.o
MAIN_OBJS += disp.o
@@ -36,9 +37,12 @@ $(MAIN_ELF): $(MAIN_OBJS)
$(CC) $(LDFLAGS) -o $(MAIN_ELF) $(MAIN_OBJS)
$(SIZE) --format=berkeley $@
DEPENDS_DIR = .dep
%.o: %.c
@mkdir -p $(DEPENDS_DIR)
$(CC) $(CFLAGS) -c $*.c -o $*.o
$(CC) -MM $(CFLAGS) $*.c > $*.d
@$(CC) -MM $(CFLAGS) $*.c > $(DEPENDS_DIR)/$*.d
$(MAIN_HEX): $(MAIN_ELF)
@@ -57,9 +61,10 @@ download:
clean:
rm -f *.i *.o *.s
rm -f *.elf *.bin *~ *.hex
rm -f *.d
rm -f *.hex *.elf *.bin
rm -f *~ *.d
rm -rf $(DEPENDS_DIR)
-include $(MAIN_OBJS:.o=.d)
-include $(DEPENDS_DIR)/$(MAIN_OBJS:.o=.d)
#EOF

View File

@@ -8,7 +8,7 @@
#include <tool.h>
void contr_adc_init() {
void adc_init() {
/* Disable ADC */
REG_SETDOWN_BIT(ADCSRA, ADEN);
/* Set reference*/
@@ -28,21 +28,16 @@ void contr_adc_init() {
REG_SETUP_BIT(ADCSRA, ADEN);
}
void contr_timer_init(void) {
/* Disable comparators */
REG_SETDOWN_BIT(TCCR0A, COM0A1);
REG_SETDOWN_BIT(TCCR0A, COM0A0);
REG_SETDOWN_BIT(TCCR0A, COM0B1);
REG_SETDOWN_BIT(TCCR0A, COM0B0);
/* Set normal mode */
REG_SETDOWN_BIT(TCCR0A, WGM01);
REG_SETDOWN_BIT(TCCR0A, WGM00);
/* Set clock to 1/64 */
REG_SETDOWN_BIT(TCCR0B, CS02);
REG_SETUP_BIT(TCCR0B, CS01);
REG_SETUP_BIT(TCCR0B, CS00);
/* Enable timer interrupt */
REG_SETUP_BIT(TIMSK0, TOIE0);
//REG_SETUP(TCNT0, TIMER_INITVAL);
uint16_t adc_read(uint8_t channel) {
uint8_t reg = ADMUX;
ADMUX = (reg & 0xF0) | channel;
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;
return hval | lval;
}

16
adc.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef ADC_H_QWERTY
#define ADC_H_QWERTY
#define ACD_CHANELL0 0x00
#define ACD_CHANELL2 0x01
#define ACD_CHANELL3 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);
#endif

View File

@@ -17,9 +17,9 @@
#include <uart.h>
#include <temp.h>
#include <relay.h>
#include <timer.h>
#include <contr_main.h>
#include <contr_init.h>
#include <contr.h>
#define CONTR_BAND_OFF 0x01
#define CONTR_BAND_10M 0x02
@@ -91,8 +91,8 @@ void contr_setup(void) {
contr_key_init();
contr_adc_init();
contr_timer_init();
adc_init();
timer0_init();
}

View File

@@ -1,7 +0,0 @@
#ifndef CONTR_INIT_H_QWERTY
#define CONTR_INIT_H_QWERTY
void contr_timer_init(void);
void contr_adc_init(void);
#endif

2
main.c
View File

@@ -16,7 +16,7 @@
#include <disp.h>
#include <relay.h>
#include <contr_main.h>
#include <contr.h>
int main(void) {
uart_init();

27
timer.c Normal file
View File

@@ -0,0 +1,27 @@
/*
* Copyright 2017 Oleg Borodin <onborodin@gmail.com>
*/
#include <avr/interrupt.h>
#include <util/delay.h>
#include <tool.h>
void timer0_init(void) {
/* Disable comparators */
REG_SETDOWN_BIT(TCCR0A, COM0A1);
REG_SETDOWN_BIT(TCCR0A, COM0A0);
REG_SETDOWN_BIT(TCCR0A, COM0B1);
REG_SETDOWN_BIT(TCCR0A, COM0B0);
/* Set normal mode */
REG_SETDOWN_BIT(TCCR0A, WGM01);
REG_SETDOWN_BIT(TCCR0A, WGM00);
/* Set clock to 1/64 */
REG_SETDOWN_BIT(TCCR0B, CS02);
REG_SETUP_BIT(TCCR0B, CS01);
REG_SETUP_BIT(TCCR0B, CS00);
/* Enable timer interrupt */
REG_SETUP_BIT(TIMSK0, TOIE0);
//REG_SETUP(TCNT0, TIMER_INITVAL);
}

18
timer.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef 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);
#endif