From 15c681c7e38f762fb416e98f01d3f3aca5b39911 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Wed, 30 Nov 2011 19:21:11 +0100 Subject: [PATCH] A simple test program to simulate the bitshifting in the ISR. --- firmware/isr_test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 firmware/isr_test.c diff --git a/firmware/isr_test.c b/firmware/isr_test.c new file mode 100644 index 0000000..c77a6ab --- /dev/null +++ b/firmware/isr_test.c @@ -0,0 +1,52 @@ + +#include +#include +#include + +int main (void) +{ + int PORTD = 0xff; + int PORTB = 0xff; + int cube = 0x000001ff; + int cube_level = 0; + + char test[100]; + + int i = 0; + for (i = 0; i < 3; i++) + { + + printf("-----------------\ncube_level = %d\n",cube_level); + + printf("PORTD = 0x%2x\n", PORTD); + printf("PORTB = 0x%2x\n", PORTB); + + PORTD &= 0x87; // 0x87 = 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren + + printf("& 0b10000111: PORTD = 0x%2x\n", PORTD); + + PORTD |= ((1 << cube_level)<< 3); // cube_level setzen (Ebene A=0, B=1, C=2) + + printf("Level festlegen: PORTD = 0x%2x\n", PORTD); + + int tmp = cube_level * 9; + + printf("8 Bits aus cube: PORTD = 0x%2x\n", ((~cube & (0xff << tmp)) >> tmp)); + // PORTB = 1..8 + // 0 = leuchtet, 1 = leuchtet nicht (invertiert!) + PORTB = ((~cube & (0xff << tmp)) >> tmp); + + printf("Pins1-8: PORTB = 0x%2x\n", PORTB); + + // PORTD &= 0b10111111; // bereits oben erledigt + PORTD |= (((~cube & (1 << (tmp+8))) >> (tmp+8)) << 6); + + printf("Pin9: PORTD = 0x%2x\n", PORTD); + + cube_level++; + if (cube_level > 2) cube_level = 0; + + } + +} +