Andrew Russell / Mbed 2 deprecated Display_Driver

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stdlib.h"
00003 #include "string.h"
00004 //---------------------------------------------------------
00005 /*
00006 SSD1963_8-bit
00007 Program for writing to Newhaven Display 5.7" TFT 640x480
00008 
00009 (c)2010 Curt Lagerstam - Newhaven Display International, LLC.
00010 
00011      This program is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     This program is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU General Public License for more details.
00020 */
00021 //---------------------------------------------------------
00022 unsigned char command;
00023 unsigned char data1;
00024 int DOWN;
00025 int RIGHT;
00026 //---------------------------------------------------------
00027 //DigitalOut RS(p14);                         /* reset  to SSD1963 */
00028 DigitalOut nWR(p15);                        /* write out to SSD1963 active LOW */
00029 DigitalOut nRD(p16);                        /* read data from SSD1963 active LOW */
00030 DigitalOut CS(p13);                         /* chip select the SSD1963 active LOW */
00031 DigitalOut DC(p17);                         /* Data/Command Select: 1=Command,  0=Data); */
00032 DigitalOut myled(LED1);                     /* for test purposes only */
00033 
00034 /* data bus I/O pins */
00035 
00036 
00037 //BusInOut DB(p12,p11,p10,p9,p8,p7,p6,p5);    /* databus D0-D7 */
00038 
00039 BusInOut DB(p5,p6,p7,p8,p9,p10,p11,p12);    /* databus D0-D7 */
00040 
00041 /*Following are HARD WIRED on the controller  board */
00042 //DigitalIn DOWN = P3^6;
00043 //sbit RIGHT = P3^2;
00044 
00045 //******************************************************************************
00046 void Write_Command(unsigned char command) {
00047     nRD = 1;        /* make sure the RD  is HIGH just to be sure */
00048     DC=1;
00049     nWR  = 0;
00050     CS=0;
00051     wait_us(1);
00052     DB=command;
00053     DB.write(command);
00054     //DB=command;
00055     wait_us(1);
00056     nWR  = 1;
00057     CS = 1;
00058 
00059 }
00060 //;******************************************************************************
00061 void Write_Data(unsigned char data1) {
00062     nRD = 1;
00063     DC=0;
00064     nWR  = 0;
00065     CS=0;
00066     wait_us(1);
00067     DB=data1;
00068     DB.write(data1);
00069     //DB=data1;
00070     wait_us(1);
00071     nWR  = 1;
00072     CS = 1;
00073 }
00074 //====================================================
00075 void Command_Write(unsigned char REG,unsigned char VALUE) {
00076     Write_Command(REG);
00077     Write_Data(VALUE);
00078 }
00079 //======================================================
00080 void SendData(unsigned long color) {
00081     Write_Data((color)>>16);    //red
00082     Write_Data((color)>>8);     //green
00083     Write_Data(color);          //blue
00084 }
00085 //======================================================
00086 // initialize controller
00087 //======================================================
00088 void Init_SSD1963 (void) {
00089 //RESET = 0;
00090     wait_ms(5);
00091 //RESET = 1;
00092 //myled-!myled;
00093     DOWN = 0;
00094     RIGHT = 1;
00095     wait_ms(100);
00096     Write_Command(0x01);     //Software Reset
00097     wait_ms(100);
00098     Write_Command(0x01);
00099     Write_Command(0x01);
00100     wait_ms(10);
00101     Command_Write(0xe0,0x01);    //START PLL
00102     Command_Write(0xe0,0x03);    //LOCK PLL
00103     Write_Command(0xb0);        //SET LCD MODE  SET TFT 18Bits MODE
00104     Write_Data(0x0c);            //SET TFT MODE & hsync+Vsync+DEN MODE
00105     Write_Data(0x80);            //SET TFT MODE & hsync+Vsync+DEN MODE
00106     Write_Data(0x02);            //SET horizontal size=640-1 HightByte
00107     Write_Data(0x7f);            //SET horizontal size=640-1 LowByte
00108     Write_Data(0x01);            //SET vertical size=480-1 HightByte
00109     Write_Data(0xdf);            //SET vertical size=480-1 LowByte
00110     Write_Data(0x00);            //SET even/odd line RGB seq.=RGB
00111     Command_Write(0xf0,0x00);    //SET pixel data I/F format=8bit
00112     Command_Write(0x3a,0x60);   // SET R G B format = 6 6 6
00113     Write_Command(0xe6);           //SET PCLK freq=4.94MHz  ; pixel clock frequency
00114     Write_Data(0x02);
00115     Write_Data(0xff);
00116     Write_Data(0xff);
00117     Write_Command(0xb4);        //SET HBP,
00118     Write_Data(0x02);            //SET HSYNC Total=760
00119     Write_Data(0xf8);
00120     Write_Data(0x00);            //SET HBP 68
00121     Write_Data(0x44);
00122     Write_Data(0x0f);            //SET VBP 16=15+1
00123     Write_Data(0x00);            //SET Hsync pulse start position
00124     Write_Data(0x00);
00125     Write_Data(0x00);            //SET Hsync pulse subpixel start position
00126     Write_Command(0xb6);         //SET VBP,
00127     Write_Data(0x01);            //SET Vsync total
00128     Write_Data(0xf8);
00129     Write_Data(0x00);            //SET VBP=19
00130     Write_Data(0x13);
00131     Write_Data(0x07);            //SET Vsync pulse 8=7+1
00132     Write_Data(0x00);            //SET Vsync pulse start position
00133     Write_Data(0x00);
00134     Write_Command(0x2a);        //SET column address
00135     Write_Data(0x00);            //SET start column address=0
00136     Write_Data(0x00);
00137     Write_Data(0x02);            //SET end column address=639
00138     Write_Data(0x7f);
00139     Write_Command(0x2b);        //SET page address
00140     Write_Data(0x00);            //SET start page address=0
00141     Write_Data(0x00);
00142     Write_Data(0x01);            //SET end page address=479
00143     Write_Data(0xdf);
00144     Write_Command(0x29);        //SET display on
00145 }
00146 //======================================================
00147 void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y) {
00148     Write_Command(0x2a);        //SET page address
00149     Write_Data((s_x)>>8);       //SET start page address=0
00150     Write_Data(s_x);
00151     Write_Data((e_x)>>8);       //SET end page address=639
00152     Write_Data(e_x);
00153     Write_Command(0x2b);        //SET column address
00154     Write_Data((s_y)>>8);       //SET start column address=0
00155     Write_Data(s_y);
00156     Write_Data((e_y)>>8);       //SET end column address=479
00157     Write_Data(e_y);
00158 
00159 }
00160 //=======================================
00161 void FULL_ON(unsigned long dat) {
00162     unsigned char x,y;
00163     printf("%s\n\r","vvvv");
00164     WindowSet(0x0000,0x027f,0x0000,0x01df);
00165     printf("%s\n\r","jjjj");
00166     Write_Command(0x2c);
00167     for (x=0;x<480;x++) {
00168         for (y= 0;y<640;y++) {
00169             SendData(dat);
00170         }
00171     }
00172     printf("%s\n\r","qqqqq");
00173 }
00174 //=======================================
00175 void QUADS() {
00176     unsigned int i,j;
00177 
00178     WindowSet(0x0000,0x027f,0x0000,0x01df);
00179 
00180     Write_Command(0x2c);
00181 
00182     for (j= 0 ;j<240;j++) {
00183         for (i=0;i<320;i++) {
00184             SendData(0x0000FF);             //blue
00185         }
00186         for (i=0;i<320;i++) {
00187             SendData(0xFF0000);             //red
00188         }
00189     }
00190     for (j= 0 ;j<240;j++) {
00191         for (i=0;i<320;i++) {
00192             SendData(0xFFFF00);             //yellow
00193         }
00194         for (i=0;i<320;i++) {
00195             SendData(0x00FF00);             //green
00196         }
00197     }
00198 }
00199 //=======================================
00200 int main(void) {
00201     wait_ms(100);
00202     myled=1;
00203     wait_ms(500);
00204     myled=!myled;
00205     wait_ms(500);
00206     myled-!myled;
00207     Init_SSD1963();
00208     while (1) {
00209         Init_SSD1963();
00210         wait_ms(5);
00211         printf("%s\n\r","here");
00212         QUADS();
00213         printf("%s\n\r","then here");
00214         FULL_ON(0x0000ff);        //blue
00215         myled=!myled;
00216         wait(2);
00217 //FULL_ON(0x000008);        //blue
00218 //myled=!myled;
00219     }
00220 }