This is the debugged version of this driver.

Dependencies:   mbed

Committer:
andrewcrussell
Date:
Thu Nov 21 04:09:29 2013 +0000
Revision:
0:901166f03471
This version of the SDD1963 works and has been debugged

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewcrussell 0:901166f03471 1 /***********************************************************************************/
andrewcrussell 0:901166f03471 2 /***** Newhaven NHD-5.7-640480WF-CTXL# Display Driver **********/
andrewcrussell 0:901166f03471 3 /***** for mbed (www.mbed,org) NXP LPC1768 32 bit ARM MCU ******/
andrewcrussell 0:901166f03471 4 /********* Adapted by Andrew C. Russell, March 2011 ***********/
andrewcrussell 0:901166f03471 5
andrewcrussell 0:901166f03471 6 /************I hereby acknowledge and thank the following ******/
andrewcrussell 0:901166f03471 7 /***software authors whose code I have adapted and/or adopted***/
andrewcrussell 0:901166f03471 8 /*******************to create these drivers:- ******************/
andrewcrussell 0:901166f03471 9
andrewcrussell 0:901166f03471 10 //Curt Lagerstam - Newhaven Display International, LLC for the dispay initialization.
andrewcrussell 0:901166f03471 11 //James P Lynch - code adapted from his Nokia LCD display tutorial at
andrewcrussell 0:901166f03471 12 //http://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdf
andrewcrussell 0:901166f03471 13 //Akifumi 'Tedd' Okano for assistance and adapting the .bmp display driver
andrewcrussell 0:901166f03471 14 /***********************************************************************************/
andrewcrussell 0:901166f03471 15
andrewcrussell 0:901166f03471 16 #include "mbed.h"
andrewcrussell 0:901166f03471 17 #include "font.h"
andrewcrussell 0:901166f03471 18 #include "stdlib.h"
andrewcrussell 0:901166f03471 19 #include "string.h"
andrewcrussell 0:901166f03471 20
andrewcrussell 0:901166f03471 21
andrewcrussell 0:901166f03471 22 /***********************************************************************************/
andrewcrussell 0:901166f03471 23 /********************************** Colors *****************************************/
andrewcrussell 0:901166f03471 24 /********* taken directly from http://web.njit.edu/~kevin/rgb.txt.html**************/
andrewcrussell 0:901166f03471 25 #define BLACK 0x000000
andrewcrussell 0:901166f03471 26 #define WHITE 0xFFFFFF
andrewcrussell 0:901166f03471 27 #define BLACK 0x000000
andrewcrussell 0:901166f03471 28 #define RED 0xFF0000
andrewcrussell 0:901166f03471 29 #define GREEN 0x00FF00
andrewcrussell 0:901166f03471 30 #define BLUE 0x0000FF
andrewcrussell 0:901166f03471 31 #define GREY 0xBEBEBE
andrewcrussell 0:901166f03471 32 #define DEEPINK 0xFF1493
andrewcrussell 0:901166f03471 33
andrewcrussell 0:901166f03471 34 #define PASET 0x2B
andrewcrussell 0:901166f03471 35 #define CASET 0x2A
andrewcrussell 0:901166f03471 36 #define DISON 0x29
andrewcrussell 0:901166f03471 37 #define DISOFF 0x28
andrewcrussell 0:901166f03471 38 #define DEEPSLEEP 0xE5
andrewcrussell 0:901166f03471 39 #define RAMWR 0x2C
andrewcrussell 0:901166f03471 40 #define RAMCT 0x3C
andrewcrussell 0:901166f03471 41 #define RESET 0x01
andrewcrussell 0:901166f03471 42 #define DISINV 0x21
andrewcrussell 0:901166f03471 43 #define DISNOR 0x20
andrewcrussell 0:901166f03471 44 #define NOP 0x00
andrewcrussell 0:901166f03471 45 #define XMAX 640
andrewcrussell 0:901166f03471 46 #define YMAX 480
andrewcrussell 0:901166f03471 47 #define TRUE 1
andrewcrussell 0:901166f03471 48
andrewcrussell 0:901166f03471 49 // Font sizes
andrewcrussell 0:901166f03471 50 #define SMALL 0
andrewcrussell 0:901166f03471 51 #define MEDIUM 1
andrewcrussell 0:901166f03471 52 #define LARGE 2
andrewcrussell 0:901166f03471 53
andrewcrussell 0:901166f03471 54 //---------------------------------------------------------
andrewcrussell 0:901166f03471 55 DigitalOut CS(p13); /* chip select the SSD1963 active LOW */
andrewcrussell 0:901166f03471 56 //DigitalOut RS(p14); /* reset to SSD1963 - not used in this implementation*/
andrewcrussell 0:901166f03471 57 DigitalOut nWR(p15); /* write out to SSD1963 active LOW */
andrewcrussell 0:901166f03471 58 DigitalOut nRD(p16); /* read data from SSD1963 active LOW - but not used */
andrewcrussell 0:901166f03471 59 DigitalOut DC(p17); /* Data/Command Select: 1=Command, 0=Data); */
andrewcrussell 0:901166f03471 60 DigitalOut myled(LED1); /* for test purposes only - on the mbed module */
andrewcrussell 0:901166f03471 61
andrewcrussell 0:901166f03471 62 /* data bus I/O pins */
andrewcrussell 0:901166f03471 63 BusOut DB(p5,p6,p7,p8,p9,p10,p11,p12); /* databus D0-D7 */
andrewcrussell 0:901166f03471 64 /* forward references */
andrewcrussell 0:901166f03471 65 unsigned int fill;
andrewcrussell 0:901166f03471 66 unsigned int radius;
andrewcrussell 0:901166f03471 67
andrewcrussell 0:901166f03471 68 //unsigned char FONT6x8[97][8];
andrewcrussell 0:901166f03471 69 //unsigned char FONT8x8[97][8];
andrewcrussell 0:901166f03471 70 //unsigned char FONT8x16[97][8];
andrewcrussell 0:901166f03471 71 unsigned char command;
andrewcrussell 0:901166f03471 72 unsigned char data1;
andrewcrussell 0:901166f03471 73 int DOWN;
andrewcrussell 0:901166f03471 74 int RIGHT;
andrewcrussell 0:901166f03471 75 void LCDSetXY(unsigned int x,unsigned int y);
andrewcrussell 0:901166f03471 76 void LCDClearScreen(void);
andrewcrussell 0:901166f03471 77 //void LCDSetXY(int x, int y);
andrewcrussell 0:901166f03471 78 void LCDSetPixel(unsigned int x, unsigned int y, unsigned int color);
andrewcrussell 0:901166f03471 79 void LCDSetLine(int x1, int y1, int x2, int y2, int color);
andrewcrussell 0:901166f03471 80 void LCDSetRect(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int fill, unsigned int color);
andrewcrussell 0:901166f03471 81 void LCDSetCircle(unsigned int x0, unsigned int y0, unsigned int radius, unsigned int color);
andrewcrussell 0:901166f03471 82 void LCDPutChar(char c, unsigned int x, unsigned int y, unsigned int size, unsigned int fcolor, unsigned int bcolor);
andrewcrussell 0:901166f03471 83 void LCDPutString (char *lcd_string, const char *font_style, unsigned char x, unsigned char y,
andrewcrussell 0:901166f03471 84 unsigned char fcolor, unsigned char bcolor);
andrewcrussell 0:901166f03471 85
andrewcrussell 0:901166f03471 86 //******************************************************************************
andrewcrussell 0:901166f03471 87 void Write_Command(unsigned char command) {
andrewcrussell 0:901166f03471 88 CS=1; /* just to make sure */
andrewcrussell 0:901166f03471 89 nRD = 1; /* make sure the RD is HIGH just to be sure */
andrewcrussell 0:901166f03471 90 DC=0;
andrewcrussell 0:901166f03471 91 nWR = 0;
andrewcrussell 0:901166f03471 92 CS=0;
andrewcrussell 0:901166f03471 93 DB=command;
andrewcrussell 0:901166f03471 94 CS = 1;
andrewcrussell 0:901166f03471 95 nWR = 1;
andrewcrussell 0:901166f03471 96
andrewcrussell 0:901166f03471 97 }
andrewcrussell 0:901166f03471 98 //;******************************************************************************
andrewcrussell 0:901166f03471 99 void Write_Data(unsigned char data1) {
andrewcrussell 0:901166f03471 100 CS=1; /* just to make sure */
andrewcrussell 0:901166f03471 101 nRD = 1;
andrewcrussell 0:901166f03471 102 DC=1;
andrewcrussell 0:901166f03471 103 nWR = 0;
andrewcrussell 0:901166f03471 104 CS=0;
andrewcrussell 0:901166f03471 105 DB=data1;//write(data1);
andrewcrussell 0:901166f03471 106 CS = 1;
andrewcrussell 0:901166f03471 107 nWR = 1;
andrewcrussell 0:901166f03471 108 }
andrewcrussell 0:901166f03471 109
andrewcrussell 0:901166f03471 110 //====================================================
andrewcrussell 0:901166f03471 111 void Command_Write(unsigned char REG,unsigned char VALUE) {
andrewcrussell 0:901166f03471 112 Write_Command(REG);
andrewcrussell 0:901166f03471 113 Write_Data(VALUE);
andrewcrussell 0:901166f03471 114 }
andrewcrussell 0:901166f03471 115 //======================================================
andrewcrussell 0:901166f03471 116 void SendData(unsigned long color) {
andrewcrussell 0:901166f03471 117 Write_Data((color)>>16); //red
andrewcrussell 0:901166f03471 118 Write_Data((color)>>8); //green
andrewcrussell 0:901166f03471 119 Write_Data(color); //blue
andrewcrussell 0:901166f03471 120 }
andrewcrussell 0:901166f03471 121 /********************************************************************************/
andrewcrussell 0:901166f03471 122 void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y) {
andrewcrussell 0:901166f03471 123 Write_Command(CASET); //SET page address
andrewcrussell 0:901166f03471 124 Write_Data((s_x)>>8); //SET start page address=0
andrewcrussell 0:901166f03471 125 Write_Data(s_x);
andrewcrussell 0:901166f03471 126 Write_Data((e_x)>>8); //SET end page address=639
andrewcrussell 0:901166f03471 127 Write_Data(e_x);
andrewcrussell 0:901166f03471 128 Write_Command(PASET); //SET column address
andrewcrussell 0:901166f03471 129 Write_Data((s_y)>>8); //SET start column address=0
andrewcrussell 0:901166f03471 130 Write_Data(s_y);
andrewcrussell 0:901166f03471 131 Write_Data((e_y)>>8); //SET end column address=479
andrewcrussell 0:901166f03471 132 Write_Data(e_y);
andrewcrussell 0:901166f03471 133 }
andrewcrussell 0:901166f03471 134
andrewcrussell 0:901166f03471 135 /***************************************************************************/
andrewcrussell 0:901166f03471 136 /* this routine locates the screen pointer at position XY in the frame buffer */
andrewcrussell 0:901166f03471 137 void LCDSetXY(unsigned int x,unsigned int y) {
andrewcrussell 0:901166f03471 138 Write_Command(CASET); //SET page address
andrewcrussell 0:901166f03471 139 Write_Data((x)>>8); //SET start page address=0
andrewcrussell 0:901166f03471 140 Write_Data(x);
andrewcrussell 0:901166f03471 141 Write_Data((XMAX)>>8); //SET end page address=XMAX
andrewcrussell 0:901166f03471 142 Write_Data(XMAX);
andrewcrussell 0:901166f03471 143 Write_Command(PASET); //SET column address
andrewcrussell 0:901166f03471 144 Write_Data((y)>>8); //SET start column address=0
andrewcrussell 0:901166f03471 145 Write_Data(y);
andrewcrussell 0:901166f03471 146 Write_Data((YMAX)>>8); //SET end column address=YMAX
andrewcrussell 0:901166f03471 147 Write_Data(YMAX);
andrewcrussell 0:901166f03471 148 Write_Command(RAMWR); //ready to now start writing the data
andrewcrussell 0:901166f03471 149 //when returnung to the caller
andrewcrussell 0:901166f03471 150 }
andrewcrussell 0:901166f03471 151
andrewcrussell 0:901166f03471 152 /***************************************************************************/
andrewcrussell 0:901166f03471 153 // initialize controller
andrewcrussell 0:901166f03471 154 void Init_SSD1963 (void) {
andrewcrussell 0:901166f03471 155
andrewcrussell 0:901166f03471 156 Write_Command(0x01); //Software Reset
andrewcrussell 0:901166f03471 157 wait_ms(10);
andrewcrussell 0:901166f03471 158 Write_Command(0x01); //Software Reset
andrewcrussell 0:901166f03471 159 wait_ms(10);
andrewcrussell 0:901166f03471 160 Write_Command(0x01); //Software Reset
andrewcrussell 0:901166f03471 161 wait_ms(10);
andrewcrussell 0:901166f03471 162 Command_Write(0xe0,0x01); //START PLL
andrewcrussell 0:901166f03471 163 wait_us(1);
andrewcrussell 0:901166f03471 164 Command_Write(0xe0,0x03); //LOCK PLL
andrewcrussell 0:901166f03471 165 Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE
andrewcrussell 0:901166f03471 166 Write_Data(0x0c); //SET TFT MODE & hsync+Vsync+DEN MODE
andrewcrussell 0:901166f03471 167 Write_Data(0x80); //SET TFT MODE & hsync+Vsync+DEN MODE
andrewcrussell 0:901166f03471 168 Write_Data(0x02); //SET horizontal size=640-1 HightByte
andrewcrussell 0:901166f03471 169 Write_Data(0x7f); //SET horizontal size=640-1 LowByte
andrewcrussell 0:901166f03471 170 Write_Data(0x01); //SET vertical size=480-1 HightByte
andrewcrussell 0:901166f03471 171 Write_Data(0xdf); //SET vertical size=480-1 LowByte
andrewcrussell 0:901166f03471 172 Write_Data(0x00); //SET even/odd line RGB seq.=RGB
andrewcrussell 0:901166f03471 173 Command_Write(0xf0,0x00); //SET pixel data I/F format=8bit
andrewcrussell 0:901166f03471 174 Command_Write(0x3a,0x60); // SET R G B format = 6 6 6
andrewcrussell 0:901166f03471 175 Write_Command(0xe6); //SET PCLK freq=4.94MHz ; pixel clock frequency
andrewcrussell 0:901166f03471 176 Write_Data(0x02);
andrewcrussell 0:901166f03471 177 Write_Data(0xff);
andrewcrussell 0:901166f03471 178 Write_Data(0xff);
andrewcrussell 0:901166f03471 179 Write_Command(0xb4); //SET HBP,
andrewcrussell 0:901166f03471 180 Write_Data(0x02); //SET HSYNC Total=760
andrewcrussell 0:901166f03471 181 Write_Data(0xf8);
andrewcrussell 0:901166f03471 182 Write_Data(0x00); //SET HBP 68
andrewcrussell 0:901166f03471 183 Write_Data(0x44);
andrewcrussell 0:901166f03471 184 Write_Data(0x0f); //SET VBP 16=15+1
andrewcrussell 0:901166f03471 185 Write_Data(0x00); //SET Hsync pulse start position
andrewcrussell 0:901166f03471 186 Write_Data(0x00);
andrewcrussell 0:901166f03471 187 Write_Data(0x00); //SET Hsync pulse subpixel start position
andrewcrussell 0:901166f03471 188 Write_Command(0xb6); //SET VBP,
andrewcrussell 0:901166f03471 189 Write_Data(0x01); //SET Vsync total
andrewcrussell 0:901166f03471 190 Write_Data(0xf8);
andrewcrussell 0:901166f03471 191 Write_Data(0x00); //SET VBP=19
andrewcrussell 0:901166f03471 192 Write_Data(0x13);
andrewcrussell 0:901166f03471 193 Write_Data(0x07); //SET Vsync pulse 8=7+1
andrewcrussell 0:901166f03471 194 Write_Data(0x00); //SET Vsync pulse start position
andrewcrussell 0:901166f03471 195 Write_Data(0x00);
andrewcrussell 0:901166f03471 196 Write_Command(0x2a); //SET column address
andrewcrussell 0:901166f03471 197 Write_Data(0x00); //SET start column address=0
andrewcrussell 0:901166f03471 198 Write_Data(0x00);
andrewcrussell 0:901166f03471 199 Write_Data(0x02); //SET end column address=639
andrewcrussell 0:901166f03471 200 Write_Data(0x7f);
andrewcrussell 0:901166f03471 201 Write_Command(0x2b); //SET page address
andrewcrussell 0:901166f03471 202 Write_Data(0x00); //SET start page address=0
andrewcrussell 0:901166f03471 203 Write_Data(0x00);
andrewcrussell 0:901166f03471 204 Write_Data(0x01); //SET end page address=479
andrewcrussell 0:901166f03471 205 Write_Data(0xdf);
andrewcrussell 0:901166f03471 206 Write_Command(0x29); //SET display on
andrewcrussell 0:901166f03471 207 }
andrewcrussell 0:901166f03471 208
andrewcrussell 0:901166f03471 209 //========================== This section displays 4 blocks of colour =================================
andrewcrussell 0:901166f03471 210 void QUADS() {
andrewcrussell 0:901166f03471 211 unsigned int i,j;
andrewcrussell 0:901166f03471 212 WindowSet(0x0000,0x027f,0x0000,0x01df); /*this incorprates Write_Command*/
andrewcrussell 0:901166f03471 213 Write_Command(RAMWR); /* start writing the data to memory */
andrewcrussell 0:901166f03471 214 for (j= 0 ;j<240;j++) {
andrewcrussell 0:901166f03471 215 for (i=0;i<320;i++) {
andrewcrussell 0:901166f03471 216 SendData(0x00FF00); //GREEN
andrewcrussell 0:901166f03471 217 }
andrewcrussell 0:901166f03471 218 for (i=0;i<320;i++) {
andrewcrussell 0:901166f03471 219 SendData(0xFF0000); //RED
andrewcrussell 0:901166f03471 220 }
andrewcrussell 0:901166f03471 221 }
andrewcrussell 0:901166f03471 222 for (j= 0 ;j<240;j++) {
andrewcrussell 0:901166f03471 223 for (i=0;i<320;i++) {
andrewcrussell 0:901166f03471 224 SendData(0xBEBEBE); //GREY
andrewcrussell 0:901166f03471 225 }
andrewcrussell 0:901166f03471 226 for (i=0;i<320;i++) {
andrewcrussell 0:901166f03471 227 SendData(0xFF1493); //DEEP PINK
andrewcrussell 0:901166f03471 228 }
andrewcrussell 0:901166f03471 229 }
andrewcrussell 0:901166f03471 230 }
andrewcrussell 0:901166f03471 231 /********************************************************************************/
andrewcrussell 0:901166f03471 232 void clear_to_color(void) {
andrewcrussell 0:901166f03471 233 int m,n;
andrewcrussell 0:901166f03471 234 WindowSet(0,640,0,480); // 0-640 wide by 0-480 high
andrewcrussell 0:901166f03471 235 Write_Command(RAMWR);
andrewcrussell 0:901166f03471 236 for (m=0;m<480;m++) {
andrewcrussell 0:901166f03471 237 for (n=0;n<640;n++) {
andrewcrussell 0:901166f03471 238 SendData(BLUE);
andrewcrussell 0:901166f03471 239 }
andrewcrussell 0:901166f03471 240 }
andrewcrussell 0:901166f03471 241 }
andrewcrussell 0:901166f03471 242
andrewcrussell 0:901166f03471 243 /***************************************************************************/
andrewcrussell 0:901166f03471 244 /******* this routine lights up a single pixel to a specific colour ********/
andrewcrussell 0:901166f03471 245 void LCDSetPixel(unsigned int x,unsigned int y, unsigned int color) {
andrewcrussell 0:901166f03471 246 Write_Command(CASET); //SET page address
andrewcrussell 0:901166f03471 247 Write_Data((x)>>8); //SET start page address=0
andrewcrussell 0:901166f03471 248 Write_Data(x);
andrewcrussell 0:901166f03471 249 Write_Data((XMAX)>>8); //SET end page address=XMAX
andrewcrussell 0:901166f03471 250 Write_Data(XMAX);
andrewcrussell 0:901166f03471 251 Write_Command(PASET); //SET column address
andrewcrussell 0:901166f03471 252 Write_Data((y)>>8); //SET start column address=0
andrewcrussell 0:901166f03471 253 Write_Data(y);
andrewcrussell 0:901166f03471 254 Write_Data((YMAX)>>8); //SET end column address=YMAX
andrewcrussell 0:901166f03471 255 Write_Data(YMAX);
andrewcrussell 0:901166f03471 256 Write_Command(RAMWR); //ready to now start writing the data
andrewcrussell 0:901166f03471 257 //when returnung to the caller
andrewcrussell 0:901166f03471 258 SendData(color);
andrewcrussell 0:901166f03471 259 Write_Command(NOP);
andrewcrussell 0:901166f03471 260 }
andrewcrussell 0:901166f03471 261 /***************************************************************************/
andrewcrussell 0:901166f03471 262 /*********This routine draws a line between 2 points on the screen**********/
andrewcrussell 0:901166f03471 263 void LCDSetLine(int x0, int y0, int x1, int y1, int color) {
andrewcrussell 0:901166f03471 264 int dy = y1 - y0;
andrewcrussell 0:901166f03471 265 int dx = x1 - x0;
andrewcrussell 0:901166f03471 266 int stepx, stepy;
andrewcrussell 0:901166f03471 267 if (dy < 0) {
andrewcrussell 0:901166f03471 268 dy = -dy;
andrewcrussell 0:901166f03471 269 stepy = -1;
andrewcrussell 0:901166f03471 270 } else {
andrewcrussell 0:901166f03471 271 stepy = 1;
andrewcrussell 0:901166f03471 272 }
andrewcrussell 0:901166f03471 273 if (dx < 0) {
andrewcrussell 0:901166f03471 274 dx = -dx;
andrewcrussell 0:901166f03471 275 stepx = -1;
andrewcrussell 0:901166f03471 276 } else {
andrewcrussell 0:901166f03471 277 stepx = 1;
andrewcrussell 0:901166f03471 278 }
andrewcrussell 0:901166f03471 279 dy <<= 1; // dy is now 2*dy
andrewcrussell 0:901166f03471 280 dx <<= 1; // dx is now 2*dx
andrewcrussell 0:901166f03471 281 LCDSetPixel(x0, y0, color);
andrewcrussell 0:901166f03471 282 if (dx > dy) {
andrewcrussell 0:901166f03471 283 int fraction = dy - (dx >> 1); // same as 2*dy - dx
andrewcrussell 0:901166f03471 284 while (x0 != x1) {
andrewcrussell 0:901166f03471 285 if (fraction >= 0) {
andrewcrussell 0:901166f03471 286 y0 += stepy;
andrewcrussell 0:901166f03471 287 fraction -= dx; // same as fraction -= 2*dx
andrewcrussell 0:901166f03471 288 }
andrewcrussell 0:901166f03471 289 x0 += stepx;
andrewcrussell 0:901166f03471 290 fraction += dy; // same as fraction -= 2*dy
andrewcrussell 0:901166f03471 291 LCDSetPixel(x0, y0, color);
andrewcrussell 0:901166f03471 292 }
andrewcrussell 0:901166f03471 293 } else {
andrewcrussell 0:901166f03471 294 int fraction = dx - (dy >> 1);
andrewcrussell 0:901166f03471 295 while (y0 != y1) {
andrewcrussell 0:901166f03471 296 if (fraction >= 0) {
andrewcrussell 0:901166f03471 297 x0 += stepx;
andrewcrussell 0:901166f03471 298 fraction -= dy;
andrewcrussell 0:901166f03471 299 }
andrewcrussell 0:901166f03471 300 y0 += stepy;
andrewcrussell 0:901166f03471 301 fraction += dx;
andrewcrussell 0:901166f03471 302 LCDSetPixel(x0, y0, color);
andrewcrussell 0:901166f03471 303 }
andrewcrussell 0:901166f03471 304 }
andrewcrussell 0:901166f03471 305 }
andrewcrussell 0:901166f03471 306 /***************************************************************************/
andrewcrussell 0:901166f03471 307 /********** draw a rectangle, filled or not filled *************************/
andrewcrussell 0:901166f03471 308 void LCDSetRect(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int fill, unsigned int color) {
andrewcrussell 0:901166f03471 309 unsigned int xmin, xmax, ymin, ymax;
andrewcrussell 0:901166f03471 310 int i;
andrewcrussell 0:901166f03471 311 //unsigned char FILL;
andrewcrussell 0:901166f03471 312 // check if the rectangle is to be filled
andrewcrussell 0:901166f03471 313 if (fill == TRUE) {
andrewcrussell 0:901166f03471 314 // best way to create a filled rectangle is to define a drawing box
andrewcrussell 0:901166f03471 315 // and loop two pixels at a time
andrewcrussell 0:901166f03471 316 // calculate the min and max for x and y directions
andrewcrussell 0:901166f03471 317 xmin = (x0 <= x1) ? x0 : x1;
andrewcrussell 0:901166f03471 318 xmax = (x0 > x1) ? x0 : x1;
andrewcrussell 0:901166f03471 319 ymin = (y0 <= y1) ? y0 : y1;
andrewcrussell 0:901166f03471 320 ymax = (y0 > y1) ? y0 : y1;
andrewcrussell 0:901166f03471 321 Write_Command(CASET); //SET page address
andrewcrussell 0:901166f03471 322 Write_Data((x0)>>8); //SET start page address=0
andrewcrussell 0:901166f03471 323 Write_Data(x0);
andrewcrussell 0:901166f03471 324 Write_Data((x1)>>8); //SET end page address=XMAX
andrewcrussell 0:901166f03471 325 Write_Data(x1);
andrewcrussell 0:901166f03471 326 Write_Command(PASET); //SET column address
andrewcrussell 0:901166f03471 327 Write_Data((y0)>>8); //SET start column address=0
andrewcrussell 0:901166f03471 328 Write_Data(y0);
andrewcrussell 0:901166f03471 329 Write_Data((y1)>>8); //SET end column address=YMAX
andrewcrussell 0:901166f03471 330 Write_Data(y1);
andrewcrussell 0:901166f03471 331 Write_Command(RAMWR); //ready to now start writing the data
andrewcrussell 0:901166f03471 332 for (i = 0; i < ((((xmax - xmin + 1) * (ymax - ymin + 1)) / 2) + 1); i++) {
andrewcrussell 0:901166f03471 333 SendData(color);
andrewcrussell 0:901166f03471 334 }
andrewcrussell 0:901166f03471 335 } else {
andrewcrussell 0:901166f03471 336 LCDSetLine(x0, y0, x1, y0, color);
andrewcrussell 0:901166f03471 337 LCDSetLine(x0, y1, x1, y1, color);
andrewcrussell 0:901166f03471 338 LCDSetLine(x0, y0, x0, y1, color);
andrewcrussell 0:901166f03471 339 LCDSetLine(x1, y0, x1, y1, color);
andrewcrussell 0:901166f03471 340 }
andrewcrussell 0:901166f03471 341 }
andrewcrussell 0:901166f03471 342
andrewcrussell 0:901166f03471 343 /***************************************************************************/
andrewcrussell 0:901166f03471 344 void LCDSetCircle(unsigned int x0, unsigned int y0, unsigned int radius, unsigned int color) {
andrewcrussell 0:901166f03471 345 int f = 1 - radius;
andrewcrussell 0:901166f03471 346 int ddF_x = 0;
andrewcrussell 0:901166f03471 347 int ddF_y = -2 * radius;
andrewcrussell 0:901166f03471 348 int x = 0;
andrewcrussell 0:901166f03471 349 int y = radius;
andrewcrussell 0:901166f03471 350 LCDSetPixel(x0, y0 + radius, color);
andrewcrussell 0:901166f03471 351 LCDSetPixel(x0, y0 - radius, color);
andrewcrussell 0:901166f03471 352 LCDSetPixel(x0 + radius, y0, color);
andrewcrussell 0:901166f03471 353 LCDSetPixel(x0 - radius, y0, color);
andrewcrussell 0:901166f03471 354 while (x < y) {
andrewcrussell 0:901166f03471 355 if (f >= 0) {
andrewcrussell 0:901166f03471 356 y--;
andrewcrussell 0:901166f03471 357 ddF_y += 2;
andrewcrussell 0:901166f03471 358 f += ddF_y;
andrewcrussell 0:901166f03471 359 }
andrewcrussell 0:901166f03471 360 x++;
andrewcrussell 0:901166f03471 361 ddF_x += 2;
andrewcrussell 0:901166f03471 362 f += ddF_x + 1;
andrewcrussell 0:901166f03471 363 LCDSetPixel(x0 + x, y0 + y, color);
andrewcrussell 0:901166f03471 364 LCDSetPixel(x0 - x, y0 + y, color);
andrewcrussell 0:901166f03471 365 LCDSetPixel(x0 + x, y0 - y, color);
andrewcrussell 0:901166f03471 366 LCDSetPixel(x0 - x, y0 - y, color);
andrewcrussell 0:901166f03471 367 LCDSetPixel(x0 + y, y0 + x, color);
andrewcrussell 0:901166f03471 368 LCDSetPixel(x0 - y, y0 + x, color);
andrewcrussell 0:901166f03471 369 LCDSetPixel(x0 + y, y0 - x, color);
andrewcrussell 0:901166f03471 370 LCDSetPixel(x0 - y, y0 - x, color);
andrewcrussell 0:901166f03471 371 }
andrewcrussell 0:901166f03471 372 }
andrewcrussell 0:901166f03471 373 /***************************************************************************/
andrewcrussell 0:901166f03471 374 void LCDPutChar(char c, unsigned int x, unsigned int y, int size, unsigned int fColor, unsigned int bColor) {
andrewcrussell 0:901166f03471 375 extern const unsigned char FONT6x8[97][8];
andrewcrussell 0:901166f03471 376 extern const unsigned char FONT8x8[97][8];
andrewcrussell 0:901166f03471 377 extern const unsigned char FONT8x16[97][16];
andrewcrussell 0:901166f03471 378 int i,j;
andrewcrussell 0:901166f03471 379 unsigned int nCols;
andrewcrussell 0:901166f03471 380 unsigned int nRows;
andrewcrussell 0:901166f03471 381 unsigned int nBytes;
andrewcrussell 0:901166f03471 382 unsigned char PixelRow;
andrewcrussell 0:901166f03471 383 unsigned char Mask;
andrewcrussell 0:901166f03471 384 unsigned int Word0;
andrewcrussell 0:901166f03471 385 unsigned int Word1;
andrewcrussell 0:901166f03471 386 unsigned char *pFont;
andrewcrussell 0:901166f03471 387 unsigned char *pChar;
andrewcrussell 0:901166f03471 388 unsigned char *FontTable[] = {(unsigned char *)FONT6x8,
andrewcrussell 0:901166f03471 389 (unsigned char *)FONT8x8,
andrewcrussell 0:901166f03471 390 (unsigned char *)FONT8x16
andrewcrussell 0:901166f03471 391 };
andrewcrussell 0:901166f03471 392 // get pointer to the beginning of the selected font table
andrewcrussell 0:901166f03471 393 pFont = (unsigned char *)FontTable[size];
andrewcrussell 0:901166f03471 394 // get the nColumns, nRows and nBytes in the font table
andrewcrussell 0:901166f03471 395 nCols = *pFont;
andrewcrussell 0:901166f03471 396 nRows = *(pFont + 1);
andrewcrussell 0:901166f03471 397 nBytes = *(pFont + 2);
andrewcrussell 0:901166f03471 398 // get pointer to the last byte of the desired character - i.e. last byte in the row
andrewcrussell 0:901166f03471 399 pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;
andrewcrussell 0:901166f03471 400 // Row address set (command 0x2B) - x position on the LCD
andrewcrussell 0:901166f03471 401 Write_Command(PASET);
andrewcrussell 0:901166f03471 402 Write_Data(x);
andrewcrussell 0:901166f03471 403 Write_Data(x + nRows - 1);
andrewcrussell 0:901166f03471 404 // Column address set (command 0x2A) - y position on the LCD
andrewcrussell 0:901166f03471 405 Write_Command(CASET);
andrewcrussell 0:901166f03471 406 Write_Data(y); Write_Data(y);
andrewcrussell 0:901166f03471 407 Write_Data(y + nCols - 1);
andrewcrussell 0:901166f03471 408 // Write Memory - get ready to start writing the character
andrewcrussell 0:901166f03471 409 Write_Command(RAMWR);
andrewcrussell 0:901166f03471 410 // loop on each row, working backwards from top to bottom
andrewcrussell 0:901166f03471 411 for (i = nRows - 1; i >= 0; i--) {
andrewcrussell 0:901166f03471 412 // copy pixel row from font table and then decrement row
andrewcrussell 0:901166f03471 413 PixelRow = *pChar--;
andrewcrussell 0:901166f03471 414 // loop on each pixel in the row (left to right)
andrewcrussell 0:901166f03471 415 // Note: we do two pixels each loop
andrewcrussell 0:901166f03471 416 Mask = 0x80;
andrewcrussell 0:901166f03471 417 for (j = 0; j < nCols; j += 2) {
andrewcrussell 0:901166f03471 418 // if pixel bit set, use foreground color; else use the background color
andrewcrussell 0:901166f03471 419 // now get the pixel color for two successive pixels
andrewcrussell 0:901166f03471 420 if ((PixelRow & Mask) == 0)
andrewcrussell 0:901166f03471 421 Word0 = bColor;
andrewcrussell 0:901166f03471 422 else
andrewcrussell 0:901166f03471 423 Word0 = fColor;
andrewcrussell 0:901166f03471 424 Mask = Mask >> 1;
andrewcrussell 0:901166f03471 425 if ((PixelRow & Mask) == 0)
andrewcrussell 0:901166f03471 426 Word1 = bColor;
andrewcrussell 0:901166f03471 427 else
andrewcrussell 0:901166f03471 428 Word1 = fColor;
andrewcrussell 0:901166f03471 429 Mask = Mask >> 1;
andrewcrussell 0:901166f03471 430 // use this information to output three data bytes
andrewcrussell 0:901166f03471 431 Write_Data((Word0 >> 4) & 0xFF);
andrewcrussell 0:901166f03471 432 Write_Data(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
andrewcrussell 0:901166f03471 433 Write_Data(Word1 & 0xFF);
andrewcrussell 0:901166f03471 434 }
andrewcrussell 0:901166f03471 435 }
andrewcrussell 0:901166f03471 436 // terminate the Write Memory command
andrewcrussell 0:901166f03471 437 Write_Command(NOP);
andrewcrussell 0:901166f03471 438 }
andrewcrussell 0:901166f03471 439 // *************************************************************************************************
andrewcrussell 0:901166f03471 440
andrewcrussell 0:901166f03471 441
andrewcrussell 0:901166f03471 442
andrewcrussell 0:901166f03471 443
andrewcrussell 0:901166f03471 444 int main(void) {
andrewcrussell 0:901166f03471 445
andrewcrussell 0:901166f03471 446 int h;
andrewcrussell 0:901166f03471 447 Serial pc(USBTX, USBRX);
andrewcrussell 0:901166f03471 448 wait_ms(10);
andrewcrussell 0:901166f03471 449 Init_SSD1963();
andrewcrussell 0:901166f03471 450
andrewcrussell 0:901166f03471 451
andrewcrussell 0:901166f03471 452 LCDSetXY(230,230);
andrewcrussell 0:901166f03471 453 QUADS();
andrewcrussell 0:901166f03471 454 clear_to_color();
andrewcrussell 0:901166f03471 455
andrewcrussell 0:901166f03471 456
andrewcrussell 0:901166f03471 457 LCDSetXY(340,200);
andrewcrussell 0:901166f03471 458 {
andrewcrussell 0:901166f03471 459 for (h=0;h<200;h++)
andrewcrussell 0:901166f03471 460 SendData(WHITE);
andrewcrussell 0:901166f03471 461 }
andrewcrussell 0:901166f03471 462
andrewcrussell 0:901166f03471 463 LCDSetXY(350,210);
andrewcrussell 0:901166f03471 464 {
andrewcrussell 0:901166f03471 465 for (h=0;h<200;h++)
andrewcrussell 0:901166f03471 466 SendData(DEEPINK);
andrewcrussell 0:901166f03471 467 }
andrewcrussell 0:901166f03471 468
andrewcrussell 0:901166f03471 469 LCDSetPixel(400,300,BLACK);//working
andrewcrussell 0:901166f03471 470 LCDSetPixel(405,305,DEEPINK);//working
andrewcrussell 0:901166f03471 471 LCDSetLine(0,300,250,10,DEEPINK);//working
andrewcrussell 0:901166f03471 472 LCDSetRect(100,100,250,250,1,DEEPINK);//working
andrewcrussell 0:901166f03471 473 LCDSetRect(200,200,350,350,0,BLACK);//working
andrewcrussell 0:901166f03471 474 LCDSetCircle(320,240,150,WHITE);//working
andrewcrussell 0:901166f03471 475 LCDSetCircle(320,240,155,WHITE);//working
andrewcrussell 0:901166f03471 476 LCDSetCircle(320,240,160,WHITE);//working
andrewcrussell 0:901166f03471 477 LCDPutChar('E',10,10,1, WHITE, BLACK);
andrewcrussell 0:901166f03471 478 //LCDPutStr("This guy is nuts", 115, 2, LARGE, BLACK, CYAN);
andrewcrussell 0:901166f03471 479 Write_Command(NOP);
andrewcrussell 0:901166f03471 480
andrewcrussell 0:901166f03471 481 while (1) {};
andrewcrussell 0:901166f03471 482 }