root / Ports / examples / glcdTracer / glcdTracer.pde
History | View | Annotate | Download (1.8 KB)
| 1 | //>>> The latest version of this code can be found at https://github.com/jcw/ !! |
|---|---|
| 2 | |
| 3 | // Very simple "Logic Analyzer", using the Graphics Board as display device. |
| 4 | // 2010-11-20 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php |
| 5 | // $Id: glcdTracer.pde 7763 2011-12-11 01:28:16Z jcw $ |
| 6 | |
| 7 | #include "ST7565.h" |
| 8 | |
| 9 | ST7565 glcd(14, 4, 17, 7); |
| 10 | byte samples[128]; |
| 11 | |
| 12 | static byte get2bits() {
|
| 13 | // bit 1 = AIO2, bit 0 = DIO2 |
| 14 | return (PINC & bit(1)) | bitRead(PIND, 5); |
| 15 | } |
| 16 | |
| 17 | static void sample() {
|
| 18 | memset(samples, 0, sizeof samples); |
| 19 | |
| 20 | // wait for a transition on either input |
| 21 | byte v = get2bits(); |
| 22 | while (get2bits() == v) |
| 23 | ; |
| 24 | |
| 25 | // take 512 2-bit samples using a 128-byte buffer |
| 26 | // first 128 samples in bits 0..1, 2nd in 2..3, etc. |
| 27 | for (byte i = 0; i < 8; i += 2) |
| 28 | for (byte j = 0; j < 128; ++j) {
|
| 29 | samples[j] |= get2bits() << i; |
| 30 | delayMicroseconds(50); // approx 10 KHz |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | void setup () {
|
| 35 | Serial.begin(57600); |
| 36 | Serial.println("\n[glcd_demo]");
|
| 37 | |
| 38 | glcd.st7565_init(); |
| 39 | glcd.st7565_command(CMD_DISPLAY_ON); |
| 40 | glcd.st7565_command(CMD_SET_ALLPTS_NORMAL); |
| 41 | glcd.st7565_set_brightness(0x15); |
| 42 | |
| 43 | digitalWrite(5, 1); // DIO2 pull-up |
| 44 | digitalWrite(15, 1); // AIO2 pull-up |
| 45 | } |
| 46 | |
| 47 | void loop () {
|
| 48 | glcd.clear(); |
| 49 | |
| 50 | // sample quickly with interrupts disabled |
| 51 | cli(); |
| 52 | sample(); |
| 53 | sei(); |
| 54 | |
| 55 | for (byte i = 0; i < 4; ++i) {
|
| 56 | for (byte j = 0; j < 128; ++j) {
|
| 57 | if (bitRead(samples[j], 2*i)) |
| 58 | glcd.drawline(j, 16*i+8, j, 16*i+4, 1); |
| 59 | else |
| 60 | glcd.setpixel(j, 16*i+7, 1); |
| 61 | if (bitRead(samples[j], 2*i+1)) |
| 62 | glcd.drawline(j, 16*i+14, j, 16*i+10, 1); |
| 63 | else |
| 64 | glcd.setpixel(j, 16*i+13, 1); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | glcd.display(); |
| 69 | delay(200); |
| 70 | } |