diff --git a/plain-avr-keyer.ino b/plain-avr-keyer.ino index 89cb6bc..cd2c048 100644 --- a/plain-avr-keyer.ino +++ b/plain-avr-keyer.ino @@ -137,13 +137,31 @@ static void stop_output(void) OUT_PORT = 0; } -static void do_output(unsigned short on_tick, unsigned short off_tick, unsigned char status) +static void do_dot_output(void) { start_output(); - wait_for_tick(on_tick); + wait_for_tick(DOT_ON_TICK); stop_output(); - wait_for_tick(off_tick); - clear_pin_memory(status); + cli(); + PinMemory &= ~DASH; + sei(); + wait_for_tick(DOT_OFF_TICK); + clear_pin_memory(DOT); +} + +static void do_dash_output(void) +{ + unsigned short n = DASH_ON_TICK / 2; + + start_output(); + wait_for_tick(n); + cli(); + PinMemory &= ~DOT; + sei(); + wait_for_tick(DASH_ON_TICK - n); + stop_output(); + wait_for_tick(DASH_OFF_TICK); + clear_pin_memory(DASH); } void setup(void) @@ -159,9 +177,7 @@ void loop(void) asm __volatile__("sleep"); while (PinMemory) { - if (PinMemory & DOT) - do_output(DOT_ON_TICK, DOT_OFF_TICK, DOT); - if (PinMemory & DASH) - do_output(DASH_ON_TICK, DASH_OFF_TICK, DASH); + if (PinMemory & DOT) do_dot_output(); + if (PinMemory & DASH) do_dash_output(); } }