nsl_cylon
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | nsl_cylon [2013/08/13 12:13] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | The end product of the first [[Eagle Class]] | ||
+ | |||
+ | * [[http:// | ||
+ | * Code is also available on the [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | [[FILE: | ||
+ | |||
+ | http:< | ||
+ | br | ||
+ | < | ||
+ | |||
+ | <a href=" | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <object type=" | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | - if 1 | ||
+ | |||
+ | /* | ||
+ | larson.c | ||
+ | The Larson Scanner | ||
+ | |||
+ | Written by Windell Oskay, http:< | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | An avr-gcc program for the Atmel ATTiny2313 | ||
+ | | ||
+ | | ||
+ | | ||
+ | * EEPROM is used to *correctly* remember last speed & brightness mode. | ||
+ | | ||
+ | * Skinny " | ||
+ | | ||
+ | * EEPROM is used to remember last speed & brightness mode.</ | ||
+ | |||
+ | |||
+ | < | ||
+ | More information about this project is at | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | A makefile is provided to compile and install this program using AVR-GCC and avrdude. | ||
+ | To use it, follow these steps: | ||
+ | 1. Update the header of the makefile as needed to reflect the type of AVR programmer that you use. | ||
+ | 2. Open a terminal window and move into the directory with this file and the makefile. | ||
+ | 3. At the terminal enter | ||
+ | make clean < | ||
+ | make all < | ||
+ | make install < | ||
+ | 4. Make sure that avrdude does not report any errors. | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | < | ||
+ | If you a different programming environment, | ||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | This code should be relatively straightforward, | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | |||
+ | | ||
+ | * / | ||
+ | |||
+ | - include < | ||
+ | - include < | ||
+ | - include < | ||
+ | - include < | ||
+ | - include < | ||
+ | |||
+ | - define shortdelay(); | ||
+ | \\t" \\ | ||
+ | "nop\ | ||
+ | \\t"); | ||
+ | |||
+ | - define TIMER1_PRESCALE_1 \t\t(1) | ||
+ | - define TIMER1_PRESCALE_8 \t\t(2) | ||
+ | - define TIMER1_PRESCALE_64 \t\t(3) | ||
+ | - define TIMER1_PRESCALE_256\t\t(4) | ||
+ | - define TIMER1_PRESCALE_1024\t(5) | ||
+ | |||
+ | uint16_t eepromWord __attribute__((section(" | ||
+ | |||
+ | int main (void) | ||
+ | { | ||
+ | \tuint8_t LEDs[[9]]; // Storage for current LED values | ||
+ | \t | ||
+ | \tint8_t eyeLoc[[5]]; | ||
+ | |||
+ | \tuint8_t LEDBright[[4]] = {1u, | ||
+ | \t | ||
+ | |||
+ | |||
+ | \tint8_t j, m; | ||
+ | \t | ||
+ | \tuint8_t position, loopcount, direction; | ||
+ | \tuint8_t ILED, RLED, MLED; | ||
+ | |||
+ | \tuint8_t delaytime; | ||
+ | \t | ||
+ | \tuint8_t skinnyEye = 0; | ||
+ | \tuint8_t | ||
+ | \tuint8_t \tUpdateConfig; | ||
+ | \tuint8_t BrightMode; | ||
+ | \tuint8_t debounce2, modeswitched; | ||
+ | \t | ||
+ | \tuint8_t CycleCountLow; | ||
+ | \tuint8_t LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8; | ||
+ | \t | ||
+ | \t// | ||
+ | \tMCUSR &= 0xF7; | ||
+ | \tWDTCSR\t= 0x18; | ||
+ | \tWDTCSR\t= 0x00; | ||
+ | |||
+ | \t//Data direction register: DDR's | ||
+ | \t//Port A: 0, 1 are inputs.\t | ||
+ | \t//Port B: 0-3 are outputs, B4 is an input. | ||
+ | \t//Port D: 1-6 are outputs, D0 is an input. | ||
+ | \t | ||
+ | \tDDRA = 0U; | ||
+ | \tDDRB = 15U;\t | ||
+ | \tDDRD = 126U; | ||
+ | \t | ||
+ | \tPORTA = 3;\t// Pull-up resistors enabled, PA0, PA1 | ||
+ | \tPORTB = 16;\t// Pull-up resistor enabled, PA | ||
+ | \tPORTD = 0; | ||
+ | \t\t | ||
+ | < | ||
+ | TCCR1B = (1 << WGM12) | TIMER1_PRESCALE_1; | ||
+ | OCR1A = (uint16_t)800; | ||
+ | TIMSK |= 1 << OCIE1A; | ||
+ | |||
+ | \t/* Visualize outputs: | ||
+ | |||
+ | \t L to R: | ||
+ | |||
+ | \t D2 D3 D4 D5 D6 B0 B1 B2 B3\t | ||
+ | | ||
+ | \t*/ | ||
+ | \t | ||
+ | \t// | ||
+ | |||
+ | \tdebounce = 0; | ||
+ | \tdebounce2 = 0; | ||
+ | \tloopcount = 254; | ||
+ | \tdelaytime = 0; | ||
+ | \t | ||
+ | \tdirection = 0; | ||
+ | \tposition = 0; | ||
+ | \tspeedLevel = 0; // Range: 1, 2, 3 | ||
+ | \tBrightMode = 0; | ||
+ | \tCycleCountLow = 0; | ||
+ | \tUpdateConfig = 0; | ||
+ | \tmodeswitched = 0; | ||
+ | \t | ||
+ | \t | ||
+ | \tif ((PINA & 2) == 0)\t\t// Check if Jumper 1, at location PA1 is shorted | ||
+ | \t{ | ||
+ | \t\t// Optional place to do something. | ||
+ | \t} | ||
+ | \t | ||
+ | \t | ||
+ | \t | ||
+ | \tif ((PINA & 1) == 0)\t\t// Check if Jumper 2, at location PA0 is shorted | ||
+ | \t{ | ||
+ | \t\tskinnyEye = 1; | ||
+ | \t}\t | ||
+ | \t | ||
+ | \t | ||
+ | \tif ((PINB & 16) == 0)\t\t// Check if button pressed pressed down at turn-on | ||
+ | \t{\t\t | ||
+ | |||
+ | \t//Toggle Skinnymode | ||
+ | \t\tif (skinnyEye) | ||
+ | \t\t\tskinnyEye = 0; | ||
+ | \t\telse | ||
+ | \t\t\tskinnyEye = 1; | ||
+ | \t} | ||
+ | \t | ||
+ | \t | ||
+ | \t | ||
+ | \tif (skinnyEye){ | ||
+ | \t\tLEDBright[[0]] = 0; | ||
+ | \t\tLEDBright[[1]] = 4;\t | ||
+ | \t\tLEDBright[[2]] = 1; | ||
+ | \t\tLEDBright[[3]] = 0; | ||
+ | \t} | ||
+ | \t | ||
+ | \t | ||
+ | \t//Check EEPROM values: | ||
+ | \t | ||
+ | \tpt = (uint8_t) (eeprom_read_word(& | ||
+ | \tspeedLevel = pt >> 4; | ||
+ | \tBrightMode = pt & 1; | ||
+ | |||
+ | \tif (pt == 0xFF) | ||
+ | \t{ | ||
+ | \t\tBrightMode = 0; | ||
+ | \t} | ||
+ | \t | ||
+ | \t | ||
+ | \tif (speedLevel > 3) | ||
+ | \t\tspeedLevel = 1; | ||
+ | \t | ||
+ | \tspeedLevel = 0; | ||
+ | |||
+ | \tif ((speedLevel == 2) || (speedLevel == 3)) { | ||
+ | \t\tdelaytime = 0; | ||
+ | \t} | ||
+ | \telse | ||
+ | \t{ | ||
+ | \t\tdelaytime = 1; | ||
+ | \t}\t | ||
+ | \t | ||
+ | \t | ||
+ | \t | ||
+ | for (;;) < | ||
+ | { | ||
+ | |||
+ | |||
+ | \tloopcount++; | ||
+ | \t | ||
+ | \tif (loopcount > delaytime) | ||
+ | \t{ | ||
+ | \t\tloopcount = 0; | ||
+ | \t\t | ||
+ | \t\tCycleCountLow++; | ||
+ | \t\tif (CycleCountLow > 250) | ||
+ | \t\t\tCycleCountLow = 0; | ||
+ | \t\t | ||
+ | \t\t | ||
+ | \t\tif (UpdateConfig){\t\t// | ||
+ | \t\t\tif (CycleCountLow > 100) // Avoid burning EEPROM in event of flaky power connection resets | ||
+ | \t\t\t{ | ||
+ | \t\t\t\t | ||
+ | \t\t\t\tUpdateConfig = 0; | ||
+ | \t\t\t\tpt = (speedLevel << 4) | (BrightMode & 1); | ||
+ | \t\t\t\teeprom_write_word(& | ||
+ | \t\t\t\t// Note: this function causes a momentary brightness glitch while it writes the EEPROM. | ||
+ | \t\t\t\t// We separate out this section to minimize the effect. | ||
+ | \t\t\t} | ||
+ | \t\t\t | ||
+ | \t\t}\t | ||
+ | |||
+ | \t\t | ||
+ | \t\t | ||
+ | \tif ((PINB & 16) == 0)\t\t// Check for button press | ||
+ | \t{ | ||
+ | \t\tdebounce2++; | ||
+ | \t\t | ||
+ | \t\tif (debounce2 > 100) | ||
+ | \t\t{ | ||
+ | \t\t\tif (modeswitched == 0) | ||
+ | \t\t\t{ | ||
+ | \t\t\t\tdebounce2 = 0; | ||
+ | \t\t\t\tUpdateConfig = 1; | ||
+ | |||
+ | \t\t\t\tswitch( BrightMode ) { | ||
+ | \t\t\t\t | ||
+ | \t\t\t\t\t\tcase 0: | ||
+ | \t\t\t\t\t\t\tBrightMode++; | ||
+ | \t\t\t\t\t\tcase 1: | ||
+ | \t\t\t\t\t\t\tBrightMode++; | ||
+ | \t\t\t\t\t\t\tbreak; | ||
+ | \t\t\t\t\t\tcase 2: | ||
+ | \t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\tBrightMode++; | ||
+ | \t\t\t\t\t\t\tbreak; | ||
+ | |||
+ | \t\t\t\t\t\tcase 3: | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\tBrightMode++; | ||
+ | \t\t\t\t\t\t\tbreak; | ||
+ | |||
+ | \t\t\t\t\t\tcase 4: | ||
+ | \t\t\t\t\t\t\tsei(); | ||
+ | \t\t\t\t\t\t\tBrightMode++; | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\tbreak; | ||
+ | \t\t\t\t\t\tcase 5: | ||
+ | \t\t\t\t\t\t\tcli(); | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\tBrightMode = 0 ; | ||
+ | \t\t\t\t\t\t\tbreak; | ||
+ | \t\t\t\t\t\t\t\t | ||
+ | \t\t\t\t\t\tdefault: | ||
+ | \t\t\t\t\t\t\t// | ||
+ | \t\t\t\t\t\t\tBrightMode= 0; | ||
+ | \t\t\t\t\t\t\tbreak; | ||
+ | \t\t\t\t} | ||
+ | \t\t\t\t\t\t\t | ||
+ | \t\t\t\tmodeswitched = 1; | ||
+ | \t\t\t} | ||
+ | \t\t} | ||
+ | \t\telse { | ||
+ | \t\t\tdebounce = 1;\t\t// Flag that the button WAS pressed. | ||
+ | \t\t\tdebounce2++; | ||
+ | \t\t} | ||
+ | |||
+ | \t}\t | ||
+ | \telse{ | ||
+ | \t\t | ||
+ | \t\tdebounce2 = 0; | ||
+ | \t\tmodeswitched = 0; | ||
+ | \t | ||
+ | \t\tif (debounce) | ||
+ | \t\t{ debounce = 0; | ||
+ | \t\t\tspeedLevel++; | ||
+ | \t\t\tUpdateConfig = 1; | ||
+ | \t\t\t | ||
+ | \t\t\tif ((speedLevel == 2) || (speedLevel == 3)) { | ||
+ | \t\t\t\tdelaytime = 0; | ||
+ | \t\t\t} | ||
+ | \t\t\telse | ||
+ | \t\t\t{ | ||
+ | \t\t\t\tdelaytime = 1; | ||
+ | \t\t\t} | ||
+ | \t\t\t | ||
+ | \t\t\tdebounce = 0; | ||
+ | \t\t} | ||
+ | \t\t | ||
+ | \t\t\t} | ||
+ | \t | ||
+ | \t\tposition++; | ||
+ | \t\t | ||
+ | \t\tif (speedLevel == 3) | ||
+ | \t\t\tposition++; | ||
+ | \t\t | ||
+ | \t if (position >= 128)\t// | ||
+ | \t { | ||
+ | \t\t position = 0; | ||
+ | \t\t | ||
+ | \t if (direction == 0) | ||
+ | \t\t direction = 1; | ||
+ | \t else | ||
+ | \t\t direction = 0; | ||
+ | \t } | ||
+ | \t | ||
+ | \t\t \t\t | ||
+ | \tif (direction == 0) // Moving to right, as viewed from front. | ||
+ | \t{ | ||
+ | \t\tILED = (15+position) >> 4; | ||
+ | \t\tRLED = (15+position) - (ILED << 4); | ||
+ | \t\tMLED = 15 - RLED; \t\t | ||
+ | \t\t} | ||
+ | < | ||
+ | else </ | ||
+ | \t{ | ||
+ | \t\tILED = (127 - position) >> 4; | ||
+ | \t\tMLED = (127 - position) | ||
+ | \t\tRLED = 15 - MLED;\t | ||
+ | \t} | ||
+ | \t\t | ||
+ | \t\tj = 0; | ||
+ | \t\twhile (j < 9) { | ||
+ | \t\t\tLEDs[[j]] = 0; | ||
+ | \t\t\tj++; | ||
+ | \t\t} | ||
+ | \t\t | ||
+ | \t\tj = 0; | ||
+ | \t\twhile (j < 5) { | ||
+ | \t\t\t | ||
+ | \t\t\tif (direction == 0) | ||
+ | \t\t\t | ||
+ | \t\t\telse | ||
+ | \t\t\t | ||
+ | \t\t\t | ||
+ | \t\t\tif (m > 8) | ||
+ | \t\t\t\tm -= (2 * (m - 8)); | ||
+ | \t\t\t | ||
+ | \t\t\tif (m < 0) | ||
+ | \t\t\t\tm *= -1; | ||
+ | \t\t\t | ||
+ | \t\t\teyeLoc[[j]] = m; | ||
+ | \t\t\t | ||
+ | \t\t\tj++; | ||
+ | \t\t} | ||
+ | \t\t | ||
+ | \t\tj = 0;\t\t// For each of the eye parts... | ||
+ | \t\twhile (j < 4) { | ||
+ | \t\t\t | ||
+ | \t\t\tLEDs[eyeLoc[j]] | ||
+ | \t\t\tLEDs[eyeLoc[j+1]] += LEDBright[[j]]*MLED; | ||
+ | \t\t\t | ||
+ | \t\t\tj++; | ||
+ | \t\t} | ||
+ | \t | ||
+ | \t LED0 = LEDs[[0]]; | ||
+ | < | ||
+ | LED1 = LEDs[[1]];</ | ||
+ | \t LED2 = LEDs[[2]]; | ||
+ | \t LED3 = LEDs[[3]]; | ||
+ | \t LED4 = LEDs[[4]]; | ||
+ | \t LED5 = LEDs[[5]]; | ||
+ | \t LED6 = LEDs[[6]]; | ||
+ | \t LED7 = LEDs[[7]]; | ||
+ | \t LED8 = LEDs[[8]]; | ||
+ | |||
+ | \t} | ||
+ | |||
+ | \tif ( BrightMode > 3 ) { | ||
+ | \t\tcontinue; | ||
+ | \t} | ||
+ | \t | ||
+ | \tif (BrightMode == 0) | ||
+ | \t{\t\t// | ||
+ | \t\t\t// | ||
+ | \t\tj = 0; | ||
+ | \t\twhile (j < 60)\t\t// Truncate brightness at a max value (60) in the interest of speed. | ||
+ | \t\t{ | ||
+ | \t\t | ||
+ | \tif (LED0 > j) | ||
+ | \t\tPORTD = 4; | ||
+ | \t\t\telse\t | ||
+ | \t\t\tPORTD = 0; | ||
+ | \t\t\t | ||
+ | \tif (LED1 > j) | ||
+ | \t\tPORTD = 8;\t | ||
+ | \telse\t | ||
+ | \t\tPORTD = 0;\t | ||
+ | \t\t\t | ||
+ | \tif (LED2 > j) | ||
+ | \t\tPORTD = 16; | ||
+ | \telse\t | ||
+ | \t\tPORTD = 0; | ||
+ | \t\t\t | ||
+ | \tif (LED3 > j) | ||
+ | \t\tPORTD = 32;\t | ||
+ | \telse\t | ||
+ | \t\tPORTD = 0; | ||
+ | \t\t\t | ||
+ | \tif (LED4 > j) | ||
+ | \t\tPORTD = 64; | ||
+ | \telse\t | ||
+ | \t\tPORTD = 0; | ||
+ | \t\t | ||
+ | \tif (LED5 > j) { | ||
+ | \t\tPORTB = 17;\t | ||
+ | \t\tPORTD = 0;} | ||
+ | \t\t\telse\t{ | ||
+ | \t\tPORTB = 16; | ||
+ | \tPORTD = 0;\t\t} | ||
+ | \t\t\t | ||
+ | \tif (LED6 > j) | ||
+ | \t\tPORTB = 18;\t | ||
+ | \telse\t | ||
+ | \t\tPORTB = 16; | ||
+ | \t\t\t | ||
+ | \tif (LED7 > j) | ||
+ | \t\tPORTB = 20;\t | ||
+ | \telse\t | ||
+ | \t\tPORTB = 16; | ||
+ | \t\t\t | ||
+ | \tif (LED8 > j) | ||
+ | \t\tPORTB = 24;\t | ||
+ | \telse\t | ||
+ | \t\tPORTB = 16; | ||
+ | \t\t | ||
+ | \t\tj++; | ||
+ | < | ||
+ | < | ||
+ | \t\t PORTB = 16; | ||
+ | \t} | ||
+ | \t | ||
+ | \t} | ||
+ | \t else | ||
+ | \t {\t\t// full power routine | ||
+ | \t\t | ||
+ | \t j = 0; | ||
+ | \t while (j < 70) | ||
+ | \t { | ||
+ | \t | ||
+ | \t pt = 0;\t | ||
+ | \t if (LED0 > j) | ||
+ | \t pt = 4; | ||
+ | \t if (LED1 > j) | ||
+ | \t pt |= 8;\t | ||
+ | \t if (LED2 > j) | ||
+ | \t pt |= 16; | ||
+ | \t if (LED3 > j) | ||
+ | \t pt |= 32; | ||
+ | \t if (LED4 > j) | ||
+ | \t pt |= 64; | ||
+ | \t | ||
+ | \t PORTD = pt; | ||
+ | \t shortdelay(); | ||
+ | \t pt = 16;\t | ||
+ | \t if (LED5 > j) | ||
+ | \t pt |= 1;\t | ||
+ | \t if (LED6 > j) | ||
+ | \t pt |= 2;\t | ||
+ | \t if (LED7 > j) | ||
+ | \t pt |= 4;\t | ||
+ | \t if (LED8 > j) | ||
+ | \t pt |= 8;\t\t\t | ||
+ | \t | ||
+ | \t PORTB = pt; | ||
+ | \t shortdelay(); | ||
+ | \t\t | ||
+ | \t j++; | ||
+ | < | ||
+ | < | ||
+ | \t } | ||
+ | \t\t | ||
+ | \t } | ||
+ | \t | ||
+ | \t | ||
+ | < | ||
+ | < | ||
+ | |||
+ | \t}\t//End main loop | ||
+ | \treturn 0; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | - define IS_BIT(a, | ||
+ | - define SET_BIT(a, | ||
+ | - define CLR_BIT(a, | ||
+ | |||
+ | |||
+ | - define LED0 \t\t( 4 )//1 | ||
+ | - define LED1 \t\t( 3 )//2 | ||
+ | - define LED2 \t\t( 2 )//3 | ||
+ | - define LED3 \t\t( 1 )//4 | ||
+ | - define LED4 \t\t( 0 )//5 | ||
+ | |||
+ | < | ||
+ | - define LED5 \t\t( 3 ) | ||
+ | - define LED6 \t\t( 2 ) | ||
+ | - define LED7 \t\t( 1 ) | ||
+ | - define LED8 \t\t( 0 ) | ||
+ | |||
+ | void delay_ms( uint16_t milliseconds) | ||
+ | { | ||
+ | < | ||
+ | for( ; milliseconds > 0; milliseconds--) | ||
+ | { | ||
+ | _delay_ms( 1); | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | - define B9__(x) ((x& | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | +((x& | ||
+ | |||
+ | - define _B9(d) ((uint16_t)B9__(HEX__(d))) | ||
+ | |||
+ | - define B9(d) 0b##d | ||
+ | |||
+ | |||
+ | const static uint16_t large_image[[]] PROGMEM | ||
+ | { | ||
+ | |||
+ | - if 1 | ||
+ | |||
+ | \tB9(000000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(100000001), | ||
+ | \tB9(100000001), | ||
+ | \tB9(000000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(111110001), | ||
+ | \tB9(100010001), | ||
+ | \tB9(100010001), | ||
+ | \tB9(100011111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(001000000), | ||
+ | \tB9(000111000), | ||
+ | \tB9(000000100), | ||
+ | \tB9(000000010), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(100000001), | ||
+ | \tB9(100000001), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(000000000), | ||
+ | \tB9(000000000), | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | \tB9(100010001), | ||
+ | \tB9(100010001), | ||
+ | \tB9(100010001), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(100000001), | ||
+ | \tB9(100000001), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000010001), | ||
+ | |||
+ | |||
+ | \tB9(000010001), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(000011111), | ||
+ | \tB9(000010001), | ||
+ | \tB9(000010001), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(111110001), | ||
+ | \tB9(100010001), | ||
+ | \tB9(100010001), | ||
+ | \tB9(100011111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(100000000), | ||
+ | \tB9(100000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(000000000), | ||
+ | \tB9(111111111), | ||
+ | \tB9(010000000), | ||
+ | \tB9(001110000), | ||
+ | \tB9(000001100), | ||
+ | \tB9(000000010), | ||
+ | \tB9(111111111), | ||
+ | |||
+ | < | ||
+ | |||
+ | - else | ||
+ | |||
+ | < | ||
+ | B9(010101010), | ||
+ | B9(010101010), | ||
+ | B9(101010101), | ||
+ | B9(101010101), | ||
+ | |||
+ | < | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | - endif | ||
+ | | ||
+ | \t0,0,0,0, | ||
+ | \t65535 | ||
+ | }; | ||
+ | |||
+ | |||
+ | < | ||
+ | PGM_P largeimage_p PROGMEM = (PGM_P)large_image; | ||
+ | |||
+ | - define NUM_ELEM(x) (sizeof (x) / sizeof (*(x))) | ||
+ | |||
+ | < | ||
+ | |||
+ | SIGNAL( SIG_TIMER1_COMPA ) { | ||
+ | |||
+ | \tstatic uint8_t j = 0; | ||
+ | \tuint8_t tmpout; | ||
+ | |||
+ | \tuint16_t tmp=0; | ||
+ | |||
+ | < | ||
+ | \tif (pgm_read_word(largeimage_p + j ) == 65535 ) { | ||
+ | \t\tj = 0; | ||
+ | \t} | ||
+ | |||
+ | \ttmp = pgm_read_word(largeimage_p + j); | ||
+ | |||
+ | \ttmpout = 0; | ||
+ | |||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | |||
+ | \tPORTB = ( tmpout | ||
+ | |||
+ | \ttmpout = 0; | ||
+ | |||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | \tif( IS_BIT(tmp, | ||
+ | |||
+ | \tPORTD = tmpout<< | ||
+ | |||
+ | < | ||
+ | \tj+=2; | ||
+ | } | ||
+ | |||
+ | - else | ||
+ | /* | ||
+ | larsonextend.c | ||
+ | The Larson Scanner -- Alternative version to allow scanner to run off the edge of the board. | ||
+ | |||
+ | < | ||
+ | It simulates one LED at brightness 4, followed by one LED of brightness 1, that moves across | ||
+ | the nine pixels, disappearing off either end of the board, before returning to scan in the other direction. | ||
+ | There is no longer any overlap of these " | ||
+ | the head fades in and the tail fades out. | ||
+ | Also, some of the input and output values and pull-up resistors have been changed from the original program | ||
+ | in anticipation of future extensibility. | ||
+ | With the buttons linked between the units, it seems to be flakey, at best, to get an accurate button press | ||
+ | on multiple units at the same time, so that section is commented out below. | ||
+ | | ||
+ | (a permanent installation in an enclosure), the unit was never really intended to change speeds. | ||
+ | get it to work like the original, but couldn' | ||
+ | |||
+ | Original written by Windell Oskay, http:< | ||
+ | New alternative version written by John Breen III | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | An avr-gcc program for the Atmel ATTiny2313 | ||
+ | Based on Version 1.1_alt1, written by Windell Oskay | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | < | ||
+ | More information about this project is at | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | A makefile is provided to compile and install this program using AVR-GCC and avrdude. | ||
+ | To use it, follow these steps: | ||
+ | 1. Update the header of the makefile as needed to reflect the type of AVR programmer that you use. | ||
+ | 2. Open a terminal window and move into the directory with this file and the makefile. | ||
+ | 3. At the terminal enter | ||
+ | make clean < | ||
+ | make all < | ||
+ | make install < | ||
+ | 4. Make sure that avrdude does not report any errors. | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | < | ||
+ | If you a different programming environment, | ||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | This code should be relatively straightforward, | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | |||
+ | | ||
+ | * / | ||
+ | |||
+ | - include < | ||
+ | |||
+ | - define shortdelay(); | ||
+ | \\t" \\ | ||
+ | "nop\ | ||
+ | \\t"); | ||
+ | |||
+ | | ||
+ | int main (void) | ||
+ | { | ||
+ | uint8_t LEDs[[9]]; // Storage for current LED values | ||
+ | uint8_t rightLED[[6]], | ||
+ | \t | ||
+ | int8_t eyeLoc[[5]]; | ||
+ | |||
+ | uint8_t LEDBright[[4]] = {4u, | ||
+ | |||
+ | void delay_ms(uint8_t ms) { | ||
+ | |||
+ | return 0; | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | while (ms != 0) | ||
+ | { | ||
+ | for (i=0; i != delay_count; | ||
+ | ms--; | ||
+ | } | ||
+ | | ||
+ | \t | ||
+ | int8_t j, k, m; | ||
+ | \t | ||
+ | uint8_t position, loopcount, direction, initloopcount, | ||
+ | uint8_t runitout, d_base, a_base, d_mod, a_mod, far_left, far_right; | ||
+ | uint8_t ILED, RLED, MLED;\t// Eye position variables: Integer, Modulo, remainder | ||
+ | |||
+ | uint8_t delaytime; | ||
+ | |||
+ | uint8_t | ||
+ | unsigned int debounce2, BrightMode; | ||
+ | \t | ||
+ | uint8_t LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8; | ||
+ | \t | ||
+ | < | ||
+ | MCUSR &= 0xF7; | ||
+ | WDTCSR\t= 0x18; | ||
+ | WDTCSR\t= 0x00; | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | \t | ||
+ | \tDDRA = 2U; | ||
+ | \tDDRB = 15U;\t | ||
+ | \tDDRD = 126U; | ||
+ | \t | ||
+ | \ta_base = 3; // set a base value (resting value) for PA, to keep things easy to modify | ||
+ | \td_base = 3; // set a base value (resting value) for PD, to keep things easy to modify | ||
+ | \t | ||
+ | \tPORTA = a_base;\t// Pull-up resistor enabled, PA0, Port A1 High | ||
+ | \tPORTB = 16;\t// Pull-up resistor enabled, PB4 | ||
+ | \tPORTD = d_base; | ||
+ | \t | ||
+ | \td_mod = 0; | ||
+ | \ta_mod = 0; | ||
+ | \t | ||
+ | /* Visualize outputs: | ||
+ | |||
+ | < | ||
+ | L to R: | ||
+ | D2 D3 D4 D5 D6 B0 B1 B2 B3\t | ||
+ | < | ||
+ | |||
+ | \t (out to right) D1 --> | ||
+ | | ||
+ | * / | ||
+ | |||
+ | < | ||
+ | |||
+ | \tj = 0; | ||
+ | \twhile (j < 9) { | ||
+ | \t\tLEDs[[j]] = 0; | ||
+ | \t\tj++; | ||
+ | \t} | ||
+ | |||
+ | \t LED0 = LEDs[[0]]; | ||
+ | < | ||
+ | LED1 = LEDs[[1]];</ | ||
+ | \t LED2 = LEDs[[2]]; | ||
+ | \t LED3 = LEDs[[3]]; | ||
+ | \t LED4 = LEDs[[4]]; | ||
+ | \t LED5 = LEDs[[5]]; | ||
+ | \t LED6 = LEDs[[6]]; | ||
+ | \t LED7 = LEDs[[7]]; | ||
+ | \t LED8 = LEDs[[8]]; | ||
+ | \t | ||
+ | < | ||
+ | |||
+ | \tdebounce = 1; | ||
+ | \tdebounce2 = 1; | ||
+ | \tloopcount = 254; | ||
+ | \tinitloopcount = 5; | ||
+ | \tdelaytime = 0; | ||
+ | \t | ||
+ | \tdirection = 0; | ||
+ | \tposition = 0; | ||
+ | \trunitout = 0; | ||
+ | \talready_running = 0; | ||
+ | \tsoftbounce = 0; | ||
+ | \tfar_left = 0; | ||
+ | \tfar_right = 0; | ||
+ | \tspeedLevel = 3; // Range: 1, 2, 3 | ||
+ | \tBrightMode = 0; | ||
+ | |||
+ | if ((PINB & 16) == 0)\t\t// Check if button held on startup; used to verify wiring configuration | ||
+ | \t{ initloopcount = 0; // if so, set the startup loop counter to 0 so that we can watch the startup lights | ||
+ | \t softbounce = 1; // Also set the " | ||
+ | \t}\t | ||
+ | |||
+ | delay_ms(200); | ||
+ | |||
+ | PORTD = 1; < | ||
+ | |||
+ | delay_ms(10); | ||
+ | |||
+ | if ((PIND & 1) == 0) < | ||
+ | \tfar_right = 1; //If D0 and D1 are connected, we're at the end of the chain; set far_right so we bounce back from this end | ||
+ | |||
+ | PORTD = d_base; < | ||
+ | |||
+ | PORTA = 1; < | ||
+ | |||
+ | delay_ms(10); | ||
+ | |||
+ | if ((PINA & 1) == 0) < | ||
+ | \tfar_left = 1; //If A0 and A1 are connected, we're at the end of the chain; set far_left so we bounce back from this end | ||
+ | |||
+ | PORTA = a_base; < | ||
+ | |||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | if (far_left) { | ||
+ | \tleftLED[[0]] = 7; | ||
+ | \tleftLED[[1]] = 11; | ||
+ | \tleftLED[[2]] = 19; | ||
+ | \tleftLED[[3]] = 19; | ||
+ | \tleftLED[[4]] = 19; | ||
+ | \tleftLED[[5]] = 19; | ||
+ | } | ||
+ | else { | ||
+ | \tleftLED[[0]] = 19; | ||
+ | \tleftLED[[1]] = 11; | ||
+ | \tleftLED[[2]] = 7; | ||
+ | \tleftLED[[3]] = 7; | ||
+ | \tleftLED[[4]] = 7; | ||
+ | \tleftLED[[5]] = 7; | ||
+ | } | ||
+ | |||
+ | if (far_right) { | ||
+ | \trightLED[[0]] = 24; | ||
+ | \trightLED[[1]] = 20; | ||
+ | \trightLED[[2]] = 18; | ||
+ | \trightLED[[3]] = 18; | ||
+ | \trightLED[[4]] = 18; | ||
+ | \trightLED[[5]] = 18; | ||
+ | } | ||
+ | else { | ||
+ | \trightLED[[0]] = 18; | ||
+ | \trightLED[[1]] = 20; | ||
+ | \trightLED[[2]] = 24; | ||
+ | \trightLED[[3]] = 24; | ||
+ | \trightLED[[4]] = 24; | ||
+ | \trightLED[[5]] = 24; | ||
+ | } | ||
+ | |||
+ | delay_ms(100); | ||
+ | \t\t\t\t * This is necessary because the clock speeds on each chip only have a 10% tolerance, and initial | ||
+ | \t\t\t\t * testing showed that the tests to configure far_left and far_right were causing | ||
+ | \t\t\t\t * " | ||
+ | \t\t\t\t */ | ||
+ | for (;;) < | ||
+ | { | ||
+ | \tloopcount++; | ||
+ | |||
+ | \tif (loopcount > delaytime) | ||
+ | \t{ | ||
+ | \t\tloopcount = 0; | ||
+ | \t\t | ||
+ | \tif ((PINB & 16) == 0) // Check for button press | ||
+ | \t{ | ||
+ | \t\tif ((initloopcount >= 4) & (far_left == 1) & (already_running == 0)) | ||
+ | \t\t{ | ||
+ | \t\t\trunitout = 1; | ||
+ | \t\t\talready_running = 1; | ||
+ | \t\t\tdebounce = 0; // Start running the program, but only on the left-most unit. | ||
+ | \t\t} | ||
+ | \t\t | ||
+ | /*\tThis is the section from the original program to let the button change the speeds and brightness. | ||
+ | \t\tdebounce2++; | ||
+ | \t\t | ||
+ | \t\tif (debounce2 > 100) | ||
+ | \t\t{ | ||
+ | \t\t\tdebounce = 0; | ||
+ | \t\t\t | ||
+ | \t\t if (BrightMode == 0) | ||
+ | \t\t\tBrightMode = 1; | ||
+ | \t\t else | ||
+ | \t\t\tBrightMode = 0; | ||
+ | \t\t\t | ||
+ | \t\t} | ||
+ | \t\t | ||
+ | \t\tif (debounce) | ||
+ | \t\t{ | ||
+ | \t\t\tspeedLevel++; | ||
+ | \t\t\t | ||
+ | \t\t\tif ((speedLevel == 2) || (speedLevel == 3)) { | ||
+ | \t\t\t\tdelaytime = 0; | ||
+ | \t\t\t} | ||
+ | \t\t\telse | ||
+ | \t\t\t{ | ||
+ | \t\t\t\tdelaytime = 1; | ||
+ | \t\t\t} | ||
+ | \t\t\t | ||
+ | \t\tdebounce = 0; | ||
+ | \t\t} | ||
+ | \t}\t | ||
+ | \telse{ | ||
+ | \tdebounce = 1; | ||
+ | \tdebounce2 = 1; | ||
+ | \t} | ||
+ | * /\t | ||
+ | |||
+ | \t} | ||
+ | \t | ||
+ | \tif ((PINA & 1) == 0) // Check to see if display from the left has triggered to start | ||
+ | \t{ | ||
+ | \t\tdirection = 0; | ||
+ | \t\trunitout = 1; | ||
+ | \t} | ||
+ | \t | ||
+ | \tif ((PIND & 1) == 0) // Check to see if display from the right has triggered to start | ||
+ | \t{ | ||
+ | \t\tdirection = 1; | ||
+ | \t\trunitout = 1; | ||
+ | \t} | ||
+ | |||
+ | \t | ||
+ | \tif (runitout) | ||
+ | \t{ | ||
+ | \t\tposition++; | ||
+ | \t\t | ||
+ | \t\tif (speedLevel == 3) | ||
+ | \t\t\tposition++; | ||
+ | \t\t | ||
+ | \t\tif ((softbounce == 1) & (((direction == 0) & (far_right == 1)) || ((direction == 1) & (far_left == 1))) & (position >= 224)) | ||
+ | \t\t{ // this allows us to " | ||
+ | \t\t\tposition = 15; | ||
+ | \t\t\tif (direction == 0) | ||
+ | \t\t\t\tdirection = 1; | ||
+ | \t\t\telse | ||
+ | \t\t\t\tdirection = 0; | ||
+ | \t\t} | ||
+ | \t\t | ||
+ | \t\tif (position >= 240)\t// To allow for runoff at the ends; was '== 128' | ||
+ | \t\t{ | ||
+ | \t\t\tposition = 0; | ||
+ | \t\t | ||
+ | \t\t\tif (direction == 0) { | ||
+ | \t\t\t\tdirection = 1; // we've reached the end, so go back in the other direction | ||
+ | \t\t\t\tif (far_right == 0) // If this isn't the end of the chain, we want to stop, and wait for a signal to go again | ||
+ | \t\t\t\t\trunitout = 0; | ||
+ | \t\t\t} | ||
+ | \t\t\telse { | ||
+ | \t\t\t\tdirection = 0; | ||
+ | \t\t\t\tif (far_left == 0) // If this isn't the end of the chain, we want to stop, and wait for a signal to go again | ||
+ | \t\t\t\t\trunitout = 0; | ||
+ | \t\t\t} | ||
+ | \t\t} | ||
+ | \t\t \t\t | ||
+ | \tif (direction == 0) // Moving to right, as viewed from front. | ||
+ | \t{ | ||
+ | \t\tILED = (15+position) >> 4; | ||
+ | \t\tRLED = (15+position) - (ILED << 4); | ||
+ | \t\tMLED = 15 - RLED; \t\t | ||
+ | \t} | ||
+ | < | ||
+ | else </ | ||
+ | \t{ | ||
+ | \t\tILED = (127 - position) >> 4; | ||
+ | \t\tMLED = (127 - position) | ||
+ | \t\tRLED = 15 - MLED;\t | ||
+ | \t} | ||
+ | \t | ||
+ | \tif ((ILED == 10) & (direction == 0) & (far_right == 0)) | ||
+ | \t\td_mod = 2; // If we're heading to the right, and we're not at the end of the chain, we want to trigger D1 to start the next scanner | ||
+ | \t\t | ||
+ | \tj = 0; | ||
+ | \twhile (j < 9) { | ||
+ | \t\tLEDs[[j]] = 0; | ||
+ | \t\tj++; | ||
+ | \t} | ||
+ | \t\t | ||
+ | \tj = 0; | ||
+ | \tif ((softbounce == 1) & (((direction == 0) & (far_right == 1)) || ((direction == 1) & (far_left == 1)))) { | ||
+ | \t\twhile (j < 5) { | ||
+ | \t\t\t | ||
+ | \t\t\tif (direction == 0) | ||
+ | \t\t\t | ||
+ | \t\t\t | ||
+ | \t\t\telse | ||
+ | \t\t\t | ||
+ | \t\t\t | ||
+ | \t\t\t | ||
+ | \t\t\tif ((direction == 0) & (m > 8)) | ||
+ | \t\t\t\tm = 8; | ||
+ | \t\t\t | ||
+ | \t\t\tif ((direction == 1) & (m < 0)) | ||
+ | \t\t\t\tm = 0; | ||
+ | \t\t\t | ||
+ | \t\t\teyeLoc[[j]] = m; | ||
+ | \t\t\t | ||
+ | \t\t\tj++; | ||
+ | \t\t} | ||
+ | \t} | ||
+ | \telse { | ||
+ | \t\twhile (j < 5) | ||
+ | \t\t{\t\t | ||
+ | \t\t\tif (direction == 0) | ||
+ | \t\t\t\tm = ILED - (j + 1);\t// e.g., eyeLoc[[0]] = ILED - 1; | ||
+ | \t\t\telse | ||
+ | \t\t\t\tm = ILED + (j + 1); // e.g., eyeLoc[[0]] = ILED + 1; | ||
+ | \t\t\t | ||
+ | \t\t\tif ((m == -1) & (direction == 1) & (far_left == 0)) | ||
+ | \t\t\t\ta_mod = 2; // If we're heading to the left, and we're not at the end of the chain, we want to trigger A1 to start the next scanner | ||
+ | \t\t | ||
+ | \t\t\tif (m > 8) | ||
+ | \t\t\t\tm = -1; // If eye position is past the end of the board, don't light it; set to -1 | ||
+ | \t\t\t\t\t\t | ||
+ | \t\t\tif (m < 0) | ||
+ | \t\t\t\tm = -1; // If eye position is past the end of the board, don't light it; set to -1 | ||
+ | \t\t\t | ||
+ | \t\t\teyeLoc[[j]] = m; | ||
+ | \t\t\t | ||
+ | \t\t\tj++; | ||
+ | \t\t} | ||
+ | \t} | ||
+ | \t\t | ||
+ | \tj = 0;\t\t// For each of the eye parts... | ||
+ | \twhile (j < 4) | ||
+ | \t{\t\t | ||
+ | \t\tif (eyeLoc[[j]] >= 0) | ||
+ | \t\t\tLEDs[eyeLoc[j]] | ||
+ | \t\tif (eyeLoc[[j+1]] >= 0) | ||
+ | \t\t\tLEDs[eyeLoc[j+1]] += LEDBright[[j]]*MLED; | ||
+ | \t\tj++; | ||
+ | \t} | ||
+ | \t | ||
+ | \t LED0 = LEDs[[0]]; | ||
+ | < | ||
+ | LED1 = LEDs[[1]];</ | ||
+ | \t LED2 = LEDs[[2]]; | ||
+ | \t LED3 = LEDs[[3]]; | ||
+ | \t LED4 = LEDs[[4]]; | ||
+ | \t LED5 = LEDs[[5]]; | ||
+ | \t LED6 = LEDs[[6]]; | ||
+ | \t LED7 = LEDs[[7]]; | ||
+ | \t LED8 = LEDs[[8]]; | ||
+ | \t} | ||
+ | \telse if (initloopcount < 4 ) | ||
+ | \t{ | ||
+ | \t\tk = 0; | ||
+ | \t\twhile (k < 6) { | ||
+ | \t\t\tPORTD = leftLED[[k]]; | ||
+ | \t\t\tPORTB = rightLED[[k]]; | ||
+ | \t\t\tdelay_ms(1); | ||
+ | \t\t | ||
+ | \t\t\tPORTD = d_base; | ||
+ | \t\t\tPORTB = 16; | ||
+ | \t\t\tdelay_ms(29); | ||
+ | |||
+ | \t\t\tk++; | ||
+ | \t\t} | ||
+ | \t\tdelay_ms(100); | ||
+ | \t\tinitloopcount++; | ||
+ | \t} | ||
+ | \t} | ||
+ | \tif (runitout) { | ||
+ | \tif (BrightMode == 0) | ||
+ | \t{\t\t// | ||
+ | \t\t\t// | ||
+ | \t\tj = 0; | ||
+ | \t\tPORTA = a_base - a_mod; // we set a_mod to correspond to A1's bit in PORTA; this makes it easier to change the pin configs later | ||
+ | \t\twhile (j < 60)\t\t// Truncate brightness at a max value (60) in the interest of speed. | ||
+ | \t\t{ | ||
+ | \t\t | ||
+ | \tif (LED0 > j) | ||
+ | \t\tPORTD = 7 - d_mod; | ||
+ | \telse\t | ||
+ | \t\tPORTD = d_base - d_mod; | ||
+ | \t\t\t | ||
+ | \tif (LED1 > j) | ||
+ | \t\tPORTD = 11 - d_mod;\t | ||
+ | \telse\t | ||
+ | \t\tPORTD = d_base - d_mod; | ||
+ | \t\t\t | ||
+ | \tif (LED2 > j) | ||
+ | \t\tPORTD = 19 - d_mod; | ||
+ | \telse\t | ||
+ | \t\tPORTD = d_base - d_mod; | ||
+ | \t\t\t | ||
+ | \tif (LED3 > j) | ||
+ | \t\tPORTD = 35 - d_mod;\t | ||
+ | \telse\t | ||
+ | \t\tPORTD = d_base - d_mod; | ||
+ | \t\t\t | ||
+ | \tif (LED4 > j) | ||
+ | \t\tPORTD = 67 - d_mod; | ||
+ | \telse\t | ||
+ | \t\tPORTD = d_base - d_mod; | ||
+ | \t\t | ||
+ | \tif (LED5 > j) { | ||
+ | \t\tPORTB = 17;\t | ||
+ | \t\tPORTD = d_base - d_mod;} | ||
+ | \telse\t{ | ||
+ | \t\tPORTB = 16; | ||
+ | \t\tPORTD = d_base - d_mod;} | ||
+ | \t\t\t | ||
+ | \tif (LED6 > j) | ||
+ | \t\tPORTB = 18;\t | ||
+ | \telse\t | ||
+ | \t\tPORTB = 16; | ||
+ | \t\t\t | ||
+ | \tif (LED7 > j) | ||
+ | \t\tPORTB = 20;\t | ||
+ | \telse\t | ||
+ | \t\tPORTB = 16; | ||
+ | \t\t\t | ||
+ | \tif (LED8 > j) | ||
+ | \t\tPORTB = 24;\t | ||
+ | \telse\t | ||
+ | \t\tPORTB = 16; | ||
+ | \t\t | ||
+ | \t\tj++; | ||
+ | < | ||
+ | < | ||
+ | \t\t PORTB = 16; | ||
+ | \t} | ||
+ | \t | ||
+ | \td_mod = 0; | ||
+ | \ta_mod = 0; | ||
+ | \t} | ||
+ | \t else | ||
+ | \t {\t\t// full power routine | ||
+ | \t | ||
+ | \t PORTA = a_base - a_mod; | ||
+ | |||
+ | \t j = 0; | ||
+ | \t while (j < 70) | ||
+ | \t { | ||
+ | \t | ||
+ | \t | ||
+ | \t pt = d_base - d_mod;\t | ||
+ | \t if (LED0 > j) | ||
+ | \t pt |= 4; | ||
+ | \t if (LED1 > j) | ||
+ | \t pt |= 8;\t | ||
+ | \t if (LED2 > j) | ||
+ | \t pt |= 16; | ||
+ | \t if (LED3 > j) | ||
+ | \t pt |= 32; | ||
+ | \t if (LED4 > j) | ||
+ | \t pt |= 64; | ||
+ | \t | ||
+ | \t PORTD = pt; | ||
+ | \t shortdelay(); | ||
+ | \t pt = 16;\t | ||
+ | \t if (LED5 > j) | ||
+ | \t pt |= 1;\t | ||
+ | \t if (LED6 > j) | ||
+ | \t pt |= 2;\t | ||
+ | \t if (LED7 > j) | ||
+ | \t pt |= 4;\t | ||
+ | \t if (LED8 > j) | ||
+ | \t pt |= 8;\t\t\t | ||
+ | \t | ||
+ | \t PORTB = pt; | ||
+ | \t shortdelay(); | ||
+ | \t\t | ||
+ | \t j++; | ||
+ | < | ||
+ | < | ||
+ | \t } | ||
+ | \t | ||
+ | \t d_mod = 0; // we want to stop triggering D1, so set the modifier of PORTD back to 0 | ||
+ | \t a_mod = 0; // we want to stop triggering A1, so set the modifier of PORTA back to 0 | ||
+ | \t | ||
+ | \t } | ||
+ | \t} | ||
+ | \t | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | PORTA = a_base - a_mod;</ | ||
+ | \t}\t//End main loop | ||
+ | \treturn 0; | ||
+ | } | ||
+ | |||
+ | - endif | ||
+ | \t | ||
+ | </ | ||
nsl_cylon.txt · Last modified: 2013/08/13 12:13 by 127.0.0.1