diff --git a/contr.c b/contr.c index bb6f6d0..16ef4ae 100644 --- a/contr.c +++ b/contr.c @@ -32,6 +32,7 @@ typedef struct { uint8_t band; uint16_t vcc; + uint16_t cnt; } contr_t; contr_t contr; @@ -41,11 +42,6 @@ void contr_set_band(uint8_t band); void contr_write_band(void); void contr_read_band(void); -ISR(TIMER0_OVF_vect) { - button_handle(); - uart_handle(); -} - void contr_init(void) { contr.band = CONTR_BAND_OFF; } @@ -109,7 +105,7 @@ void contr_set_band(uint8_t band) { break; } contr_write_band(); - atten_on(); + atten_off(); } char* contr_get_bandname() { @@ -161,24 +157,71 @@ void contr_show_logo(void) { } void contr_show_band(void) { - disp_string(0, 12, contr_get_bandname(contr.band)); + disp_string(0, 13, contr_get_bandname(contr.band)); } void contr_show_vcc(void) { char buffer[12] = { '\0' }; - sprintf(buffer, "#%4.1fV", contr_get_vcc()); - disp_string(0, 0, buffer); + sprintf(buffer, "%03.1fv", contr_get_vcc()); + disp_string(3, 11, buffer); +} + +void contr_show_ptt(void) { + if (ptt_is_pressed()) { + disp_string(3, 0, "TX"); + } else { + disp_string(3, 0, " "); + } +} + +ISR(TIMER0_OVF_vect) { + //button_handle(); + //uart_handle(); +} + +ISR(TIMER1_OVF_vect) { + contr.cnt++; } +void xxtimer0_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); +} + + + +void contr_show_cnt(void) { + char buffer[12] = { '\0' }; + sprintf(buffer, "%8u", contr.cnt); + disp_string(2, 0, buffer); +} + void contr_main(void) { + contr_show_logo(); uint16_t counter = 0; + sei(); + while (true) { + contr_show_ptt(); contr_button_eval(); contr_measure_vcc(); contr_show_vcc(); contr_show_band(); + contr_show_cnt(); counter++; _delay_ms(100); } diff --git a/main.c b/main.c index e65f317..85a2ff9 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,7 @@ int main(void) { adc_init(); timer0_init(); + timer1_init(); atten_init(); relaytx_init(); @@ -37,6 +38,7 @@ int main(void) { relay80m_init(); buzzer_init(); fan_init(); + ptt_init(); button_init(); button_reset(); diff --git a/relay.c b/relay.c index 7208563..5d2b49f 100644 --- a/relay.c +++ b/relay.c @@ -11,6 +11,20 @@ #include +void ptt_init(void) { + /* D2 PD2: Set PTT input */ + REG_SETDOWN_BIT(DDRD, PD2); + REG_SETUP_BIT(PORTD, PD2); +} + +bool ptt_is_pressed(void) { + if (!REG_BIT_VALUE(PIND, PD2)) { + return true; + } + return false; +} + + /* D4 PD4: Set input relay 5 output */ void relaytx_init(void) { REG_SETUP_BIT(DDRD, PD4); diff --git a/relay.h b/relay.h index 85f5a78..0027385 100644 --- a/relay.h +++ b/relay.h @@ -2,6 +2,8 @@ #ifndef CONTR_RELAY_H_QWERTY #define CONTR_RELAY_H_QWERTY +void ptt_init(void); +bool ptt_is_pressed(void); void relaytx_init(void); void relaytx_on(void); diff --git a/timer.c b/timer.c index 687007c..7f0fe00 100644 --- a/timer.c +++ b/timer.c @@ -9,6 +9,7 @@ #include void timer0_init(void) { + /* TCCR0A */ /* Disable comparators */ REG_SETDOWN_BIT(TCCR0A, COM0A1); REG_SETDOWN_BIT(TCCR0A, COM0A0); @@ -17,11 +18,46 @@ void timer0_init(void) { /* Set normal mode */ REG_SETDOWN_BIT(TCCR0A, WGM01); REG_SETDOWN_BIT(TCCR0A, WGM00); + + /* TCCR0B */ /* Set clock to 1/64 */ REG_SETDOWN_BIT(TCCR0B, CS02); REG_SETUP_BIT(TCCR0B, CS01); REG_SETUP_BIT(TCCR0B, CS00); + + /* TIMSK0 */ /* Enable timer interrupt */ REG_SETUP_BIT(TIMSK0, TOIE0); - //REG_SETUP(TCNT0, TIMER_INITVAL); +} + +void timer1_init(void) { + /* TCCR1A */ + REG_SETDOWN_BIT(TCCR1A, COM1A1); + REG_SETDOWN_BIT(TCCR1A, COM1A0); + REG_SETDOWN_BIT(TCCR1A, COM1B1); + REG_SETDOWN_BIT(TCCR1A, COM1B0); + REG_SETDOWN_BIT(TCCR1A, WGM11); + REG_SETDOWN_BIT(TCCR1A, WGM10); + + /* TCCR1B */ + /* Disable capture noise canceler */ + REG_SETDOWN_BIT(TCCR1B, ICNC1); + /* Set Capture Edge */ + REG_SETUP_BIT(TCCR1B, ICES1); + /* Disable waveform generation */ + REG_SETDOWN_BIT(TCCR1B, WGM13); + REG_SETDOWN_BIT(TCCR1B, WGM12); + /* Set prescaler */ + REG_SETDOWN_BIT(TCCR1B, CS10); + REG_SETUP_BIT(TCCR1B, CS11); + REG_SETUP_BIT(TCCR1B, CS12); + + /* TIMSK1 */ + /* Disable capture interrupt */ + REG_SETDOWN_BIT(TIMSK1, ICIE1); + /* Disable compare interrupt */ + REG_SETDOWN_BIT(TIMSK1, OCIE1B); + REG_SETDOWN_BIT(TIMSK1, OCIE1A); + /* ENABLE overflow interrupt */ + REG_SETUP_BIT(TIMSK1, TOIE1); } diff --git a/timer.h b/timer.h index 7d2b179..e43ddc3 100644 --- a/timer.h +++ b/timer.h @@ -2,5 +2,6 @@ #define CONTR_INIT_H_QWERTY void timer0_init(void); +void timer1_init(void); #endif