bunnytaur

Untitled

Jan 3rd, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  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.  * The four patterns below drive a dash, backslash, pipe, and slash.
  13.  */
  14.  
  15. #define MODES 10
  16.  
  17. int leds[MODES] = {
  18. 0xE1F80,
  19. /*J*/    ~0x20000 + ~0x01000 + ~0x00400 + ~0x00200 + ~0x00100 + ~0x00080,
  20. 0xE1F80,
  21. /*E*/    ~0x80000 + ~0x40000 + ~0x20000 + ~0x01000 + ~0x00800 + ~0x00200 + ~0x00100 + ~0x00080,
  22. 0xE1F80,
  23. /*N*/    ~0x80000 + ~0x40000 + ~0x20000 + ~0x01000 + ~0x00400 + ~0x00200 + ~0x00080,
  24. 0xE1F80,
  25. /*N*/    ~0x80000 + ~0x40000 + ~0x20000 + ~0x01000 + ~0x00400 + ~0x00200 + ~0x00080,
  26. 0xE1F80,
  27. /*Y*/    ~0x80000 + ~0x20000 + ~0x00800 + ~0x00100
  28. };
  29.  
  30. /* This the port where the leds reside */
  31. port p32 = XS1_PORT_32A;
  32.  
  33. int main(void) {
  34.     int delay = 1000;      // initial delay 50 ms
  35.     int led_counter = 0; // A counter to count through the leds array
  36.     while(1) {
  37.         delay_milliseconds(delay);        // Wait
  38.         //delay += 1;                       // Gradually increase the delay
  39.         p32 <: leds[led_counter];         // Drive the next led pattern
  40.         led_counter++;                    // Pick the next pattern
  41.         if (led_counter == MODES) {       // If we are at the last pattern
  42.             led_counter = 0;              // then wrap around.
  43.         }
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment