Revision 1:ce391193b822, committed 2011-05-19
- Comitter:
- Wimpie
- Date:
- Thu May 19 18:06:13 2011 +0000
- Parent:
- 0:6468a28a7b7d
- Commit message:
Changed in this revision
--- a/PCD8544LCD.cpp Sun Apr 17 18:03:24 2011 +0000
+++ b/PCD8544LCD.cpp Thu May 19 18:06:13 2011 +0000
@@ -37,6 +37,8 @@
#include "DebugTrace.h"
#include "sstream"
+#include "stdio.h"
+#include "stringman.h"
DebugTrace pc_PCD8544(ON, TO_SERIAL);
@@ -55,7 +57,7 @@
+-------------------------+
| 1 2 3 4 5 6 7 8 |
| # # # # # # # # |
- | ===#=#=#=#=#=#=#=#=== | Red 1 .. VDD - chip power supply +3.3V
+ | ===#=#=#=#=#=#=#=#=== | Red 1 .. VDD - chip power supply +3.3V
+--=====================--+ Green 2 .. SCLK - serial clock line of LCD
| | Yellow 3 .. SI - serial data input of LCD
| | Gray 4 .. D/C - command/data switch
@@ -68,6 +70,7 @@
*/
+
PCD8544LCD::PCD8544LCD (PinName mosi, PinName miso, PinName sck,
PinName cs, PinName data_cmd, PinName reset):
_spi(mosi, miso, sck),
@@ -83,6 +86,7 @@
void PCD8544LCD::init() {
+ pc_PCD8544.traceOut("Init PCD8544\r\n");
_spi.format(8,0);
_spi.frequency(1000000);
@@ -114,8 +118,11 @@
writeCmd(NORMAL_MODE);
- _LoMark = LCD_CACHE_SIZE; // Reset watermark pointers.
- _HiMark = 0;
+
+ _LoMark = 0;
+ _HiMark = LCD_CACHE_SIZE - 1;
+ //_LoMark = LCD_CACHE_SIZE; // Reset watermark pointers.
+ // _HiMark = 0;
cls();
}
@@ -142,13 +149,14 @@
// GRAPHICAL functions
-void PCD8544LCD::cls() {
+void PCD8544LCD::cls(bool fupdate) {
for (int i = 0; i < LCD_CACHE_SIZE ; i++) {
- _LcdCache[i]=0x00;
+ LcdCache[i]=0x00;
}
_LoMark = 0;
_HiMark = LCD_CACHE_SIZE - 1;
- update();
+ if (fupdate)
+ update();
}
void PCD8544LCD::update() {
@@ -166,7 +174,7 @@
writeCmd(SET_ADDRES_Y | (_LoMark / LCD_X_RES));
for (int i = _LoMark; i <= _HiMark; i++ ) {
- writeData( _LcdCache[i]);
+ writeData( LcdCache[i]);
}
_LoMark = LCD_CACHE_SIZE - 1;
_HiMark = 0;
@@ -175,12 +183,12 @@
void PCD8544LCD::locate(BYTE x0, BYTE y0) {
- _LcdCacheIdx = x0*LCD_BANKS + y0 * LCD_X_RES;
+ LcdCacheIdx = x0*LCD_BANKS + y0 * LCD_X_RES;
}
// Bitmap
-void PCD8544LCD::drawBitmap(BYTE x0, BYTE y0, BYTE* bitmap, BYTE bmpXSize, BYTE bmpYSize,BYTE fupdate) {
+void PCD8544LCD::drawBitmap(BYTE x0, BYTE y0, const unsigned char* bitmap, BYTE bmpXSize, BYTE bmpYSize,BYTE fupdate) {
BYTE row;
if (0 == bmpYSize % 8)
@@ -195,7 +203,7 @@
locate(x0, y0);
for (BYTE i = 0; i < bmpXSize; i++) {
- _LcdCache[_LcdCacheIdx+ i]=bitmap[i + (n * bmpXSize)];
+ LcdCache[LcdCacheIdx+ i]=bitmap[i + (n * bmpXSize)];
}
y0++;
}
@@ -203,13 +211,15 @@
update();
}
-void PCD8544LCD::writeString(BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode mode,BYTE fupdate) {
+void PCD8544LCD::writeString(BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode dmode,eSpaceMode smode, BYTE fupdate) {
locate(x0, y0);
chooseFont(font);
while (*string) {
- writeChar(x0,y0,*string++,font, mode, FALSE);
+ writeChar(x0,y0,*string++,font, dmode, FALSE);
x0+=_font_width; // width +1;
+ if (smode==SPACE_NORMAL)
+ x0++;
}
if (fupdate==TRUE)
update();
@@ -336,7 +346,7 @@
index = ((y0 / 8) * LCD_X_RES) + x0;
offset = y0 - ((y0 / 8) * 8);
- data = _LcdCache[index];
+ data = LcdCache[index];
if ( mode == PIXEL_OFF ) {
data &= (~(0x01 << offset));
@@ -345,7 +355,7 @@
} else if ( mode == PIXEL_XOR ) {
data ^= (0x01 << offset);
}
- _LcdCache[index] = data;
+ LcdCache[index] = data;
if ( index < _LoMark ) {
_LoMark = index;
@@ -446,119 +456,130 @@
}
void PCD8544LCD::drawchart(BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE unitx, BYTE unity,
- eRasterMode rmode,signed char * val, int start, int count) {
- BYTE miny,endy,maxy;
-
- drawrectangle(x0,y0-h,x0+w,y0,FILL_OFF,PIXEL_ON,FALSE);
+ eRasterMode rMode, eChartMode cMode,eDrawMode dMode, int16_t * val, int size, int t) {
+ int maxy;
+ int _scale=1;
+ int prescale=1;
- for (int i=0;i<h;i++) {
- if ((i % unity) == 0) {
- drawpixel(x0-2,y0-i,PIXEL_ON,FALSE);
- drawpixel(x0+w+2,y0-i,PIXEL_ON,FALSE);
+ signed char v1,v2;
+ char buffer[4];
- if (rmode==RASTER_ON) {
- for (int r=0;r<w;r++) {
- if ((r % 2) ==0)
- drawpixel(x0+r,y0-i,PIXEL_ON,FALSE);
- }
- }
- }
- if ((i % 2) == 0) {
- drawpixel(x0-1,y0-i,PIXEL_ON,FALSE);
- drawpixel(x0+w+1,y0-i,PIXEL_ON,FALSE);
- }
- }
+ if (size>w)
+ size=w;
- for (int i=0;i<w;i++) {
- if ((i % unitx) == 0) {
- drawpixel(x0+i,y0-1,PIXEL_ON,FALSE);
+ // search maximum value to calculate scale
+ if (dMode==DRAW_OVERWRITE) {
+ maxy=0;
+ for (int i=0; i<size;i++) {
+ if (val[i]>maxy)
+ maxy=val[i];
- if (rmode==RASTER_ON) {
- for (int r=0;r<h;r++) {
- if ((r % 2) ==0)
- drawpixel(x0+i,y0-r,PIXEL_ON,FALSE);
- }
- }
- }
- if ((i % 2) == 0) {
- drawpixel(x0+i,y0+1,PIXEL_ON,FALSE);
- }
- }
-/*
- // clear axis area
- drawrectangle(x0-9,y0-1,x0-3,y0-h,FILL_ON,PIXEL_OFF,FALSE);
- drawrectangle(x0-4,y0+3,x0+w+2,y0+7,FILL_ON,PIXEL_OFF,FALSE);
- */
- //write labels Axis X
+ }
- //draw data values
- //axisy halen uit minimum ans maximum value van timeframe
-
+ if (maxy>h) { //scale can be 1,2,5 *10i
+ prescale= ((maxy-1)/((h/unity)*unity));
+ _scale=1;
+ while (prescale>10) {
+ _scale=_scale*10;
+ prescale=prescale/10;
+ }
+ if (prescale>1)
+ _scale=_scale*5;
+ else
+ if (prescale==1)
+ _scale =_scale*2;
- endy = ((val[start+count] / unity))*unity;
- maxy=0;
- miny =10;
- for ( int i=start; i<start+count-1;i++) {
- if (maxy < ((val[start+count] / unity)+1)*unity)
- maxy=(((val[start+count] / unity)+1)*unity);
- if (miny > ((val[start+count] / unity))*unity)
- miny=((val[start+count] / unity)*unity);
+ }
+ Scale=_scale;
}
- // TODO check this
- // if ((maxy-miny)>h) // problems screen is not high enough
- miny =10; //(h- (maxy-endy));
+ if (dMode==DRAW_OVERWRITE) {
+ drawrectangle(x0-11,y0-h,x0+w,y0+4+7,FILL_ON,PIXEL_OFF,FALSE);
+ drawline(x0,y0,x0,y0-h,PIXEL_ON,FALSE);
+ drawline(x0,y0,x0+w,y0,PIXEL_ON,FALSE);
+
+ //drawrectangle(x0,y0-h,x0+w,y0,FILL_OFF,PIXEL_ON,FALSE);
+
+ for (int i=0;i<=h;i++) {
+ if ((i % unity) == 0) {
+ drawpixel(x0-2,y0-i,PIXEL_ON,FALSE);
+ // drawpixel(x0+w+2,y0-i,PIXEL_ON,FALSE);
- signed char v1,v2;
-
- if (count>w)
- count=w;
+ if (rMode==RASTER_ON) {
+ for (int r=0;r<=w;r++) {
+ if ((r % 2) ==0)
+ drawpixel(x0+r,y0-i,PIXEL_ON,FALSE);
+ }
+ }
+ // draw vertical axis labels
- for (int i=0; i<count-1;i++) {
- v1 = val[i+start]*0.5;
-
-
- /*if ((v1-miny)<=0)
- v1=miny;
+ itostr(buffer,i*Scale);
+
+ // pc_PCD8544.traceOut(" %i %s |",i*Scale,buffer);
+ writeString(x0-11,y0-i+1,buffer,VERYSMALLFONT,NORMAL,SPACE_NONE,FALSE);
- if ((v1-miny)>=h)
- v1=v1*0.5;*/
-
- //pc_PCD8544.traceOut("v1=%i ",v1);
-
- v2 = val[i+start+1]*0.5;
-
- //pc_PCD8544.traceOut("v2=%i",v2);
-/*
- if ((v2-miny)<=0)
- v2=miny;
+ }
+ if ((i % 2) == 0) {
+ drawpixel(x0-1,y0-i,PIXEL_ON,FALSE);
+ // drawpixel(x0+w+1,y0-i,PIXEL_ON,FALSE);
+ }
+ }
+
+ for (int i=0;i<=w;i++) {
+ if (((i+(t % unitx)) % unitx) == 0) {
+ drawpixel(x0+i,y0+2,PIXEL_ON,FALSE);
- if ((v2-miny)>=h)
- v2=h;*/
-
- //drawpixel(x0+i,y0-v1,PIXEL_ON,FALSE);
-
- drawline(x0+i,y0-v1,x0+i+1,y0-v2,PIXEL_ON,FALSE);
+ if (rMode==RASTER_ON) {
+ for (int r=0;r<=h;r++) {
+ if ((r % 2) ==0)
+ drawpixel(x0+i,y0-r,PIXEL_ON,FALSE);
+ }
+ }
+ if (((t-w+i)/unitx)>=0)
+ snprintf(buffer,3,"%i",((t-w+i)/unitx));
+ else
+ snprintf(buffer,3,"%i",24+((t-w+i)/unitx));
+
+ // pc_PCD8544.traceOut(" %i %s ",(t-w+i)/unitx,buffer);
+ writeString(x0+i-3,y0+4,buffer,VERYSMALLFONT,NORMAL,SPACE_NORMAL,FALSE);
+ }
+ if ((i % 2) == 0) {
+ drawpixel(x0+i,y0+1,PIXEL_ON,FALSE);
+ }
+ }
+ // update();
}
- /*
+ for (int i=0;i<size;i++) {
+ // pc_PCD8544.traceOut(" %i ",val[i]);
+ v1 = val[i] / Scale;
+ if (v1>h)
+ v1=h;
- BYTE V;
- char s[2];
+ if (i!=(size-1)) {
+ v2 = val[i+1] / Scale;
+ if (v2>h)
+ v2=h;
+ } else
+ v2=v1;
- for (int i=0;i<unitx;i++){
- V=axisx+i*axisunitx;
- std::string s;
- std::stringstream out;
- out << V;
- s = out.str();
-
- if (B>10)
- writeString(x0-4,0,"Hallo Pieter-Jan",TINYFONT,NORMAL,TRUE);
- }
- }*/
+ switch (cMode) {
+ case C_POINT: {
+ drawpixel(x0+i,y0-v1,PIXEL_ON,FALSE);
+ break;
+ }
+ case C_LINE: {
+ drawline(x0+i,y0-v1,x0+i+1,y0-v2,PIXEL_ON,FALSE);
+ break;
+ }
+ case C_VLINE: {
+ drawline(x0+i,y0-v1,x0+i,y0,PIXEL_ON,FALSE);
+ break;
+ }
+ }
+ }
update();
}
--- a/PCD8544LCD.h Sun Apr 17 18:03:24 2011 +0000
+++ b/PCD8544LCD.h Thu May 19 18:06:13 2011 +0000
@@ -26,11 +26,14 @@
#ifndef PCD8544LCD_H
#define PCD8544LCD_H
+// the Nokia 3310 has a resolution of 84 x 48
+// the Nokia 3410 has a resolution of 102 x 72
+
#include "mbed.h"
/* Number of pixels on the LCD */
-#define LCD_X_RES 84
-#define LCD_Y_RES 48
+#define LCD_X_RES 102 //84
+#define LCD_Y_RES 72 //48
#define LCD_BANKS (LCD_Y_RES / 8)
#define LCD_CACHE_SIZE ((LCD_X_RES * LCD_Y_RES) / 8)
@@ -74,6 +77,12 @@
}eRasterMode;
typedef enum {
+ DRAW_OVERWRITE = 0,
+ DRAW_MERGE = 1
+}eDrawMode;
+
+
+typedef enum {
VERYSMALLFONT = 0, //3x5
TINYFONT = 1, //5x7
SMALLFONT = 2, //6x8
@@ -83,6 +92,19 @@
BIGNUMBERFONT= 6
}eFonts;
+typedef enum {
+ C_POINT = 0, //point
+ C_LINE = 1, //line
+ C_VLINE = 2, //Vertical Line
+ C_HLINE = 3, //Horizontal Line
+}eChartMode;
+
+typedef enum {
+ SPACE_NONE = 0,
+ SPACE_NORMAL = 1
+}eSpaceMode;
+
+
enum eDisplayMode {NORMAL, HIGHLIGHT};
@@ -120,7 +142,7 @@
* clears the cached copy of the screen
* and the screen itself
*/
- void cls();
+ void cls(bool fupdate=true);
/** update()
* copies the cached memory to the screen
@@ -141,14 +163,14 @@
void chooseFont(eFonts font);
- void writeString (BYTE x0, BYTE y0, char* string, eFonts font, eDisplayMode mode, BYTE update);
+ void writeString (BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode dmode,eSpaceMode smode, BYTE fupdate);
void writeChar (BYTE x0, BYTE y0, BYTE ch, eFonts font,eDisplayMode mode, BYTE update);
/** drawBitmap(x,y,bitmap,xsize,ysize)
* draw a monochrome bitmap on position x,y
* with size xsize,ysize
*/
- void drawBitmap (BYTE x0, BYTE y0, BYTE* bitmap, BYTE bmpXSize, BYTE bmpYSize, BYTE update);
+ void drawBitmap (BYTE x0, BYTE y0, const unsigned char* bitmap, BYTE bmpXSize, BYTE bmpYSize, BYTE update);
void drawpixel (BYTE x0, BYTE y0, ePixelMode pmode, BYTE update);
void drawline (BYTE x0, BYTE y0, BYTE x1,BYTE y1, ePixelMode pmode, BYTE update);
@@ -156,7 +178,7 @@
void drawrectangle (BYTE x0, BYTE y0, BYTE x1,BYTE y1, eFillMode fill, ePixelMode pmode, BYTE update);
void drawprogressbar(BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE percentage, BYTE update);
void drawchart (BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE unitx, BYTE unity,
- eRasterMode rmode,signed char * val, int start, int count);
+ eRasterMode rMode, eChartMode cMode, eDrawMode dMode,int16_t * val, int size, int t);
private:
@@ -168,11 +190,12 @@
void writeCmd(BYTE data);
void writeData(BYTE data);
- BYTE _LcdCache[ LCD_CACHE_SIZE ]; // local LCD buffer
+ BYTE LcdCache[LCD_CACHE_SIZE]; // __attribute__((section("AHBSRAM0")));
- int _LcdCacheIdx;
+ int LcdCacheIdx;
int _LoMark;
int _HiMark;
+ int Scale;
BYTE _font_width;
BYTE _font_height;
--- a/fonts/font_3x5.h Sun Apr 17 18:03:24 2011 +0000
+++ b/fonts/font_3x5.h Thu May 19 18:06:13 2011 +0000
@@ -1,20 +1,102 @@
/* *******************************************
* Only numbers in a 3x5 dot format
********************************************* */
-#define FONT3x5_START 0x30
-#define FONT3x5_END 0x39
+#define FONT3x5_START 0x20
+#define FONT3x5_END 0x78
#define FONT3x5_WIDTH 3
#define FONT3x5_HEIGHT 5
static const char font_3x5[] = {
- 0x1F, 0x11, 0x1F, // 0 //0x30
- 0x00, 0x1F, 0x00, // 1 //0x31
- 0x1D, 0x15, 0x17, // 2 //0x32
- 0x15, 0x15, 0x1F, // 3//0x33
- 0x07, 0x04, 0x1F, // 4//0x34
- 0x17, 0x15, 0x1D, // 5//0x35
- 0x1F, 0x14, 0x1C, // 6//0x36
- 0x01, 0x01, 0x1F, // 7//0x37
- 0x1F, 0x15, 0x1F, // 8//0x38
- 0x07, 0x05, 0x1F, // 9//0x39
+
+ 0x00, 0x00, 0x00, // - 0x20
+ 0x00, 0x00, 0x00, // - 0x21
+ 0x00, 0x00, 0x00, // - 0x22
+ 0x00, 0x00, 0x00, // - 0x23
+ 0x00, 0x00, 0x00, // - 0x24
+ 0x00, 0x00, 0x00, // - 0x25
+ 0x00, 0x00, 0x00, // - 0x26
+ 0x00, 0x00, 0x00, // - 0x27
+ 0x00, 0x00, 0x00, // - 0x28
+ 0x00, 0x00, 0x00, // - 0x29
+ 0x00, 0x00, 0x00, // - 0x2A
+ 0x00, 0x00, 0x00, // - 0x2B
+ 0x00, 0x00, 0x00, // - 0x2C
+ 0x04, 0x04, 0x04, // - 0x2D
+ 0x00, 0x04, 0x00, // . 0x2E
+ 0x01, 0x0E, 0x10, // / 0x2F
+ 0x1F, 0x11, 0x1F, // 0 0x30
+ 0x00, 0x1F, 0x00, // 1 0x31
+ 0x1D, 0x15, 0x17, // 2 0x32
+ 0x15, 0x15, 0x1F, // 3 0x33
+ 0x07, 0x04, 0x1F, // 4 0x34
+ 0x17, 0x15, 0x1D, // 5 0x35
+ 0x1F, 0x14, 0x1C, // 6 0x36
+ 0x01, 0x01, 0x1F, // 7 0x37
+ 0x1F, 0x15, 0x1F, // 8 0x38
+ 0x07, 0x05, 0x1F, // 9 0x39
+ 0x18, 0x17, 0x1C, // 0x3A
+ 0x18, 0x17, 0x1C, // 0x3B
+ 0x18, 0x17, 0x1C, // 0x3C
+ 0x18, 0x17, 0x1C, // 0x3D
+ 0x18, 0x17, 0x1C, // 0x3E
+ 0x18, 0x17, 0x1C, // 0x3F
+ 0x18, 0x17, 0x1C, // 0x40
+ 0x18, 0x17, 0x1C, // 0x41
+ 0x18, 0x17, 0x1C, // 0x42
+ 0x18, 0x17, 0x1C, // 0x43
+ 0x18, 0x17, 0x1C, // 0x44
+ 0x18, 0x17, 0x1C, // 0x45
+ 0x18, 0x17, 0x1C, // 0x46
+ 0x18, 0x17, 0x1C, // 0x47
+ 0x18, 0x17, 0x1C, // 0x48
+ 0x18, 0x17, 0x1C, // 0x49
+ 0x18, 0x17, 0x1C, // 0x4A
+ 0x18, 0x17, 0x1C, // 0x4B
+ 0x18, 0x17, 0x1C, // 0x4C
+ 0x18, 0x17, 0x1C, // 0x4D
+ 0x18, 0x17, 0x1C, // 0x4E
+ 0x18, 0x17, 0x1C, // 0x4F
+ 0x18, 0x17, 0x1C, // 0x50
+ 0x18, 0x17, 0x1C, // 0x51
+ 0x18, 0x17, 0x1C, // 0x52
+ 0x18, 0x17, 0x1C, // 0x53
+ 0x18, 0x17, 0x1C, // 0x54
+ 0x18, 0x17, 0x1C, // 0x55
+ 0x18, 0x17, 0x1C, // 0x56
+ 0x18, 0x17, 0x1C, // 0x57
+ 0x18, 0x17, 0x1C, // 0x58
+ 0x18, 0x17, 0x1C, // 0x59
+ 0x18, 0x17, 0x1C, // 0x5A
+ 0x18, 0x17, 0x1C, // 0x5B
+ 0x18, 0x17, 0x1C, // 0x5C
+ 0x18, 0x17, 0x1C, // 0x5D
+ 0x18, 0x17, 0x1C, // 0x5E
+ 0x18, 0x17, 0x1C, // 0x5F
+ 0x18, 0x17, 0x1C, // 0x60
+ 0x18, 0x17, 0x1C, // 0x61
+ 0x18, 0x17, 0x1C, // 0x62
+ 0x18, 0x17, 0x1C, // 0x63
+ 0x18, 0x17, 0x1C, // 0x64
+ 0x18, 0x17, 0x1C, // 0x65
+ 0x18, 0x17, 0x1C, // 0x66
+ 0x18, 0x17, 0x1C, // 0x67
+ 0x18, 0x17, 0x1C, // 0x68
+ 0x18, 0x17, 0x1C, // 0x69
+ 0x18, 0x17, 0x1C, // 0x6A
+ 0x1F, 0x04, 0x0B, // k 0x6B
+ 0x18, 0x17, 0x1C, // 0x6C
+ 0x18, 0x17, 0x1C, // 0x6D
+ 0x18, 0x17, 0x1C, // 0x6E
+ 0x18, 0x17, 0x1C, // 0x6F
+ 0x18, 0x17, 0x1C, // 0x70
+ 0x18, 0x17, 0x1C, // 0x71
+ 0x18, 0x17, 0x1C, // 0x72
+ 0x18, 0x17, 0x1C, // 0x73
+ 0x18, 0x17, 0x1C, // 0x74
+ 0x18, 0x17, 0x1C, // 0x75
+ 0x18, 0x17, 0x1C, // 0x76
+ 0x18, 0x17, 0x1C, // 0x77
+ 0x0A, 0x04, 0x0A // x 0x78
+
+
};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stringman.h Thu May 19 18:06:13 2011 +0000
@@ -0,0 +1,37 @@
+void itostr(char* buffer, int v) {
+ char temp[3];
+
+ //temp="";
+
+ if (v>99999) {
+
+ snprintf(buffer,4,"%3i",v);
+ } else
+
+ if (v>9999) {
+ snprintf(buffer,4,"%3i",v);
+ snprintf(temp,2,"k");
+ buffer[3] = temp[1];
+
+ } else
+
+ if (v>999) {
+
+ snprintf(buffer,4,"%3i",v);
+ buffer[3] = buffer[2];
+ snprintf(temp,2,"k");
+ buffer[2] = temp[1];
+ } else
+ if (v>99) {
+ snprintf(buffer,4,"%3i",v);
+
+ } else
+ if (v>9) {
+ snprintf(buffer,4,"%3i",v);
+
+ } else {
+ snprintf(buffer,4,"%3i",v);
+
+ }
+
+}
\ No newline at end of file