diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-11-29 17:55:13 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-11-29 17:58:09 +0100 |
commit | 3e02a4455157422eebfc718bbbc66b0c7ea16d2e (patch) | |
tree | a144802a18f6090fed3bf20cfe9a9b594ce092a7 /src/testapp1 | |
parent | 679a15419631545dfd72c2cecb5385f74ecca0d3 (diff) | |
download | renard_hb9hi-3e02a4455157422eebfc718bbbc66b0c7ea16d2e.tar.gz renard_hb9hi-3e02a4455157422eebfc718bbbc66b0c7ea16d2e.tar.bz2 renard_hb9hi-3e02a4455157422eebfc718bbbc66b0c7ea16d2e.zip |
Fix morse routine, add LED output
Diffstat (limited to 'src/testapp1')
-rw-r--r-- | src/testapp1/Makefile | 4 | ||||
-rw-r--r-- | src/testapp1/main.c | 22 | ||||
-rw-r--r-- | src/testapp1/morse.c | 14 | ||||
-rw-r--r-- | src/testapp1/morse.h | 12 |
4 files changed, 35 insertions, 17 deletions
diff --git a/src/testapp1/Makefile b/src/testapp1/Makefile index 98dcc23..68c15e9 100644 --- a/src/testapp1/Makefile +++ b/src/testapp1/Makefile @@ -24,7 +24,7 @@ BUILD_DIR=build APP_NAME = testapp1 # Application object files -APP_OBJECTS = main.o +APP_OBJECTS = main.o morse.o # Library object files to build and use LIB_OBJECTS = @@ -92,7 +92,7 @@ clean: rm -rf build # Send to device -program: $(BUILD_DIR)/$(APP_HEX) +program: $(APP_HEX) $(SIZE) -C $(BUILD_DIR)/$(APP_ELF) $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U flash:w:$(BUILD_DIR)/$(APP_HEX) -v diff --git a/src/testapp1/main.c b/src/testapp1/main.c index c266684..b305372 100644 --- a/src/testapp1/main.c +++ b/src/testapp1/main.c @@ -4,8 +4,11 @@ #include <avr/interrupt.h> #include "delay.h" +#include "morse.h" + #define PORTB_PTT (1 << 0) +#define PORTB_LED (1 << 4) volatile uint8_t Timer; /* Timer (100Hz increment) */ @@ -31,13 +34,12 @@ static int inittimer(void) return 0; } -#define DIT_DURATION 100 // ms #define PTT_LOGIC_LOW 0 #if PTT_LOGIC_LOW void dah(void) { - PORTB = 0; // PTT is inverted logic + PORTB = PORTB_LED; // LED is non-inverted logic delay_ms(3*DIT_DURATION); PORTB = PORTB_PTT; // PTT is inverted logic @@ -46,7 +48,7 @@ void dah(void) void dit(void) { - PORTB = 0; // PTT is inverted logic + PORTB = PORTB_LED; // LED is non-inverted logic delay_ms(DIT_DURATION); PORTB = PORTB_PTT; // PTT is inverted logic @@ -55,7 +57,7 @@ void dit(void) #else void dah(void) { - PORTB = PORTB_PTT; + PORTB = PORTB_PTT | PORTB_LED; delay_ms(3*DIT_DURATION); PORTB = 0; @@ -64,7 +66,7 @@ void dah(void) void dit(void) { - PORTB = PORTB_PTT; + PORTB = PORTB_PTT | PORTB_LED; delay_ms(DIT_DURATION); PORTB = 0; @@ -72,21 +74,19 @@ void dit(void) } #endif -#include "morse.c" - int main(void) { /* Enable PTT output on PB0 */ - PORTB = PORTB_PTT; #if PTT_LOGIC_LOW - DDRB = PORTB_PTT; -#else - DDRB = 0; + PORTB = PORTB_PTT; #endif + /* LED is never inverted */ + DDRB = PORTB_PTT | PORTB_LED; /* initialise timer interrupt */ inittimer(); + delay_ms(12*DIT_DURATION); morse("HB9EGM"); delay_ms(12*DIT_DURATION); diff --git a/src/testapp1/morse.c b/src/testapp1/morse.c index a448a4b..cb06b4a 100644 --- a/src/testapp1/morse.c +++ b/src/testapp1/morse.c @@ -1,3 +1,11 @@ +#include <stdio.h> +#include <avr/pgmspace.h> +#include <avr/io.h> +#include <avr/interrupt.h> + +#include "delay.h" +#include "morse.h" + const uint8_t morse_mapping[60] PROGMEM = { // Read bits from right to left @@ -69,10 +77,6 @@ void morse_symbol(uint8_t sym) while((val >> p) != 0b1) { - if (p != 0) { - delay_ms(2 * DIT_DURATION); - } - if (((val >> p) & 0b1) == 0b1) { dit(); } @@ -82,6 +86,8 @@ void morse_symbol(uint8_t sym) p++; } + + delay_ms(4*DIT_DURATION); } // Transmit a string in morse code. Supported range: diff --git a/src/testapp1/morse.h b/src/testapp1/morse.h new file mode 100644 index 0000000..68cebb1 --- /dev/null +++ b/src/testapp1/morse.h @@ -0,0 +1,12 @@ +#ifndef __MORSE_H_ +#define __MORSE_H_ + +#define DIT_DURATION 100 // ms + +void morse(char* text); + +void dah(void); +void dit(void); + +#endif + |