Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Commit 9e3a4c4

Browse files
committed
Fixed the bug in switching logic, timer is now working properly, LEDs are now disabled when microcontroller is in sleep mode
1 parent 237152f commit 9e3a4c4

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

main.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ HDMI Switcher code for ATmega88PA
2222
#include "switch.h"
2323
#include "eeprom.h"
2424

25-
volatile uint8_t selectedInput;
25+
volatile uint8_t selectedInput = 0x0;
2626
volatile uint8_t timer = 11;
2727

2828
void init(void);
@@ -38,6 +38,8 @@ int main(void) {
3838
outputState = 0x0; // reading failed, revert to default parameters
3939
eeprom_write(outputState); // try to save defaults
4040
}
41+
selectedInput = outputState;
42+
outputState = 0x0;
4143

4244
init();
4345

@@ -85,7 +87,7 @@ void init(void) {
8587
PORTC = 0x0;
8688
DDRD = 0x0; // set PD to input
8789
PORTD = 0x0; // disable pull-ups
88-
PRR = 0xEB; // power reduction
90+
PRR = 0xE7; // power reduction
8991

9092
PCMSK2 = 0x3F; // prepare interrupts for every input pin
9193
PCICR = 0x4; // enable PCINT for PORTD
@@ -97,6 +99,15 @@ void init(void) {
9799
}
98100

99101
void mcu_sleep(void) {
102+
PORTB |= 0xC3; // blink all LEDs
103+
_delay_ms(1000);
104+
PORTB &= ~0xC3;
105+
_delay_ms(100);
106+
PORTB |= 0xC3;
107+
_delay_ms(100);
108+
PORTB &= ~0xC3; // disable LEDs
109+
_delay_ms(100);
110+
100111
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
101112
cli();
102113
sleep_enable();

switch.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ void switch_off(void) {
2525
_delay_ms(10);
2626
PORTC &= ~SW3_OE; // disable SW3_OE
2727
_delay_ms(10);
28+
PORTC &= ~Dx_SEL_MASK; // clear Dx_SEL on all switches
2829
}
2930

3031
void switch_input(uint8_t portConfig, uint8_t coldStart) {
3132
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
3233
if (coldStart == 0) switch_off();
33-
if (portConfig == OFF) PORTC &= ~Dx_SEL_MASK; // clear Dx_SEL on all switches
34-
else {
34+
if (portConfig != OFF) {
3535
PORTC |= (portConfig & Dx_SEL_MASK); // set Dx_SEL on all switches
3636
_delay_ms(500);
3737
PORTC |= (portConfig & SW1_SW2_OE); // enable SWn_OE

0 commit comments

Comments
 (0)