diff --git a/ST7565/ST7565.cpp b/ST7565/ST7565.cpp index 3856208..851ffbf 100644 --- a/ST7565/ST7565.cpp +++ b/ST7565/ST7565.cpp @@ -23,8 +23,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ //#include +#ifdef __AVR__ #include #include +#endif + +#ifndef _delay_ms + #define _delay_ms(t) delay(t) +#endif + +#ifndef _BV + #define _BV(bit) (1<<(bit)) +#endif + + #include #include "ST7565.h" @@ -433,7 +445,22 @@ void ST7565::st7565_init(void) { } inline void ST7565::spiwrite(uint8_t c) { - shiftOut(sid, sclk, MSBFIRST, c); + +#if not defined (_VARIANT_ARDUINO_DUE_X_) && not defined (_VARIANT_ARDUINO_ZERO_) + shiftOut(sid, sclk, MSBFIRST, c); +#else + int8_t i; + for (i=7; i>=0; i--) { + digitalWrite(sclk, LOW); + delayMicroseconds(5); //need to slow down the data rate for Due and Zero + if (c & _BV(i)) + digitalWrite(sid, HIGH); + else + digitalWrite(sid, LOW); + // delayMicroseconds(5); //need to slow down the data rate for Due and Zero + digitalWrite(sclk, HIGH); + } +#endif /* int8_t i; for (i=7; i>=0; i--) { diff --git a/ST7565/examples/gol/gol.pde b/ST7565/examples/gol/gol.pde index d9904d8..44ee924 100644 --- a/ST7565/examples/gol/gol.pde +++ b/ST7565/examples/gol/gol.pde @@ -7,7 +7,7 @@ int ledPin = 13; // LED connected to digital pin 13 // the LCD backlight is connected up to a pin so you can turn it on & off -#define BACKLIGHT_LED 10 +#define BACKLIGHT_LED 4 // pin 9 - Serial data out (SID) // pin 8 - Serial clock out (SCLK) @@ -31,10 +31,12 @@ extern uint8_t st7565_buffer[1024]; void setup() { Serial.begin(9600); - Serial.println(freeRam()); +#ifdef __AVR__ + Serial.print(freeRam()); +#endif pinMode(BACKLIGHT_LED, OUTPUT); - digitalWrite(BACKLIGHT_LED, HIGH); + digitalWrite(BACKLIGHT_LED, LOW); glcd.st7565_init(); glcd.st7565_command(CMD_DISPLAY_ON); @@ -45,7 +47,9 @@ void setup() { glcd.clear(); +#ifdef __AVR__ Serial.println(freeRam()); +#endif // A little of Conway's game of Life drawGabrielsp138(); @@ -58,6 +62,7 @@ void loop() glcd.display(); } +#ifdef __AVR__ // this handy function will return the number of bytes currently free in RAM, great for debugging! int freeRam(void) { @@ -72,6 +77,7 @@ int freeRam(void) } return free_memory; } +#endif // http://www.conwaylife.com/wiki/index.php?title=Gabriel%27s_p138 void drawGabrielsp138() { @@ -136,4 +142,4 @@ void lifeNextGen(ST7565 *g) { } g->setpixel(x-1, y-1, pix); } -} +} \ No newline at end of file diff --git a/ST7565/examples/st7565lcd/st7565lcd.pde b/ST7565/examples/st7565lcd/st7565lcd.pde index 08bef0e..728cf35 100644 --- a/ST7565/examples/st7565lcd/st7565lcd.pde +++ b/ST7565/examples/st7565lcd/st7565lcd.pde @@ -3,7 +3,7 @@ int ledPin = 13; // LED connected to digital pin 13 // the LCD backlight is connected up to a pin so you can turn it on & off -#define BACKLIGHT_LED 10 +#define BACKLIGHT_LED 4 // pin 9 - Serial data out (SID) // pin 8 - Serial clock out (SCLK) @@ -24,11 +24,13 @@ const static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={ void setup() { Serial.begin(9600); +#ifdef __AVR__ Serial.print(freeRam()); - +#endif + // turn on backlight pinMode(BACKLIGHT_LED, OUTPUT); - digitalWrite(BACKLIGHT_LED, HIGH); + digitalWrite(BACKLIGHT_LED, LOW); // initialize and set the contrast to 0x18 glcd.begin(0x18); @@ -93,6 +95,7 @@ void setup() { void loop() {} +#ifdef __AVR__ // this handy function will return the number of bytes currently free in RAM, great for debugging! int freeRam(void) { @@ -107,7 +110,7 @@ int freeRam(void) } return free_memory; } - +#endif #define NUMFLAKES 10 #define XPOS 0 @@ -116,13 +119,13 @@ int freeRam(void) void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { uint8_t icons[NUMFLAKES][3]; - srandom(666); // whatever seed + randomSeed(666); // whatever seed // initialize for (uint8_t f=0; f< NUMFLAKES; f++) { - icons[f][XPOS] = random() % 128; + icons[f][XPOS] = random(128); icons[f][YPOS] = 0; - icons[f][DELTAY] = random() % 5 + 1; + icons[f][DELTAY] = random(5) + 1; } while (1) { @@ -140,9 +143,9 @@ void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { icons[f][YPOS] += icons[f][DELTAY]; // if its gone, reinit if (icons[f][YPOS] > 64) { - icons[f][XPOS] = random() % 128; + icons[f][XPOS] = random(128); icons[f][YPOS] = 0; - icons[f][DELTAY] = random() % 5 + 1; + icons[f][DELTAY] = random(5) + 1; } } } @@ -192,4 +195,4 @@ void testdrawline() { for (uint8_t i=0; i<64; i+=4) { glcd.drawline(127, i, 0, 0, WHITE); } -} +} \ No newline at end of file diff --git a/ST7565/glcdfont.c b/ST7565/glcdfont.c index c2f4509..b52d3e3 100644 --- a/ST7565/glcdfont.c +++ b/ST7565/glcdfont.c @@ -1,9 +1,15 @@ // 5x7 LCD font 'flipped' for the ST7565 - public domain +#ifdef __AVR__ #include #include - -const uint8_t font[] PROGMEM = { +#endif + +#ifndef __AVR__ +#define PROGMEM +#endif + +const unsigned char font[] PROGMEM = { 0x0, 0x0, 0x0, 0x0, 0x0, // Ascii 0 0x7C, 0xDA, 0xF2, 0xDA, 0x7C, //ASC(01) 0x7C, 0xD6, 0xF2, 0xD6, 0x7C, //ASC(02)