interrupt.pde 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. GD.wr(IOMODE, 'J'); // pin 2 is under microprogram control
  29. line = 150;
  30. GD.wr16(COMM+0, line); // Set first split line
  31. // The raster interrupt microprogram
  32. GD.microcode(rasterinterrupt_code, sizeof(rasterinterrupt_code));
  33. // call 'rising' every time pin 2 rises
  34. attachInterrupt(0, service, RISING);
  35. }
  36. void loop()
  37. {
  38. }