Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 15th, 2010  |  syntax: C  |  size: 1.62 KB  |  views: 92  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "embiosapp.h"
  2.  
  3.  
  4. void main();
  5. EMBIOS_APP_HEADER("LCD Test application", 0x1000, main, 127)
  6.  
  7.  
  8. #define LCDSTS       (*((volatile uint32_t*)(0x3860001c)))
  9. #define LCDWCMD      (*((volatile uint32_t*)(0x38600004)))
  10. #define LCDWDAT      (*((volatile uint32_t*)(0x38600040)))
  11. #define PDAT(x)      (*((volatile uint32_t*)(0x3CF00004 + (x) * 16)))
  12.  
  13. static inline void waitlcd()
  14. {
  15.     while (LCDSTS & 0x10);
  16. }
  17.  
  18. static inline void waitlcdread()
  19. {
  20.     while (!(LCDSTS & 1));
  21. }
  22.  
  23. static inline void sendlcdc(int cmd)
  24. {
  25.     waitlcd();
  26.     LCDWCMD = cmd;
  27. }
  28.  
  29. static inline void sendlcd2d(int data)
  30. {
  31.     waitlcd();
  32.     LCDWDAT = data >> 8;
  33.     waitlcd();
  34.     LCDWDAT = data & 0xff;
  35. }
  36.  
  37. volatile bool done;
  38. volatile bool sync;
  39.  
  40. void handler(enum button_event eventtype, int which, int value)
  41. {
  42.     if (eventtype == BUTTON_PRESS)
  43.     {
  44.         if (which == 4) done = true;
  45.         else if (which == 2) sync = false;
  46.         else if (which == 1) sync = true;
  47.     }
  48. }
  49.  
  50. void main()
  51. {
  52.     int i, j;
  53.  
  54.     button_register_handler(handler);
  55.  
  56.     sendlcdc(0x35);
  57.     sendlcd2d(0);
  58.  
  59.     done = false;
  60.     sync = false;
  61.     while (!done)
  62.     {
  63.         for (j = 1; j < 176; j++)
  64.         {
  65.             if (done) break;
  66.             while (sync && !(PDAT(8) & 1)) if (done) break;
  67.             sendlcdc(0x2a);
  68.             sendlcd2d(j - 1);
  69.             sendlcd2d(j);
  70.             sendlcdc(0x2b);
  71.             sendlcd2d(0);
  72.             sendlcd2d(131);
  73.             sendlcdc(0x2c);
  74.             for (i = 0; i < 132; i++)
  75.             {
  76.                 sendlcd2d(0xffff);
  77.                 sendlcd2d(0);
  78.             }
  79.             sleep(50000);
  80.         }
  81.     }
  82.     cputs(3, "Terminated\n");
  83. }
clone this paste RAW Paste Data