Develop a program which conCnuously monitors the dip switches on the Dragon12 an
ID: 3856049 • Letter: D
Question
Develop a program which conCnuously monitors the dip switches on the Dragon12 and echo the switches on #0 7-segment display. USE ASSEMBLY
Explanation / Answer
void buttonCheck(void) { unsigned char temp = PTH & PB_MASK; // only look at bottom switches if (lastButtons != temp) { // new button combination lastButtons = temp; debounce = DEBOUNCE_DELAY; // wait before processing repeat = -1; // signify initial depression repeatDelay = INITIAL_REPEAT_DELAY; return; } if (debounce != 0) { // we are debouncing debounce--; return; } if (temp == (TIME_SW & MINUTE_SW)) { // Minute Time set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; powerOnCheck(); seconds = 0; // reset seconds incrementM(dispt); } } else if (temp == (TIME_SW & HOUR_SW)) { // Hour Time set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; powerOnCheck(); seconds = 0; // reset seconds incrementH(dispt); } } else if (temp == (ALARM_SW & MINUTE_SW)) { // Minute Alarm set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; incrementM(dispa); } } else if (temp == (ALARM_SW & HOUR_SW)) { // Hour Alarm set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; incrementH(dispa); } } else if (temp == TIME_SW) { // Just the Time button powerOnCheck(); } else if (temp == ALARM_SW) { // Just the Alarm button if (repeat < 0) { // don't allow repeats repeat = 0; if (buzzing) { alarmOff(); } else { alarmon2 = (alarmon ^= POINT); } } } } void powerOnCheck(void) { if (dispt[MIN10] == BLANK || dispt[MIN10] == 8) { // clock not set if (PTH & AMPM_SW) { dispt[HOUR10] = BLANK; dispt[HOUR1] = 1; } else { dispt[HOUR10] = 0; dispt[HOUR1] = 1; } dispt[MIN10] = 0; dispt[MIN1] = 0; } } void buttonCheck(void) { unsigned char temp = PTH & PB_MASK; // only look at bottom switches if (lastButtons != temp) { // new button combination lastButtons = temp; debounce = DEBOUNCE_DELAY; // wait before processing repeat = -1; // signify initial depression repeatDelay = INITIAL_REPEAT_DELAY; return; } if (debounce != 0) { // we are debouncing debounce--; return; } if (temp == (TIME_SW & MINUTE_SW)) { // Minute Time set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; powerOnCheck(); seconds = 0; // reset seconds incrementM(dispt); } } else if (temp == (TIME_SW & HOUR_SW)) { // Hour Time set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; powerOnCheck(); seconds = 0; // reset seconds incrementH(dispt); } } else if (temp == (ALARM_SW & MINUTE_SW)) { // Minute Alarm set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; incrementM(dispa); } } else if (temp == (ALARM_SW & HOUR_SW)) { // Hour Alarm set if (repeat > 0) { // waiting for repeat repeat--; } else { repeat = repeatDelay; repeatDelay = REPEAT_DELAY; incrementH(dispa); } } else if (temp == TIME_SW) { // Just the Time button powerOnCheck(); } else if (temp == ALARM_SW) { // Just the Alarm button if (repeat < 0) { // don't allow repeats repeat = 0; if (buzzing) { alarmOff(); } else { alarmon2 = (alarmon ^= POINT); } } } } void powerOnCheck(void) { if (dispt[MIN10] == BLANK || dispt[MIN10] == 8) { // clock not set if (PTH & AMPM_SW) { dispt[HOUR10] = BLANK; dispt[HOUR1] = 1; } else { dispt[HOUR10] = 0; dispt[HOUR1] = 1; } dispt[MIN10] = 0; dispt[MIN1] = 0; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.