CT_Lab_2_BitManipulations/bit_manipulations/app/main.c

90 lines
2.3 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
/// 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;
int counted = 0;
/// END: To be programmed
while (1) {
// ---------- Task 3.1 ----------
led_value = read_byte(ADDR_DIP_SWITCH_7_0);
/// STUDENTS: To be programmed
led_value = (led_value | BRIGHT_MASK);
led_value = (led_value & DARK_MASK);
button_value = read_byte(ADDR_BUTTONS);
button_value = button_value & BUTTON_MASK;
if((button_value & T0_MASK) > 0) {
if(counted == 0) {
button_counter = button_counter + 1;
counted = 1;
}
} else {
counted = 0;
}
write_byte(ADDR_LED_15_8, button_counter);
/// 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
}
}