Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of KS0108 by
Diff: KS0108.h
- Revision:
- 0:135b9a0a816e
- Child:
- 1:a368f2688222
diff -r 000000000000 -r 135b9a0a816e KS0108.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KS0108.h Tue Jan 04 18:35:28 2011 +0000 @@ -0,0 +1,141 @@ +#ifndef KS0108_H +#define KS0108_H + +#define VERSION 1 + +#include "mbed.h" +#include "SystemFont5x7.h" + +/************************************************************************************/ +// Commands +#define LCD_ON 0x3F +#define LCD_OFF 0x3E +#define LCD_SET_ADD 0x40 +#define LCD_SET_PAGE 0xB8 +#define LCD_DISP_START 0xC0 + +//Controller directives +#define LEFT 1 +#define RIGHT 2 +#define BOTH 3 +#define NONE 4 + +// Colors +#define BLACK 0xFF +#define WHITE 0x00 + +//Screen dimensions +#define SCREEN_HEIGHT 64 +#define SCREEN_WIDTH 128 + +/***********************************************************************************/ + +#define absDiff(x,y) ((x>y) ? (x-y) : (y-x)) +#define swap(a,b) \ +do\ +{\ +uint8_t t;\ + t=a;\ + a=b;\ + b=t;\ +} while(0) + +/**************************************************************************************/ + +#define MAX_IMG_SIZE 128*64 + +typedef struct { + unsigned char imgarray[MAX_IMG_SIZE]; + unsigned int imgWidth; + unsigned int imgHeight; +}Image; + +/**************************************************************************************/ + +// Font Indices +#define FONT_LENGTH 0 +#define FONT_FIXED_WIDTH 2 +#define FONT_HEIGHT 3 +#define FONT_FIRST_CHAR 4 +#define FONT_CHAR_COUNT 5 +#define FONT_WIDTH_TABLE 6 + + +typedef struct { + unsigned int x; + unsigned int y; + unsigned int page; +} LCDCoord; + + +/****************************************************************************************/ + + +class KS0108 { + public: + // Constructor: + KS0108 (PinName _RST,PinName _DI, PinName _RW, PinName _E, PinName _CS1, PinName _CS2, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7); + + void WriteInstruction(unsigned int Command,unsigned int side); + void WriteData(unsigned int data ,unsigned char side); + void WriteDataColPag(unsigned int page, unsigned int col, unsigned int data); + unsigned int ReadData(); + unsigned int ReadStatus(); + void SelectSide(unsigned char side); + void ClearScreen(); + + //Graphic functions + void SetPixel( unsigned int x, unsigned int y, unsigned int color); + + void HLine(unsigned int Xaxis1, unsigned int Xaxis2 ,unsigned int Yaxis,unsigned int color); + void HLineShort(unsigned int Xaxis, unsigned int Yaxis,unsigned int width ,unsigned int color); + void VLine(unsigned int Xaxis, unsigned int Yaxis1 ,unsigned int Yaxis2,unsigned int color); + void VLineShort(unsigned int Xaxis,unsigned int Yaxis, unsigned int height ,unsigned int color); + void Line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2, unsigned int color); + void SlantyLine(unsigned int lX1, unsigned int lY1, unsigned int lX2,unsigned int lY2,unsigned int color); + void DegreeLine(unsigned int x, int y,unsigned int degree,unsigned int inner_radius,unsigned int outer_radius, unsigned int color); + + + void FullRectangle(unsigned int Xaxis1, unsigned int Yaxis1, unsigned int Xaxis2 ,unsigned int Yaxis2,unsigned int color); + void EmptyRectangle(unsigned int Xaxis1,unsigned int Yaxis1, unsigned int Xaxis2,unsigned int Yaxis2,unsigned int color); + void RoundRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int radius, unsigned int color); + + + void EmptyCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); + void FullCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); + void PlotEllipse(long CX, long CY, long XRadius,long YRadius, int color); + void Plot4EllipsePoints(long CX,long CY, long X, long Y, int color); + + void FullScreenBMP (unsigned char *PictureData); + + double dfloor( double value ); + + + // Font Functions + void Putc (int page, int col,unsigned char c); + void PutString(unsigned int x, unsigned int y,char* str); + void PrintFloat(float val, unsigned int x,unsigned int y); + void PrintInteger(int val,unsigned int x,unsigned int y); + + void CursorXY( unsigned int x, unsigned int y); + + + + private: + BusInOut DB; + DigitalOut RST; + DigitalOut DI; + DigitalOut RW; + DigitalOut E; + DigitalInOut CS2; + DigitalInOut CS1; + + unsigned int color; + + unsigned int FontColor; + unsigned int* Font; + LCDCoord Coord; +}; + + +#endif