bunnytaur

Untitled

Jan 3rd, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <xs1.h>
  2. #include <timer.h>
  3.  
  4. /*
  5.  * the patterns for each bit are:
  6.  *   0x80000 0x40000 0x20000
  7.  *   0x01000 0x00800 0x00400
  8.  *   0x00200 0x00100 0x00080
  9.  *
  10.  * As the leds go to 3V3, 0x00000 drives all 9 leds on, and 0xE1F80 drives
  11.  * all nine leds off.
  12.  * Add the values from left to right, top to bottom prefixing each value with '~'
  13.  * to turn them on. See example below.
  14.  */
  15.  
  16. #define MODES 10
  17.  
  18. int leds[MODES] = {
  19. 0xE1F80,
  20. /*J*/    ~0x20000 + ~0x01000 + ~0x00400 + ~0x00200 + ~0x00100 + ~0x00080,
  21. 0xE1F80,
  22. /*E*/    ~0x80000 + ~0x40000 + ~0x20000 + ~0x01000 + ~0x00800 + ~0x00200 + ~0x00100 + ~0x00080,
  23. 0xE1F80,
  24. /*N*/    ~0x80000 + ~0x40000 + ~0x20000 + ~0x01000 + ~0x00400 + ~0x00200 + ~0x00080,
  25. 0xE1F80,
  26. /*N*/    ~0x80000 + ~0x40000 + ~0x20000 + ~0x01000 + ~0x00400 + ~0x00200 + ~0x00080,
  27. 0xE1F80,
  28. /*Y*/    ~0x80000 + ~0x20000 + ~0x00800 + ~0x00100
  29. };
  30.  
  31. /* This the port where the leds reside */
  32. port p32 = XS1_PORT_32A;
  33.  
  34. int main(void) {
  35.     int delay = 1000;      // initial delay 50 ms
  36.     int led_counter = 0; // A counter to count through the leds array
  37.     while(1) {
  38.         delay_milliseconds(delay);        // Wait
  39.         //delay += 1;                       // Gradually increase the delay
  40.         p32 <: leds[led_counter];         // Drive the next led pattern
  41.         led_counter++;                    // Pick the next pattern
  42.         if (led_counter == MODES) {       // If we are at the last pattern
  43.             led_counter = 0;              // then wrap around.
  44.         }
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment