Skip to content

Commit

Permalink
Merge pull request #4 from yvest/master
Browse files Browse the repository at this point in the history
I've implemented the suggestions I posted on the forum.
  • Loading branch information
ladyada committed Sep 7, 2011
2 parents 95d7a50 + 2a53d0b commit 67212a0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
47 changes: 32 additions & 15 deletions PCD8544.cpp
Expand Up @@ -23,7 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

//#include <Wire.h>
#include <avr/pgmspace.h>
#include <WProgram.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <util/delay.h>
#include <stdlib.h>

Expand Down Expand Up @@ -161,14 +165,22 @@ void PCD8544::drawchar(uint8_t x, uint8_t y, char c) {
if (d & _BV(j)) {
my_setpixel(x+i, y+j, textcolor);
}
else {
my_setpixel(x+i, y+j, !textcolor);
}
}
// pcd8544_buffer[x + (line*LCDWIDTH) ] =
}

for (uint8_t j = 0; j<8; j++) {
my_setpixel(x+5, y+j, !textcolor);
}
updateBoundingBox(x, y, x+5, y + 8);
}

void PCD8544::write(uint8_t c) {
#if defined(ARDUINO) && ARDUINO >= 100
size_t PCD8544::write(uint8_t c) {
#else
void PCD8544::write(uint8_t c) {
#endif
if (c == '\n') {
cursor_y += textsize*8;
cursor_x = 0;
Expand Down Expand Up @@ -377,15 +389,11 @@ uint8_t PCD8544::getPixel(uint8_t x, uint8_t y) {
return (pcd8544_buffer[x+ (y/8)*LCDWIDTH] >> (7-(y%8))) & 0x1;
}


void PCD8544::begin(uint8_t contrast) {
init();
// st7565_command(CMD_DISPLAY_ON);
//st7565_command(CMD_SET_ALLPTS_NORMAL);
//st7565_set_brightness(contrast);
void PCD8544::init(void) {
init(50);
}

void PCD8544::init(void) {
void PCD8544::init(uint8_t contrast) {
// set pin directions
pinMode(_din, OUTPUT);
pinMode(_sclk, OUTPUT);
Expand All @@ -409,15 +417,17 @@ void PCD8544::init(void) {
command(PCD8544_SETBIAS | 0x4);

// set VOP
command( PCD8544_SETVOP | 50); // Experimentally determined
if (contrast > 0x7f)
contrast = 0x7f;

command( PCD8544_SETVOP | contrast); // Experimentally determined


// normal mode
command(PCD8544_FUNCTIONSET);

// turn all the pixels on
command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON);

// Set display to Normal
command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);

// initial display line
// set page address
Expand All @@ -427,6 +437,12 @@ void PCD8544::init(void) {
// set up a bounding box for screen updates

updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
// Push out pcd8544_buffer to the Display (will show the AFI logo)
display();
_delay_ms(1000);
// Clear the display
clear();
display();
}

inline void PCD8544::spiwrite(uint8_t c) {
Expand Down Expand Up @@ -504,6 +520,7 @@ void PCD8544::display(void) {
void PCD8544::clear(void) {
memset(pcd8544_buffer, 0, LCDWIDTH*LCDHEIGHT/8);
updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
cursor_y = cursor_x = 0;
}

/*
Expand Down
14 changes: 11 additions & 3 deletions PCD8544.h
Expand Up @@ -21,7 +21,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <WProgram.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define BLACK 1
#define WHITE 0
Expand Down Expand Up @@ -56,8 +60,8 @@ class PCD8544 : public Print {
PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST);
PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, int8_t RST);

void init(uint8_t contrast);
void init(void);
void begin(uint8_t contrast);

void command(uint8_t c);
void data(uint8_t c);
Expand All @@ -83,7 +87,11 @@ class PCD8544 : public Print {
void setCursor(uint8_t x, uint8_t y);
void setTextSize(uint8_t s);
void setTextColor(uint8_t c);
void write(uint8_t c);
#if defined(ARDUINO) && ARDUINO >= 100
size_t write(uint8_t c);
#else
void write(uint8_t c);
#endif

void drawchar(uint8_t x, uint8_t line, char c);
void drawstring(uint8_t x, uint8_t line, char *c);
Expand Down
4 changes: 2 additions & 2 deletions examples/pcdtest/pcdtest.pde
Expand Up @@ -133,12 +133,12 @@ void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {

void testdrawchar(void) {
for (uint8_t i=0; i < 64; i++) {
nokia.drawchar((i % 14) * 6, i/14, i);
nokia.drawchar((i % 14) * 6, (i/14) * 8, i);
}
nokia.display();
delay(2000);
for (uint8_t i=0; i < 64; i++) {
nokia.drawchar((i % 14) * 6, i/14, i + 64);
nokia.drawchar((i % 14) * 6, (i/14) * 8, i + 64);
}
}

Expand Down

0 comments on commit 67212a0

Please sign in to comment.