interrupt.ino 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <SPI.h>
  2. #include <GD.h>
  3. #include "rasterinterrupt.h"
  4. #define LINETIME_US 41.6 // time for one raster line in microseconds
  5. #define delayLines(n) delayMicroseconds(int(n * LINETIME_US))
  6. static int line;
  7. #define BLACK
  8. #define RED RGB(255, 0, 0)
  9. void service()
  10. {
  11. delayLines(0.5); // wait half a line: puts us in middle of screen
  12. if (line == 150) {
  13. GD.wr16(BG_COLOR, RGB(255, 0, 0)); // turn red at line 150
  14. line = 170;
  15. } else {
  16. GD.wr16(BG_COLOR, RGB(0, 0, 0)); // turn black at line 170
  17. line = 150;
  18. }
  19. GD.wr16(COMM+0, line); // Set next split line
  20. }
  21. void setup()
  22. {
  23. int i;
  24. GD.begin();
  25. GD.ascii();
  26. GD.putstr(0, 0, "Raster interrupts");
  27. pinMode(2, INPUT); // Arduino reads on pin 2
  28. // JCB-PIN2-A
  29. GD.wr(IOMODE, 'J'); // pin 2 is under microprogram control
  30. // JCB-PIN2-B
  31. line = 150;
  32. GD.wr16(COMM+0, line); // Set first split line
  33. // The raster interrupt microprogram
  34. GD.microcode(rasterinterrupt_code, sizeof(rasterinterrupt_code));
  35. // call 'rising' every time pin 2 rises
  36. attachInterrupt(0, service, RISING);
  37. // Serial.begin(1000000); // JCB
  38. // GD.screenshot(0); // JCB
  39. }
  40. void loop()
  41. {
  42. }