diff options
-rw-r--r-- | src/display.cc | 25 | ||||
-rw-r--r-- | src/display.h | 1 | ||||
-rw-r--r-- | src/main.cc | 3 | ||||
-rw-r--r-- | src/modem.cc | 50 | ||||
-rw-r--r-- | src/modem.h | 1 |
5 files changed, 45 insertions, 35 deletions
diff --git a/src/display.cc b/src/display.cc index 4215983..30a441f 100644 --- a/src/display.cc +++ b/src/display.cc @@ -9,8 +9,6 @@ Display display; -uint8_t teststr[] = {'O', 'h', 'a', 'i', '!', 0}; - void Display::disable() { TIMSK0 &= ~_BV(TOIE0); @@ -30,15 +28,7 @@ void Display::enable() TIMSK0 = _BV(TOIE0); } -/* - * Draws a single display column. This function should be called at least once - * per millisecond. - * - * Current configuration: - * Called every 256 microseconds. The whole display is refreshed every 2048us, - * giving a refresh rate of ~500Hz - */ -ISR(TIMER0_OVF_vect) +void Display::multiplex() { static uint8_t active_col = 0; static uint16_t scroll = 0; @@ -89,3 +79,16 @@ ISR(TIMER0_OVF_vect) } } } + +/* + * Draws a single display column. This function should be called at least once + * per millisecond. + * + * Current configuration: + * Called every 256 microseconds. The whole display is refreshed every 2048us, + * giving a refresh rate of ~500Hz + */ +ISR(TIMER0_OVF_vect) +{ + display.multiplex(); +} diff --git a/src/display.h b/src/display.h index d239e18..6545caa 100644 --- a/src/display.h +++ b/src/display.h @@ -9,6 +9,7 @@ class Display { Display() {}; void enable(void); void disable(void); + void multiplex(void); char string[128]; }; diff --git a/src/main.cc b/src/main.cc index f665e18..9558109 100644 --- a/src/main.cc +++ b/src/main.cc @@ -25,7 +25,8 @@ int main (void) display.string[2] = 'a'; display.string[3] = 'i'; display.string[4] = '!'; - display.string[5] = 0; + display.string[5] = ' '; + display.string[6] = 0; display.enable(); modem.enable(); diff --git a/src/modem.cc b/src/modem.cc index 2eae685..0a89586 100644 --- a/src/modem.cc +++ b/src/modem.cc @@ -45,9 +45,31 @@ uint8_t Modem::buffer_get() { } /* - * Pin Change Interrupt Vector. This is The Modem. + * Start the modem by enabling Pin Change Interrupts & Timer */ -ISR(PCINT3_vect) { +void Modem::enable() { + /* Enable R1 */ + DDRA |= _BV(PA3); + PORTA |= _BV(PA3); + + /* Modem pin as input */ + MODEM_DDR &= ~_BV(MODEM_PIN); + + /* Enable Pin Change Interrupts and PCINT for MODEM_PIN */ + MODEM_PCMSK |= _BV(MODEM_PCINT); + PCICR |= _BV(MODEM_PCIE); + + /* Timer: TCCR1: CS10 and CS11 bits: 8MHz clock with Prescaler 64 = 125kHz timer clock */ + TCCR1B = _BV(CS11) | _BV(CS10); +} + +void Modem::disable() +{ + PORTA &= ~_BV(PA3); + DDRA &= ~_BV(PA3); +} + +void Modem::receive() { /* Static variables instead of globals to keep scope inside ISR */ static uint8_t modem_bit = 0; static uint8_t modem_bitlen = 0; @@ -81,26 +103,8 @@ ISR(PCINT3_vect) { } /* - * Start the modem by enabling Pin Change Interrupts & Timer + * Pin Change Interrupt Vector. This is The Modem. */ -void Modem::enable() { - /* Enable R1 */ - DDRA |= _BV(PA3); - PORTA |= _BV(PA3); - - /* Modem pin as input */ - MODEM_DDR &= ~_BV(MODEM_PIN); - - /* Enable Pin Change Interrupts and PCINT for MODEM_PIN */ - MODEM_PCMSK |= _BV(MODEM_PCINT); - PCICR |= _BV(MODEM_PCIE); - - /* Timer: TCCR1: CS10 and CS11 bits: 8MHz clock with Prescaler 64 = 125kHz timer clock */ - TCCR1B = _BV(CS11) | _BV(CS10); -} - -void Modem::disable() -{ - PORTA &= ~_BV(PA3); - DDRA &= ~_BV(PA3); +ISR(PCINT3_vect) { + modem.receive(); } diff --git a/src/modem.h b/src/modem.h index a37d7d8..afd6aff 100644 --- a/src/modem.h +++ b/src/modem.h @@ -29,6 +29,7 @@ class Modem { uint8_t buffer_get(void); void enable(void); void disable(void); + void receive(void); }; extern Modem modem; |