SSD1963 TFT LCD Controller 8-bit mode program for writing to Newhaven Display 5.7\" TFT 640x480. Rev A Does not work yet

Dependencies:   mbed

This is the basic display driver from Newhaven displays for the SSD1963 TFT LCD Controller . Written by Kurt Lagerstram. I adapted it for the mbed LPC1768.

Committer:
andrewcrussell
Date:
Sun Jan 23 01:15:27 2011 +0000
Revision:
0:5e44c36ffbf3
Rev A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewcrussell 0:5e44c36ffbf3 1 #include "mbed.h"
andrewcrussell 0:5e44c36ffbf3 2 #include "stdlib.h"
andrewcrussell 0:5e44c36ffbf3 3 #include "string.h"
andrewcrussell 0:5e44c36ffbf3 4 //---------------------------------------------------------
andrewcrussell 0:5e44c36ffbf3 5 /*
andrewcrussell 0:5e44c36ffbf3 6 SSD1963_8-bit
andrewcrussell 0:5e44c36ffbf3 7 Program for writing to Newhaven Display 5.7" TFT 640x480
andrewcrussell 0:5e44c36ffbf3 8
andrewcrussell 0:5e44c36ffbf3 9 (c)2010 Curt Lagerstam - Newhaven Display International, LLC.
andrewcrussell 0:5e44c36ffbf3 10
andrewcrussell 0:5e44c36ffbf3 11 This program is free software; you can redistribute it and/or modify
andrewcrussell 0:5e44c36ffbf3 12 it under the terms of the GNU General Public License as published by
andrewcrussell 0:5e44c36ffbf3 13 the Free Software Foundation; either version 2 of the License, or
andrewcrussell 0:5e44c36ffbf3 14 (at your option) any later version.
andrewcrussell 0:5e44c36ffbf3 15
andrewcrussell 0:5e44c36ffbf3 16 This program is distributed in the hope that it will be useful,
andrewcrussell 0:5e44c36ffbf3 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewcrussell 0:5e44c36ffbf3 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewcrussell 0:5e44c36ffbf3 19 GNU General Public License for more details.
andrewcrussell 0:5e44c36ffbf3 20 */
andrewcrussell 0:5e44c36ffbf3 21 //---------------------------------------------------------
andrewcrussell 0:5e44c36ffbf3 22 unsigned char command;
andrewcrussell 0:5e44c36ffbf3 23 unsigned char data1;
andrewcrussell 0:5e44c36ffbf3 24 int DOWN;
andrewcrussell 0:5e44c36ffbf3 25 int RIGHT;
andrewcrussell 0:5e44c36ffbf3 26 //---------------------------------------------------------
andrewcrussell 0:5e44c36ffbf3 27 //DigitalOut RS(p14); /* reset to SSD1963 */
andrewcrussell 0:5e44c36ffbf3 28 DigitalOut nWR(p15); /* write out to SSD1963 active LOW */
andrewcrussell 0:5e44c36ffbf3 29 DigitalOut nRD(p16); /* read data from SSD1963 active LOW */
andrewcrussell 0:5e44c36ffbf3 30 DigitalOut CS(p13); /* chip select the SSD1963 active LOW */
andrewcrussell 0:5e44c36ffbf3 31 DigitalOut DC(p17); /* Data/Command Select: 1=Command, 0=Data); */
andrewcrussell 0:5e44c36ffbf3 32 DigitalOut myled(LED1); /* for test purposes only */
andrewcrussell 0:5e44c36ffbf3 33
andrewcrussell 0:5e44c36ffbf3 34 /* data bus I/O pins */
andrewcrussell 0:5e44c36ffbf3 35
andrewcrussell 0:5e44c36ffbf3 36
andrewcrussell 0:5e44c36ffbf3 37 //BusInOut DB(p12,p11,p10,p9,p8,p7,p6,p5); /* databus D0-D7 */
andrewcrussell 0:5e44c36ffbf3 38
andrewcrussell 0:5e44c36ffbf3 39 BusInOut DB(p5,p6,p7,p8,p9,p10,p11,p12); /* databus D0-D7 */
andrewcrussell 0:5e44c36ffbf3 40
andrewcrussell 0:5e44c36ffbf3 41 /*Following are HARD WIRED on the controller board */
andrewcrussell 0:5e44c36ffbf3 42 //DigitalIn DOWN = P3^6;
andrewcrussell 0:5e44c36ffbf3 43 //sbit RIGHT = P3^2;
andrewcrussell 0:5e44c36ffbf3 44
andrewcrussell 0:5e44c36ffbf3 45 //******************************************************************************
andrewcrussell 0:5e44c36ffbf3 46 void Write_Command(unsigned char command) {
andrewcrussell 0:5e44c36ffbf3 47 nRD = 1; /* make sure the RD is HIGH just to be sure */
andrewcrussell 0:5e44c36ffbf3 48 DC=1;
andrewcrussell 0:5e44c36ffbf3 49 nWR = 0;
andrewcrussell 0:5e44c36ffbf3 50 CS=0;
andrewcrussell 0:5e44c36ffbf3 51 wait_us(1);
andrewcrussell 0:5e44c36ffbf3 52 DB=command;
andrewcrussell 0:5e44c36ffbf3 53 DB.write(command);
andrewcrussell 0:5e44c36ffbf3 54 //DB=command;
andrewcrussell 0:5e44c36ffbf3 55 wait_us(1);
andrewcrussell 0:5e44c36ffbf3 56 nWR = 1;
andrewcrussell 0:5e44c36ffbf3 57 CS = 1;
andrewcrussell 0:5e44c36ffbf3 58
andrewcrussell 0:5e44c36ffbf3 59 }
andrewcrussell 0:5e44c36ffbf3 60 //;******************************************************************************
andrewcrussell 0:5e44c36ffbf3 61 void Write_Data(unsigned char data1) {
andrewcrussell 0:5e44c36ffbf3 62 nRD = 1;
andrewcrussell 0:5e44c36ffbf3 63 DC=0;
andrewcrussell 0:5e44c36ffbf3 64 nWR = 0;
andrewcrussell 0:5e44c36ffbf3 65 CS=0;
andrewcrussell 0:5e44c36ffbf3 66 wait_us(1);
andrewcrussell 0:5e44c36ffbf3 67 DB=data1;
andrewcrussell 0:5e44c36ffbf3 68 DB.write(data1);
andrewcrussell 0:5e44c36ffbf3 69 //DB=data1;
andrewcrussell 0:5e44c36ffbf3 70 wait_us(1);
andrewcrussell 0:5e44c36ffbf3 71 nWR = 1;
andrewcrussell 0:5e44c36ffbf3 72 CS = 1;
andrewcrussell 0:5e44c36ffbf3 73 }
andrewcrussell 0:5e44c36ffbf3 74 //====================================================
andrewcrussell 0:5e44c36ffbf3 75 void Command_Write(unsigned char REG,unsigned char VALUE) {
andrewcrussell 0:5e44c36ffbf3 76 Write_Command(REG);
andrewcrussell 0:5e44c36ffbf3 77 Write_Data(VALUE);
andrewcrussell 0:5e44c36ffbf3 78 }
andrewcrussell 0:5e44c36ffbf3 79 //======================================================
andrewcrussell 0:5e44c36ffbf3 80 void SendData(unsigned long color) {
andrewcrussell 0:5e44c36ffbf3 81 Write_Data((color)>>16); //red
andrewcrussell 0:5e44c36ffbf3 82 Write_Data((color)>>8); //green
andrewcrussell 0:5e44c36ffbf3 83 Write_Data(color); //blue
andrewcrussell 0:5e44c36ffbf3 84 }
andrewcrussell 0:5e44c36ffbf3 85 //======================================================
andrewcrussell 0:5e44c36ffbf3 86 // initialize controller
andrewcrussell 0:5e44c36ffbf3 87 //======================================================
andrewcrussell 0:5e44c36ffbf3 88 void Init_SSD1963 (void) {
andrewcrussell 0:5e44c36ffbf3 89 //RESET = 0;
andrewcrussell 0:5e44c36ffbf3 90 wait_ms(5);
andrewcrussell 0:5e44c36ffbf3 91 //RESET = 1;
andrewcrussell 0:5e44c36ffbf3 92 //myled-!myled;
andrewcrussell 0:5e44c36ffbf3 93 DOWN = 0;
andrewcrussell 0:5e44c36ffbf3 94 RIGHT = 1;
andrewcrussell 0:5e44c36ffbf3 95 wait_ms(100);
andrewcrussell 0:5e44c36ffbf3 96 Write_Command(0x01); //Software Reset
andrewcrussell 0:5e44c36ffbf3 97 wait_ms(100);
andrewcrussell 0:5e44c36ffbf3 98 Write_Command(0x01);
andrewcrussell 0:5e44c36ffbf3 99 Write_Command(0x01);
andrewcrussell 0:5e44c36ffbf3 100 wait_ms(10);
andrewcrussell 0:5e44c36ffbf3 101 Command_Write(0xe0,0x01); //START PLL
andrewcrussell 0:5e44c36ffbf3 102 Command_Write(0xe0,0x03); //LOCK PLL
andrewcrussell 0:5e44c36ffbf3 103 Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE
andrewcrussell 0:5e44c36ffbf3 104 Write_Data(0x0c); //SET TFT MODE & hsync+Vsync+DEN MODE
andrewcrussell 0:5e44c36ffbf3 105 Write_Data(0x80); //SET TFT MODE & hsync+Vsync+DEN MODE
andrewcrussell 0:5e44c36ffbf3 106 Write_Data(0x02); //SET horizontal size=640-1 HightByte
andrewcrussell 0:5e44c36ffbf3 107 Write_Data(0x7f); //SET horizontal size=640-1 LowByte
andrewcrussell 0:5e44c36ffbf3 108 Write_Data(0x01); //SET vertical size=480-1 HightByte
andrewcrussell 0:5e44c36ffbf3 109 Write_Data(0xdf); //SET vertical size=480-1 LowByte
andrewcrussell 0:5e44c36ffbf3 110 Write_Data(0x00); //SET even/odd line RGB seq.=RGB
andrewcrussell 0:5e44c36ffbf3 111 Command_Write(0xf0,0x00); //SET pixel data I/F format=8bit
andrewcrussell 0:5e44c36ffbf3 112 Command_Write(0x3a,0x60); // SET R G B format = 6 6 6
andrewcrussell 0:5e44c36ffbf3 113 Write_Command(0xe6); //SET PCLK freq=4.94MHz ; pixel clock frequency
andrewcrussell 0:5e44c36ffbf3 114 Write_Data(0x02);
andrewcrussell 0:5e44c36ffbf3 115 Write_Data(0xff);
andrewcrussell 0:5e44c36ffbf3 116 Write_Data(0xff);
andrewcrussell 0:5e44c36ffbf3 117 Write_Command(0xb4); //SET HBP,
andrewcrussell 0:5e44c36ffbf3 118 Write_Data(0x02); //SET HSYNC Total=760
andrewcrussell 0:5e44c36ffbf3 119 Write_Data(0xf8);
andrewcrussell 0:5e44c36ffbf3 120 Write_Data(0x00); //SET HBP 68
andrewcrussell 0:5e44c36ffbf3 121 Write_Data(0x44);
andrewcrussell 0:5e44c36ffbf3 122 Write_Data(0x0f); //SET VBP 16=15+1
andrewcrussell 0:5e44c36ffbf3 123 Write_Data(0x00); //SET Hsync pulse start position
andrewcrussell 0:5e44c36ffbf3 124 Write_Data(0x00);
andrewcrussell 0:5e44c36ffbf3 125 Write_Data(0x00); //SET Hsync pulse subpixel start position
andrewcrussell 0:5e44c36ffbf3 126 Write_Command(0xb6); //SET VBP,
andrewcrussell 0:5e44c36ffbf3 127 Write_Data(0x01); //SET Vsync total
andrewcrussell 0:5e44c36ffbf3 128 Write_Data(0xf8);
andrewcrussell 0:5e44c36ffbf3 129 Write_Data(0x00); //SET VBP=19
andrewcrussell 0:5e44c36ffbf3 130 Write_Data(0x13);
andrewcrussell 0:5e44c36ffbf3 131 Write_Data(0x07); //SET Vsync pulse 8=7+1
andrewcrussell 0:5e44c36ffbf3 132 Write_Data(0x00); //SET Vsync pulse start position
andrewcrussell 0:5e44c36ffbf3 133 Write_Data(0x00);
andrewcrussell 0:5e44c36ffbf3 134 Write_Command(0x2a); //SET column address
andrewcrussell 0:5e44c36ffbf3 135 Write_Data(0x00); //SET start column address=0
andrewcrussell 0:5e44c36ffbf3 136 Write_Data(0x00);
andrewcrussell 0:5e44c36ffbf3 137 Write_Data(0x02); //SET end column address=639
andrewcrussell 0:5e44c36ffbf3 138 Write_Data(0x7f);
andrewcrussell 0:5e44c36ffbf3 139 Write_Command(0x2b); //SET page address
andrewcrussell 0:5e44c36ffbf3 140 Write_Data(0x00); //SET start page address=0
andrewcrussell 0:5e44c36ffbf3 141 Write_Data(0x00);
andrewcrussell 0:5e44c36ffbf3 142 Write_Data(0x01); //SET end page address=479
andrewcrussell 0:5e44c36ffbf3 143 Write_Data(0xdf);
andrewcrussell 0:5e44c36ffbf3 144 Write_Command(0x29); //SET display on
andrewcrussell 0:5e44c36ffbf3 145 }
andrewcrussell 0:5e44c36ffbf3 146 //======================================================
andrewcrussell 0:5e44c36ffbf3 147 void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y) {
andrewcrussell 0:5e44c36ffbf3 148 Write_Command(0x2a); //SET page address
andrewcrussell 0:5e44c36ffbf3 149 Write_Data((s_x)>>8); //SET start page address=0
andrewcrussell 0:5e44c36ffbf3 150 Write_Data(s_x);
andrewcrussell 0:5e44c36ffbf3 151 Write_Data((e_x)>>8); //SET end page address=639
andrewcrussell 0:5e44c36ffbf3 152 Write_Data(e_x);
andrewcrussell 0:5e44c36ffbf3 153 Write_Command(0x2b); //SET column address
andrewcrussell 0:5e44c36ffbf3 154 Write_Data((s_y)>>8); //SET start column address=0
andrewcrussell 0:5e44c36ffbf3 155 Write_Data(s_y);
andrewcrussell 0:5e44c36ffbf3 156 Write_Data((e_y)>>8); //SET end column address=479
andrewcrussell 0:5e44c36ffbf3 157 Write_Data(e_y);
andrewcrussell 0:5e44c36ffbf3 158
andrewcrussell 0:5e44c36ffbf3 159 }
andrewcrussell 0:5e44c36ffbf3 160 //=======================================
andrewcrussell 0:5e44c36ffbf3 161 void FULL_ON(unsigned long dat) {
andrewcrussell 0:5e44c36ffbf3 162 unsigned char x,y;
andrewcrussell 0:5e44c36ffbf3 163 printf("%s\n\r","vvvv");
andrewcrussell 0:5e44c36ffbf3 164 WindowSet(0x0000,0x027f,0x0000,0x01df);
andrewcrussell 0:5e44c36ffbf3 165 printf("%s\n\r","jjjj");
andrewcrussell 0:5e44c36ffbf3 166 Write_Command(0x2c);
andrewcrussell 0:5e44c36ffbf3 167 for (x=0;x<480;x++) {
andrewcrussell 0:5e44c36ffbf3 168 for (y= 0;y<640;y++) {
andrewcrussell 0:5e44c36ffbf3 169 SendData(dat);
andrewcrussell 0:5e44c36ffbf3 170 }
andrewcrussell 0:5e44c36ffbf3 171 }
andrewcrussell 0:5e44c36ffbf3 172 printf("%s\n\r","qqqqq");
andrewcrussell 0:5e44c36ffbf3 173 }
andrewcrussell 0:5e44c36ffbf3 174 //=======================================
andrewcrussell 0:5e44c36ffbf3 175 void QUADS() {
andrewcrussell 0:5e44c36ffbf3 176 unsigned int i,j;
andrewcrussell 0:5e44c36ffbf3 177
andrewcrussell 0:5e44c36ffbf3 178 WindowSet(0x0000,0x027f,0x0000,0x01df);
andrewcrussell 0:5e44c36ffbf3 179
andrewcrussell 0:5e44c36ffbf3 180 Write_Command(0x2c);
andrewcrussell 0:5e44c36ffbf3 181
andrewcrussell 0:5e44c36ffbf3 182 for (j= 0 ;j<240;j++) {
andrewcrussell 0:5e44c36ffbf3 183 for (i=0;i<320;i++) {
andrewcrussell 0:5e44c36ffbf3 184 SendData(0x0000FF); //blue
andrewcrussell 0:5e44c36ffbf3 185 }
andrewcrussell 0:5e44c36ffbf3 186 for (i=0;i<320;i++) {
andrewcrussell 0:5e44c36ffbf3 187 SendData(0xFF0000); //red
andrewcrussell 0:5e44c36ffbf3 188 }
andrewcrussell 0:5e44c36ffbf3 189 }
andrewcrussell 0:5e44c36ffbf3 190 for (j= 0 ;j<240;j++) {
andrewcrussell 0:5e44c36ffbf3 191 for (i=0;i<320;i++) {
andrewcrussell 0:5e44c36ffbf3 192 SendData(0xFFFF00); //yellow
andrewcrussell 0:5e44c36ffbf3 193 }
andrewcrussell 0:5e44c36ffbf3 194 for (i=0;i<320;i++) {
andrewcrussell 0:5e44c36ffbf3 195 SendData(0x00FF00); //green
andrewcrussell 0:5e44c36ffbf3 196 }
andrewcrussell 0:5e44c36ffbf3 197 }
andrewcrussell 0:5e44c36ffbf3 198 }
andrewcrussell 0:5e44c36ffbf3 199 //=======================================
andrewcrussell 0:5e44c36ffbf3 200 int main(void) {
andrewcrussell 0:5e44c36ffbf3 201 wait_ms(100);
andrewcrussell 0:5e44c36ffbf3 202 myled=1;
andrewcrussell 0:5e44c36ffbf3 203 wait_ms(500);
andrewcrussell 0:5e44c36ffbf3 204 myled=!myled;
andrewcrussell 0:5e44c36ffbf3 205 wait_ms(500);
andrewcrussell 0:5e44c36ffbf3 206 myled-!myled;
andrewcrussell 0:5e44c36ffbf3 207 Init_SSD1963();
andrewcrussell 0:5e44c36ffbf3 208 while (1) {
andrewcrussell 0:5e44c36ffbf3 209 Init_SSD1963();
andrewcrussell 0:5e44c36ffbf3 210 wait_ms(5);
andrewcrussell 0:5e44c36ffbf3 211 printf("%s\n\r","here");
andrewcrussell 0:5e44c36ffbf3 212 QUADS();
andrewcrussell 0:5e44c36ffbf3 213 printf("%s\n\r","then here");
andrewcrussell 0:5e44c36ffbf3 214 FULL_ON(0x0000ff); //blue
andrewcrussell 0:5e44c36ffbf3 215 myled=!myled;
andrewcrussell 0:5e44c36ffbf3 216 wait(2);
andrewcrussell 0:5e44c36ffbf3 217 //FULL_ON(0x000008); //blue
andrewcrussell 0:5e44c36ffbf3 218 //myled=!myled;
andrewcrussell 0:5e44c36ffbf3 219 }
andrewcrussell 0:5e44c36ffbf3 220 }