129 lines
3.2 KiB
C
129 lines
3.2 KiB
C
/* -----------------------------------------------------------------
|
|
* -- _____ ______ _____ -
|
|
* -- |_ _| | ____|/ ____| -
|
|
* -- | | _ __ | |__ | (___ Institute of Embedded Systems -
|
|
* -- | | | '_ \| __| \___ \ Zurich University of -
|
|
* -- _| |_| | | | |____ ____) | Applied Sciences -
|
|
* -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
|
|
* ------------------------------------------------------------------
|
|
* --
|
|
* -- main.c
|
|
* --
|
|
* -- main for Computer Engineering "Bit Manipulations"
|
|
* --
|
|
* -- $Id: main.c 744 2014-09-24 07:48:46Z ruan $
|
|
* ------------------------------------------------------------------
|
|
*/
|
|
//#include <reg_ctboard.h>
|
|
#include "utils_ctboard.h"
|
|
|
|
#define ADDR_DIP_SWITCH_31_0 0x60000200
|
|
#define ADDR_DIP_SWITCH_7_0 0x60000200
|
|
#define ADDR_LED_31_24 0x60000103
|
|
#define ADDR_LED_23_16 0x60000102
|
|
#define ADDR_LED_15_8 0x60000101
|
|
#define ADDR_LED_7_0 0x60000100
|
|
#define ADDR_BUTTONS 0x60000210
|
|
|
|
// define your own macros for bitmasks below (#define)
|
|
/// STUDENTS: To be programmed
|
|
#define BRIGHT_MASK 0xC0
|
|
#define DARK_MASK 0xCF
|
|
#define BUTTON_MASK 0x0F
|
|
#define T0_MASK 0x01
|
|
#define T1_MASK 0x02
|
|
#define T2_MASK 0x04
|
|
#define T3_MASK 0x08
|
|
|
|
|
|
|
|
/// END: To be programmed
|
|
|
|
int main(void)
|
|
{
|
|
uint8_t led_value = 0;
|
|
|
|
// add variables below
|
|
/// STUDENTS: To be programmed
|
|
uint8_t button_value = 0;
|
|
uint8_t button_counter = 0;
|
|
uint8_t button_counter2 = 0;
|
|
int counted = 0;
|
|
int executed = 0;
|
|
|
|
uint8_t led_23_16_value = 0x00;
|
|
|
|
|
|
|
|
/// END: To be programmed
|
|
|
|
while (1) {
|
|
// ---------- Task 3.1 ----------
|
|
led_value = read_byte(ADDR_DIP_SWITCH_7_0);
|
|
|
|
/// STUDENTS: To be programmed
|
|
/// Task 3.1
|
|
led_value = (led_value | BRIGHT_MASK);
|
|
led_value = (led_value & DARK_MASK);
|
|
|
|
///Task 3.2
|
|
button_value = read_byte(ADDR_BUTTONS);
|
|
button_value = button_value & BUTTON_MASK;
|
|
|
|
if((button_value & T0_MASK) > 0) {
|
|
button_counter = button_counter + 1;
|
|
if(counted == 0) {
|
|
button_counter2 = button_counter2 + 1;
|
|
counted = 1;
|
|
}
|
|
} else {
|
|
counted = 0;
|
|
}
|
|
|
|
/// Task 3.3
|
|
if((button_value & T0_MASK) > 0) {
|
|
if(executed == 0) {
|
|
led_23_16_value = led_23_16_value>>1;
|
|
executed = 1;
|
|
}
|
|
} else if ((button_value & T1_MASK) > 0) {
|
|
if(executed == 0) {
|
|
led_23_16_value = led_23_16_value<<1;
|
|
executed = 1;
|
|
}
|
|
} else if ((button_value & T2_MASK) > 0) {
|
|
if(executed == 0) {
|
|
led_23_16_value = ~ led_23_16_value;
|
|
executed = 1;
|
|
}
|
|
} else if ((button_value & T3_MASK) > 0) {
|
|
if(executed == 0) {
|
|
led_23_16_value = read_byte(ADDR_DIP_SWITCH_7_0);
|
|
executed = 1;
|
|
}
|
|
} else {
|
|
executed = 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
write_byte(ADDR_LED_15_8, button_counter);
|
|
write_byte(ADDR_LED_31_24, button_counter2);
|
|
write_byte(ADDR_LED_23_16, led_23_16_value);
|
|
|
|
|
|
/// END: To be programmed
|
|
|
|
write_byte(ADDR_LED_7_0, led_value);
|
|
|
|
// ---------- Task 3.2 and 3.3 ----------
|
|
/// STUDENTS: To be programmed
|
|
|
|
|
|
|
|
|
|
/// END: To be programmed
|
|
}
|
|
}
|