1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
-
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <stdlib.h>
-
- #include "cube.h"
-
- #ifndef F_CPU
- #define F_CPU 16000000L
- #endif
-
- volatile uint8_t _isrCounter = 0;
- volatile uint8_t **imgBuffer = NULL;
- volatile uint8_t imgFlag = 0;
-
-
- ISR(TIMER1_COMPA_vect) {
- if (_isrCounter < 20) {
- _isrCounter++;
- } else {
- _isrCounter = 0;
- isrCall();
- }
- }
-
- inline void setFet(uint8_t data) {
- data &= ~((1 << 1) | 1);
- PORTD = data;
- data &= ~(3);
- data = data << 3;
- PORTB |= data;
- }
-
-
- inline void selectLatch(uint8_t latchNr) {
- PORTC = 0;
- if (latchNr < 8) {
- PORTC = 1 << latchNr;
- }
- }
-
- inline void setLatch(uint8_t latchNr, uint8_t data) {
- setFet(0);
- selectLatch(latchNr);
- PORTA = data;
- delay_ns(LATCHDELAY);
- selectLatch(8);
- setFet(1 << latchNr);
- }
-
- inline void isrCall(void) {
- static uint8_t layer = 0;
- uint8_t latchCtr = 0;
-
- for (; latchCtr < 8; latchCtr++) {
- setLatch(latchCtr, imgBuffer[layer][latchCtr]);
- }
-
-
- if (layer < 7) {
- layer++;
- } else {
- layer = 0;
- }
- }
-
- inline void delay_ns(int16_t ns) {
-
- for (ns > 0; ns -= 63)
- asm volatile("nop"::);
- }
|