From dd3a06d322ca5ba30de3da66fafacd8cbba820e1 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 31 Oct 2018 23:09:38 +0100 Subject: [avr] Implement set_addr(addr) to control 74LS259 chips --- sw-avr/rom-loader/main.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'sw-avr/rom-loader/main.c') diff --git a/sw-avr/rom-loader/main.c b/sw-avr/rom-loader/main.c index 784afb6..de1dbee 100644 --- a/sw-avr/rom-loader/main.c +++ b/sw-avr/rom-loader/main.c @@ -1,12 +1,11 @@ #include +#include +#include + #include "usart.h" #include "pinmap.h" -// TODO: remove -#include - - inline void io_init(void) { ADDRL_DDR |= (_BV(ADDRL_bitE) | _BV(ADDRL_bitD)); @@ -19,19 +18,48 @@ inline void io_init(void) DATA_DDR = 0xFF; } +inline void set_addr(uint16_t addr) +{ + uint8_t i; + + // disable 74LS259 chips + ADDRL_PORT &= ~(_BV(ADDRL_bitE)); + ADDRH_PORT &= ~(_BV(ADDRH_bitE)); + + for (i = 0; i < 8; i++) { + ADDRL_PORT &= ~(0x7<