/* --COPYRIGHT--,BSD * Copyright (c) 2017, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --/COPYRIGHT--*/ /****************************************************************************** * MSP432 Empty Project * * Description: An empty project that uses DriverLib * * MSP432P401 * ------------------ * /|\| |-- * | | P5.0|--GSLAT * --|RST |-- * | P5.2|--BLNK * GSSIN--|P3.5 P4.3|--GSCKR/G/B * --| |-- * GSSCK--|P3.7 |-- * --| |-- * Author: *******************************************************************************/ /* DriverLib Includes */ #include /* Standard Includes */ #include #include static volatile uint32_t aclk, mclk, smclk, hsmclk, bclk; #define CPU_F ((double)25000000) #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0)) #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0)) char DCdata0[]={ 0x00,0x00,0x00,//R0 G0 B0 0x00,0x00,0x00,//R1 G1 B1 0x00,0x00,0x00,//R2 G2 B2 0x00,0x00,0x00,//R3 G3 B3 0x00,0x00,0x00,//R4 G4 B4 0x00,0x00,0x00,//R5 G5 B5 0x00,0x00,0x00,//R6 G6 B6 0x00,0x00,0x00,//R7 G7 B7 }; char DCdata1[]={ 0xff,0xff,0xff,//R0 G0 B0 0xff,0xff,0xff,//R1 G1 B1 0xff,0xff,0xff,//R2 G2 B2 0xff,0xff,0xff,//R3 G3 B3 0xff,0xff,0xff,//R4 G4 B4 0xff,0xff,0xff,//R5 G5 B5 0xff,0xff,0xff,//R6 G6 B6 0xff,0xff,0xff,//R7 G7 B7 }; int GSdata0[]={ 0x000,0x000,0x000,//R0 G0 B0 0x000,0x000,0x000,//R1 G1 B1 0x000,0x000,0x000,//R2 G2 B2 0x000,0x000,0x000,//R3 G3 B3 0x000,0x000,0x000,//R4 G4 B4 0x000,0x000,0x000,//R5 G5 B5 0x000,0x000,0x000,//R6 G6 B6 0x000,0x000,0x000,//R7 G7 B7 }; int GSdata1[]={ 0xfff,0xfff,0xfff,//R0 G0 B0 0xfff,0xfff,0xfff,//R1 G1 B1 0xfff,0xfff,0xfff,//R2 G2 B2 0xfff,0xfff,0xfff,//R3 G3 B3 0xfff,0xfff,0xfff,//R4 G4 B4 0xfff,0xfff,0xfff,//R5 G5 B5 0xfff,0xfff,0xfff,//R6 G6 B6 0xfff,0xfff,0xfff,//R7 G7 B7 }; void SendDCData(int CMD, int UD, char GS_MODE, char DSTMR, char ADSRPM, char DC_Range_Blue, char DC_Range_Green, char DC_Range_Red, char BCB, char BCG, char BCR, char *DCdata)//Send DC/BC/FC data thru GS Data Path { GPIO_setOutputHighOnPin(GPIO_PORT_P5,GPIO_PIN0 ); //LATCH-High for DC Mode int k,temp1,temp2; /*Command Code BITS 287-276*/ for(k=287;k>=276;k--) { temp1=1<<(k-276); temp2=CMD&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } //GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*No Value BITS 275-216*/ GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low for(k=275;k>=216;k--) { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*User Define BITS 215-199*/ for(k=215;k>=199;k--) { temp1=1<<(k-199); temp2=UD&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } //GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*GS Counter Mode BITS 198-197*/ for(k=198;k>=197;k--) { temp1=1<<(k-197); temp2=GS_MODE&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*Display Timing Reset Mode BITS 196*/ if(DSTMR==1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High /*Auto Display Repeat Mode BITS 195*/ if(ADSRPM==1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High /*Dot correction adjustment range for the BLUE color output BITS 194*/ if(DC_Range_Blue==1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High /*Dot correction adjustment range for the GREEN color output BITS 193*/ if(DC_Range_Green==1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High /*Dot correction adjustment range for the RED color output BITS 192*/ if(DC_Range_Red==1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI- Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High /*Global Brightness Control Blue BITS 191-184*/ for(k=191;k>=184;k--) { temp1=1<<(k-184); temp2=BCB&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*Global Brightness Control Green BITS 183-176*/ for(k=183;k>=176;k--) { temp1=1<<(k-176); temp2=BCG&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SDI-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*Global Brightness Control Red BITS 175-168*/ for(k=175;k>=168;k--) { temp1=1<<(k-168); temp2=BCR&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } /*Dot Correction Data BITS 167-0*/ for(k=167;k>=0;k--) { temp1=1<<(k%7); temp2=DCdata[k/7]&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } GPIO_setOutputLowOnPin(GPIO_PORT_P5,GPIO_PIN0 ); //LATCH-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P5,GPIO_PIN0);//LATCH-High __delay_cycles(6); } void SendGSData(int *temp)// Send Gray Scale data { GPIO_setOutputLowOnPin(GPIO_PORT_P5,GPIO_PIN0 ); //GSLAT-Low for GS Mode int k,temp1,temp2; for(k=287;k>=0;k--) { temp1=1<<(k%12); temp2=temp[k/12]&temp1; if(temp2==temp1) { GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - High } else { GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN5);//SDI - Low } GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low __delay_cycles(6); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-High } //GPIO_setOutputLowOnPin(GPIO_PORT_P3,GPIO_PIN7);//SCK-Low GPIO_setOutputHighOnPin(GPIO_PORT_P5,GPIO_PIN0);//LATCH-High __delay_cycles(6); GPIO_setOutputLowOnPin(GPIO_PORT_P5,GPIO_PIN0 ); //LATCH-Low __delay_cycles(6); } int main(void) { MAP_WDT_A_holdTimer(); /* Setting the DCO Frequency to a non-standard 8.33MHz */ // MAP_CS_setDCOFrequency(8330000); /* Initializing the clock source as follows: * MCLK = MODOSC/4 = 6MHz * ACLK = REFO/2 = 16kHz * HSMCLK = DCO/2 = 1.5Mhz * SMCLK = DCO/4 = 750kHz * BCLK = REFO = 32kHz */ MAP_CS_initClockSignal(CS_MCLK, CS_MODOSC_SELECT, CS_CLOCK_DIVIDER_128); //MODOSC:Internal low-power oscillator with 25-MHz typical frequency MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2); MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_4); MAP_CS_initClockSignal(CS_BCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); /* * Getting all of the frequency values of the CLK sources using the * convenience functions */ aclk = CS_getACLK(); mclk = CS_getMCLK(); smclk = CS_getSMCLK(); hsmclk = CS_getHSMCLK(); bclk = CS_getBCLK(); GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_PIN5|GPIO_PIN6|GPIO_PIN7); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_PIN5|GPIO_PIN6|GPIO_PIN7); GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2); GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4,GPIO_PIN3,GPIO_PRIMARY_MODULE_FUNCTION); GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2); /*SendDCData(double CMD, int UD, char GS_MODE, char DSTMR, char ADSRPM, char DC_Range_Blue, char DC_Range_Green, char DC_Range_Red, char BCB, char BCG, char BCR, char *DCdata)*/ while(1) { SendDCData(0, 0x3, 0x00, 0, 1, 0, 0, 0, 10, 10, 10, DCdata1); SendGSData(GSdata1); delay_ms(80); } //SendDCData(0, 3, 0x00, 0, 1, 0, 0, 0, 0, 0, 0, DCdata0); /*while(1) { delay_ms(10); SendDCData(0x53A, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, DCdata0); delay_ms(10); }*/ }