First test of keypad software - the LEDs work.
parent
062430e3c2
commit
b36b0ecfd1
|
@ -0,0 +1,102 @@
|
||||||
|
PRG = uart_hello
|
||||||
|
OBJ = main.o
|
||||||
|
PROGRAMMER = buspirate
|
||||||
|
PORT = /dev/ttyACM0
|
||||||
|
MCU_TARGET = atmega8
|
||||||
|
AVRDUDE_TARGET = atmega8
|
||||||
|
OPTIMIZE = -Os
|
||||||
|
DEFS =
|
||||||
|
LIBS =
|
||||||
|
|
||||||
|
HZ = 20000000
|
||||||
|
|
||||||
|
# You should not have to change anything below here.
|
||||||
|
|
||||||
|
CC = avr-gcc
|
||||||
|
|
||||||
|
# Override is only needed by avr-lib build system.
|
||||||
|
|
||||||
|
override CFLAGS = -g -DF_CPU=$(HZ) -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
|
||||||
|
override LDFLAGS = -Wl,-Map,$(PRG).map
|
||||||
|
|
||||||
|
OBJCOPY = avr-objcopy
|
||||||
|
OBJDUMP = avr-objdump
|
||||||
|
|
||||||
|
all: $(PRG).elf lst text #eeprom
|
||||||
|
|
||||||
|
$(PRG).elf: $(OBJ)
|
||||||
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak *.hex *.bin *.srec
|
||||||
|
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
|
||||||
|
|
||||||
|
lst: $(PRG).lst
|
||||||
|
|
||||||
|
%.lst: %.elf
|
||||||
|
$(OBJDUMP) -h -S $< > $@
|
||||||
|
|
||||||
|
# Rules for building the .text rom images
|
||||||
|
|
||||||
|
text: hex bin srec
|
||||||
|
|
||||||
|
hex: $(PRG).hex
|
||||||
|
bin: $(PRG).bin
|
||||||
|
srec: $(PRG).srec
|
||||||
|
|
||||||
|
%.hex: %.elf
|
||||||
|
$(OBJCOPY) -j .text -j .data -O ihex $< $@
|
||||||
|
|
||||||
|
%.srec: %.elf
|
||||||
|
$(OBJCOPY) -j .text -j .data -O srec $< $@
|
||||||
|
|
||||||
|
%.bin: %.elf
|
||||||
|
$(OBJCOPY) -j .text -j .data -O binary $< $@
|
||||||
|
|
||||||
|
# Rules for building the .eeprom rom images
|
||||||
|
|
||||||
|
eeprom: ehex ebin esrec
|
||||||
|
|
||||||
|
|
||||||
|
ehex: $(PRG)_eeprom.hex
|
||||||
|
#ebin: $(PRG)_eeprom.bin
|
||||||
|
esrec: $(PRG)_eeprom.srec
|
||||||
|
|
||||||
|
%_eeprom.hex: %.elf
|
||||||
|
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
|
||||||
|
|
||||||
|
#%_eeprom.srec: %.elf
|
||||||
|
# $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
|
||||||
|
|
||||||
|
%_eeprom.bin: %.elf
|
||||||
|
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
|
||||||
|
|
||||||
|
|
||||||
|
# command to program chip (invoked by running "make install")
|
||||||
|
install: $(PRG).hex
|
||||||
|
avrdude -p $(AVRDUDE_TARGET) -c $(PROGRAMMER) -P $(PORT) -v \
|
||||||
|
-U flash:w:$(PRG).hex
|
||||||
|
# hack: turn on the buspirate PSU
|
||||||
|
echo -e "m5\n\n\n\n\n\n\n\nW" > /dev/ttyACM0
|
||||||
|
|
||||||
|
fuse:
|
||||||
|
avrdude -p $(AVRDUDE_TARGET) -c $(PROGRAMMER) -P $(PORT) -v \
|
||||||
|
-U lfuse:w:0xc6:m -U hfuse:w:0xd9:m
|
||||||
|
|
||||||
|
ddd: gdbinit
|
||||||
|
ddd --debugger "avr-gdb -x $(GDBINITFILE)"
|
||||||
|
|
||||||
|
gdbserver: gdbinit
|
||||||
|
simulavr --device $(MCU_TARGET) --gdbserver
|
||||||
|
|
||||||
|
gdbinit: $(GDBINITFILE)
|
||||||
|
|
||||||
|
$(GDBINITFILE): $(PRG).hex
|
||||||
|
@echo "file $(PRG).elf" > $(GDBINITFILE)
|
||||||
|
|
||||||
|
@echo "target remote localhost:1212" >> $(GDBINITFILE)
|
||||||
|
@echo "load" >> $(GDBINITFILE)
|
||||||
|
@echo "break main" >> $(GDBINITFILE)
|
||||||
|
@echo
|
||||||
|
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
/////////////////////
|
||||||
|
// I/O ports setup //
|
||||||
|
/////////////////////
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
volatile uint8_t *DDR;
|
||||||
|
volatile uint8_t *PORT;
|
||||||
|
volatile uint8_t *PIN;
|
||||||
|
uint8_t Bitmap;
|
||||||
|
} TIOPort;
|
||||||
|
|
||||||
|
#define DECLARE_IO(name, port, bit) TIOPort g_IO_##name = { &DDR##port, &PORT##port, &PIN##port, (1 << bit) }
|
||||||
|
#define IO_SET_OUTPUT(name) do { *g_IO_##name.DDR |= g_IO_##name.Bitmap; } while(0)
|
||||||
|
#define IO_SET_INPUT(name) do { *g_IO_##name.DDR &= ~g_IO_##name.Bitmap; } while(0)
|
||||||
|
#define IO_INPUT_PULLUP(name) do { *g_IO_##name.PORT |= g_IO_##name.Bitmap; } while(0)
|
||||||
|
|
||||||
|
#define IO_OUT(name, value) do { if (value) \
|
||||||
|
*g_IO_##name.PORT |= g_IO_##name.Bitmap; \
|
||||||
|
else \
|
||||||
|
*g_IO_##name.PORT &= ~g_IO_##name.Bitmap; } while(0)
|
||||||
|
#define IO_TOGGLE(name) do { *g_IO_##name.PORT ^= g_IO_##name.Bitmap; } while(0)
|
||||||
|
#define IO_IN(name) (*g_IO_##name.PIN & g_IO_##name.Bitmap)
|
||||||
|
|
||||||
|
// Buzzer on PC2
|
||||||
|
DECLARE_IO(BUZZER, C, 2);
|
||||||
|
// Red LED pn PC1
|
||||||
|
DECLARE_IO(LED_RED, C, 1);
|
||||||
|
// Green LED on PC0
|
||||||
|
DECLARE_IO(LED_GREEN, C, 0);
|
||||||
|
|
||||||
|
// Keypad
|
||||||
|
DECLARE_IO(KPAD_COL3, D, 0);
|
||||||
|
DECLARE_IO(KAPD_ROW3, D, 1);
|
||||||
|
DECLARE_IO(KPAD_COMMON, D, 2);
|
||||||
|
DECLARE_IO(KPAD_COL2, D, 3);
|
||||||
|
DECLARE_IO(KPAD_ROW1, D, 4);
|
||||||
|
DECLARE_IO(KPAD_ROW2, D, 5);
|
||||||
|
DECLARE_IO(KPAD_ROW4, D, 6);
|
||||||
|
DECLARE_IO(KPAD_COL1, D, 7);
|
||||||
|
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
// Setup outputs
|
||||||
|
IO_SET_OUTPUT(BUZZER);
|
||||||
|
IO_SET_OUTPUT(LED_RED);
|
||||||
|
IO_SET_OUTPUT(LED_GREEN);
|
||||||
|
|
||||||
|
IO_OUT(LED_GREEN, 1);
|
||||||
|
IO_OUT(LED_RED, 1);
|
||||||
|
|
||||||
|
for (;;) {}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue