56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
#include "CubeRegister.h"
|
|
|
|
CubeRegister CubeRegisterPortB;
|
|
|
|
void CubeRegister::reset() {
|
|
// Port B Pin 8 - 13
|
|
//Serial.println("reset");
|
|
DDRB |= _SER; // _SER als Output
|
|
DDRB |= _OE; // _OE als Output
|
|
DDRB |= _RCLK; // _RCLK als Output
|
|
DDRB |= _SRCLK; // _SRCLK als Output
|
|
DDRB |= _SRCLR; // _SRCLR als Output
|
|
|
|
output_disable();
|
|
clear_register();
|
|
register_to_output();
|
|
// Serial.println(PORTB);
|
|
};
|
|
|
|
void CubeRegister::output_enable() {
|
|
// OUTPUT für OE auf 0 setzen
|
|
PORTB &= ~_OE; // -> LOW
|
|
};
|
|
void CubeRegister::output_disable() {
|
|
// OUTPUT für OE auf 1 setzen
|
|
PORTB |= _OE; //-> HIGH
|
|
};
|
|
|
|
void CubeRegister::clear_register() {
|
|
PORTB |= _SRCLR; // -> HIGH
|
|
PORTB &= ~_SRCLK; // -> LOW
|
|
PORTB &= ~_RCLK; // -> LOW
|
|
PORTB &= ~_SRCLR; // -> LOW
|
|
PORTB &= ~_SRCLR; // -> LOW
|
|
PORTB |= _SRCLR; // -> HIGH
|
|
};
|
|
|
|
void CubeRegister::shift_bit(bool bit) {
|
|
//
|
|
// copy bit to SER (input) of shift regitster
|
|
if (bit == LOW) {
|
|
PORTB &= ~_SER; // -> LOW
|
|
} else {
|
|
PORTB |= _SER; // -> HIGH
|
|
}
|
|
// clock signal for shift registers
|
|
PORTB |= _SRCLK; // -> HIGH
|
|
PORTB &= ~_SRCLK; // -> LOW
|
|
};
|
|
|
|
// copy shift registers to output registers
|
|
void CubeRegister::register_to_output() {
|
|
// clock signal for output registers
|
|
PORTB |= _RCLK; // -> HIGH
|
|
PORTB &= ~_RCLK; // -> LOW
|
|
};
|