This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: C2000 communicates with LCD by SPI

Part Number: TMS320F28379D
Other Parts Discussed in Thread: AFE031, C2000WARE, BOOSTXL-EDUMKII

Hi Expert,

Do we have SPI example project which could be able to communicate with LCD, is it boostxl_afe031_f28379d_dacmode?

For there's no guide book about this example, I'd like to double check with you.

If the above example could not support to communicate with LCD by SPI module, could you supply a related solution which could be found in C2000Ware folder? Thanks!

Best Regards

Rayna

  • Rayna,

    We don't SPI example which interfaces with LCD screen.

    I would guess spi_ex3_external_loopback_fifo_interrupts available in C2000Ware would be good starting point get started with your project.

    Regards,

    Manoj

  • Rayna/Manoj,

    Below is an example code I created for controlling the LCD on the Educational BoosterPack (BOOSTXL-EDUMKII) using the F280049C LaunchPad.  The code is applicable to that particular LCD & it's controller, but it should serve as a reference.  Note the actual LCD commands and sequence was adapted from a project on Sparkfun.  The code leverages C2000Ware for controlling the SPI module.  I hope it helps.

    Code is provided as-is.

    //===========================================================================
    //
    //  Code written for LAUNCHXL-F280049C
    //
    //  CRYSTALFONTZ CFAF128128B-0145T 128X128 SPI COLOR 1.45" TFT
    //
    //  Super-simple software SPI example code.
    //
    //  ref: www.crystalfontz.com/.../cfaf128128b0145t
    //
    //  April 02, 2020
    //
    //  Gustavo Martinez
    //
    //============================================================================
    //
    // Display is Crystalfontz CFAF128128B-0145T
    //   www.crystalfontz.com/.../cfaf128128b0145t
    //
    // The controller is a Sitronix ST7735S
    //   www.crystalfontz.com/.../
    //
    //============================================================================
    
    
    //============================================================================
    //
    // LCD SPI & control lines
    // CK2_LP       | PIN   | EDU_BP
    // -------------+-------+-------------------
    // PGA1/3/5_GND | J1.02 | JOY_X
    // NC           | J1.05 | JOY_SEL
    // ADCINB3/VDAC | J1.06 | MIC_IN
    // GPIO56       | J1.07 | LCD_SPI_CLK*
    // ADCINC4      | J1.08 | LIGHT_INT
    // GPIO37       | J1.09 | I2C_SCL
    // GPIO35       | J1.10 | I2C_SDA
    //
    // GPIO59       | J2.11 | TEMP_DRDY
    // GPIO23       | J2.12 | NC (must hardwire to J2.17)
    // GPIO39       | J2.13 | LCD_SPI_CS*
    // GPIO17       | J2.14 | NC
    // GPIO16       | J2.15 | LCD_SPI_MOSI*
    // NC           | J2.17 | LCD_RST* (must hardwire to J2.12)
    // GPIO57       | J2.19 | PWM_SERVC
    //
    // ADCINA5      | J3.23 | ACC_XOUT
    // ADCINB0      | J3.24 | ACC_YOUT
    // ADCINC2      | J3.25 | ACC_ZOUT
    // ADCINB1      | J3.26 | JOY_Y
    //
    // GPIO25       | J4.31 | LCD_RS*
    // GPIO18       | J4.32 | BUTTON2
    // GPIO30       | J4.33 | BUTTON1
    // GPIO58       | J4.34 | GATOR
    // GPIO09       | J4.37 | PWM_BLU
    // GPIO11       | J4.39 | PWM_LED_LCD
    // GPIO10       | J4.40 | BUZZER_OUT
    
    //============================================================================
    
    
    //----------------------------------------------------------------------------
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //----------------------------------------------------------------------------
    // Defines for GPIO setup
    //
    #define DEVICE_GPIO_PIN_LCD_SPI_CS  39U  // GPIO number for LCD_SPI_CS
    #define DEVICE_GPIO_CFG_LCD_SPI_CS  GPIO_39_GPIO39    // "pinConfig" for LCD_SPI_CS
    #define DEVICE_GPIO_PIN_LCD_RST     23U  // GPIO number for LCD_RST
    #define DEVICE_GPIO_CFG_LCD_RST     GPIO_23_GPIO23    // "pinConfig" for LCD_RST
    #define DEVICE_GPIO_PIN_LCD_RS      25U  // GPIO number for LCD_RS
    #define DEVICE_GPIO_CFG_LCD_RS      GPIO_25_GPIO25    // "pinConfig" for LCD_RS
    
    //----------------------------------------------------------------------------
    // Defines for LCD control pins
    //
    #define LCD_SPI_CS_LOW    GPIO_writePin(DEVICE_GPIO_PIN_LCD_SPI_CS, 0)
    #define LCD_SPI_CS_HIGH   GPIO_writePin(DEVICE_GPIO_PIN_LCD_SPI_CS, 1)
    
    #define LCD_RST_LOW       GPIO_writePin(DEVICE_GPIO_PIN_LCD_RST, 0)
    #define LCD_RST_HIGH      GPIO_writePin(DEVICE_GPIO_PIN_LCD_RST, 1)
    
    #define LCD_RS_LOW        GPIO_writePin(DEVICE_GPIO_PIN_LCD_RS, 0)
    #define LCD_RS_HIGH       GPIO_writePin(DEVICE_GPIO_PIN_LCD_RS, 1)
    
    //----------------------------------------------------------------------------
    // Defines for the ST7735 registers.
    // ref: www.crystalfontz.com/.../ST7735_V2.1_20100505.pdf
    #define ST7735_SLPOUT   (0x11)
    #define ST7735_DISPON   (0x29)
    #define ST7735_CASET    (0x2A)
    #define ST7735_RASET    (0x2B)
    #define ST7735_RAMWR    (0x2C)
    #define ST7735_RAMRD    (0x2E)
    #define ST7735_MADCTL   (0x36)
    #define ST7735_COLMOD   (0x3A)
    #define ST7735_FRMCTR1  (0xB1)
    #define ST7735_FRMCTR2  (0xB2)
    #define ST7735_FRMCTR3  (0xB3)
    #define ST7735_INVCTR   (0xB4)
    #define ST7735_PWCTR1   (0xC0)
    #define ST7735_PWCTR2   (0xC1)
    #define ST7735_PWCTR3   (0xC2)
    #define ST7735_PWCTR4   (0xC3)
    #define ST7735_PWCTR5   (0xC4)
    #define ST7735_VMCTR1   (0xC5)
    #define ST7735_GAMCTRP1 (0xE0)
    #define ST7735_GAMCTRN1 (0xE1)
    
    
    //============================================================================
    void msdelay(uint16_t msdelay)
    {
        uint16_t i, j;
    
        for(j=0;j<1000;j++)
        {
            for(i=0;i<msdelay;i++)
            {
                asm(" NOP");
            }
        }
    }
    
    //============================================================================
    void SPI_sendCommand(uint16_t command)
      {
        uint16_t volatile dummy = 0;
      // Select the LCD's command register
      LCD_RS_LOW;
      // Select the LCD controller
      LCD_SPI_CS_LOW;
      //Send the command via SPI:
      SPI_writeDataBlockingNonFIFO(SPIA_BASE, command << 8);
      dummy = SPI_readDataBlockingNonFIFO(SPIA_BASE); //dummy read to clear INT_FLAG
      // Deselect the LCD controller
      LCD_SPI_CS_HIGH;
      }
    
    //----------------------------------------------------------------------------
    void SPI_sendData(uint16_t data)
      {
        uint16_t volatile dummy = 0;
      // Select the LCD's data register
      LCD_RS_HIGH;
      // Select the LCD controller
      LCD_SPI_CS_LOW;
      //Send the command via SPI:
      SPI_writeDataBlockingNonFIFO(SPIA_BASE, data << 8);
      dummy = SPI_readDataBlockingNonFIFO(SPIA_BASE); //dummy read to clear INT_FLAG
      // Deselect the LCD controller
      LCD_SPI_CS_HIGH;
      }
    
    //----------------------------------------------------------------------------
    void Initialize_LCD(void)
      {
      //Reset the LCD controller
      LCD_RST_LOW;
      msdelay(1);//10µS min
      LCD_RST_HIGH;
      msdelay(150);//120mS max
    
      //SLPOUT (11h): Sleep Out ("Sleep Out"  is chingrish for "wake")
      //The DC/DC converter is enabled, Internal display oscillator
      //is started, and panel scanning is started.
      SPI_sendCommand(ST7735_SLPOUT);
      msdelay(120);
    
      //FRMCTR1 (B1h): Frame Rate Control (In normal mode/ Full colors)
      //Set the frame frequency of the full colors normal mode.
      // * Frame rate=fosc/((RTNA + 20) x (LINE + FPA + BPA))
      // * 1 < FPA(front porch) + BPA(back porch) ; Back porch ?0
      //Note: fosc = 333kHz
      SPI_sendCommand(ST7735_FRMCTR1);//In normal mode(Full colors)
      SPI_sendData(0x02);//RTNB: set 1-line period
      SPI_sendData(0x35);//FPB:  front porch
      SPI_sendData(0x36);//BPB:  back porch
    
      //FRMCTR2 (B2h): Frame Rate Control (In Idle mode/ 8-colors)
      //Set the frame frequency of the Idle mode.
      // * Frame rate=fosc/((RTNB + 20) x (LINE + FPB + BPB))
      // * 1 < FPB(front porch) + BPB(back porch) ; Back porch ?0
      //Note: fosc = 333kHz
      SPI_sendCommand(ST7735_FRMCTR2);//In Idle mode (8-colors)
      SPI_sendData(0x02);//RTNB: set 1-line period
      SPI_sendData(0x35);//FPB:  front porch
      SPI_sendData(0x36);//BPB:  back porch
    
      //FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
      //Set the frame frequency of the Partial mode/ full colors.
      // * 1st parameter to 3rd parameter are used in line inversion mode.
      // * 4th parameter to 6th parameter are used in frame inversion mode.
      // * Frame rate=fosc/((RTNC + 20) x (LINE + FPC + BPC))
      // * 1 < FPC(front porch) + BPC(back porch) ; Back porch ?0
      //Note: fosc = 333kHz
      SPI_sendCommand(ST7735_FRMCTR3);//In partial mode + Full colors
      SPI_sendData(0x02);//RTNC: set 1-line period
      SPI_sendData(0x35);//FPC:  front porch
      SPI_sendData(0x36);//BPC:  back porch
      SPI_sendData(0x02);//RTND: set 1-line period
      SPI_sendData(0x35);//FPD:  front porch
      SPI_sendData(0x36);//BPD:  back porch
    
      //INVCTR (B4h): Display Inversion Control
      SPI_sendCommand(ST7735_INVCTR);
      SPI_sendData(0x07);
      // 0000 0ABC
      // |||| ||||-- NLC: Inversion setting in full Colors partial mode
      // |||| |||         (0=Line Inversion, 1 = Frame Inversion)
      // |||| |||--- NLB: Inversion setting in idle mode
      // |||| ||          (0=Line Inversion, 1 = Frame Inversion)
      // |||| ||---- NLA: Inversion setting in full Colors normal mode
      // |||| |----- Unused: 0
    
      //PWCTR1 (C0h): Power Control 1
      SPI_sendCommand(ST7735_PWCTR1);
      SPI_sendData(0x02);// VRH[4:0] (0-31) Sets GVDD
                         // VRH=0x00 => GVDD=5.0v
                         // VRH=0x1F => GVDD=3.0v
                         // Each tick is a variable step:
                         // VRH[4:0] |  VRH | GVDD
                         //   00000b | 0x00 | 5.00v
                         //   00001b | 0x01 | 4.75v
                         //   00010b | 0x02 | 4.70v <<<<<
                         //   00011b | 0x03 | 4.65v
                         //   00100b | 0x04 | 4.60v
                         //   00101b | 0x05 | 4.55v
                         //   00110b | 0x06 | 4.50v
                         //   00111b | 0x07 | 4.45v
                         //   01000b | 0x08 | 4.40v
                         //   01001b | 0x09 | 4.35v
                         //   01010b | 0x0A | 4.30v
                         //   01011b | 0x0B | 4.25v
                         //   01100b | 0x0C | 4.20v
                         //   01101b | 0x0D | 4.15v
                         //   01110b | 0x0E | 4.10v
                         //   01111b | 0x0F | 4.05v
                         //   10000b | 0x10 | 4.00v
                         //   10001b | 0x11 | 3.95v
                         //   10010b | 0x12 | 3.90v
                         //   10011b | 0x13 | 3.85v
                         //   10100b | 0x14 | 3.80v
                         //   10101b | 0x15 | 3.75v
                         //   10110b | 0x16 | 3.70v
                         //   10111b | 0x17 | 3.65v
                         //   11000b | 0x18 | 3.60v
                         //   11001b | 0x19 | 3.55v
                         //   11010b | 0x1A | 3.50v
                         //   11011b | 0x1B | 3.45v
                         //   11100b | 0x1C | 3.40v
                         //   11101b | 0x1D | 3.35v
                         //   11110b | 0x1E | 3.25v
                         //   11111b | 0x1F | 3.00v
      SPI_sendData(0x02);// 010i i000
                         // |||| ||||-- Unused: 0
                         // |||| |----- IB_SEL0:
                         // ||||------- IB_SEL1:
                         // |||-------- Unused: 010
                         // IB_SEL[1:0] | IB_SEL | AVDD
                         //         00b | 0x00   | 2.5µA   <<<<<
                         //         01b | 0x01   | 2.0µA
                         //         10b | 0x02   | 1.5µA
                         //         11b | 0x03   | 1.0µA
    
                         //PWCTR2 (C1h): Power Control 2
                         // * Set the VGH and VGL supply power level
                         //Restriction: VGH-VGL <= 32V
      SPI_sendCommand(ST7735_PWCTR2);
      SPI_sendData(0xC5);// BT[2:0] (0-15) Sets GVDD
                         // BT[2:0] |    VGH      |     VGL
                         //    000b | 4X |  9.80v | -3X |  -7.35v
                         //    001b | 4X |  9.80v | -4X |  -9.80v
                         //    010b | 5X | 12.25v | -3X |  -7.35v
                         //    011b | 5X | 12.25v | -4X |  -9.80v
                         //    100b | 5X | 12.25v | -5X | -12.25v
                         //    101b | 6X | 14.70v | -3X |  -7.35v   <<<<<
                         //    110b | 6X | 14.70v | -4X |  -9.80v
                         //    111b | 6X | 14.70v | -5X | -12.25v
    
                         //PWCTR3 (C2h): Power Control 3 (in Normal mode/ Full colors)
                         // * Set the amount of current in Operational amplifier in
                         //   normal mode/full colors.
                         // * Adjust the amount of fixed current from the fixed current
                         //   source in the operational amplifier for the source driver.
                         // * Set the Booster circuit Step-up cycle in Normal mode/ full
                         //   colors.
      SPI_sendCommand(ST7735_PWCTR3);
      SPI_sendData(0x0D);// AP[2:0] Sets Operational Amplifier Bias Current
                         // AP[2:0] | Function
                         //    000b | Off
                         //    001b | Small
                         //    010b | Medium Low
                         //    011b | Medium
                         //    100b | Medium High
                         //    101b | Large          <<<<<
                         //    110b | reserved
                         //    111b | reserved
      SPI_sendData(0x00);// DC[2:0] Booster Frequency
                         // DC[2:0] | Circuit 1 | Circuit 2,4
                         //    000b | BCLK / 1  | BCLK / 1  <<<<<
                         //    001b | BCLK / 1  | BCLK / 2
                         //    010b | BCLK / 1  | BCLK / 4
                         //    011b | BCLK / 2  | BCLK / 2
                         //    100b | BCLK / 2  | BCLK / 4
                         //    101b | BCLK / 4  | BCLK / 4
                         //    110b | BCLK / 4  | BCLK / 8
                         //    111b | BCLK / 4  | BCLK / 16
    
                         //PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
                         // * Set the amount of current in Operational amplifier in
                         //   normal mode/full colors.
                         // * Adjust the amount of fixed current from the fixed current
                         //   source in the operational amplifier for the source driver.
                         // * Set the Booster circuit Step-up cycle in Normal mode/ full
                         //   colors.
      SPI_sendCommand(ST7735_PWCTR4);
      SPI_sendData(0x8D);// AP[2:0] Sets Operational Amplifier Bias Current
                         // AP[2:0] | Function
                         //    000b | Off
                         //    001b | Small
                         //    010b | Medium Low
                         //    011b | Medium
                         //    100b | Medium High
                         //    101b | Large          <<<<<
                         //    110b | reserved
                         //    111b | reserved
      SPI_sendData(0x1A);// DC[2:0] Booster Frequency
                         // DC[2:0] | Circuit 1 | Circuit 2,4
                         //    000b | BCLK / 1  | BCLK / 1
                         //    001b | BCLK / 1  | BCLK / 2
                         //    010b | BCLK / 1  | BCLK / 4  <<<<<
                         //    011b | BCLK / 2  | BCLK / 2
                         //    100b | BCLK / 2  | BCLK / 4
                         //    101b | BCLK / 4  | BCLK / 4
                         //    110b | BCLK / 4  | BCLK / 8
                         //    111b | BCLK / 4  | BCLK / 16
    
                         //PPWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
                         // * Set the amount of current in Operational amplifier in
                         //   normal mode/full colors.
                         // * Adjust the amount of fixed current from the fixed current
                         //   source in the operational amplifier for the source driver.
                         // * Set the Booster circuit Step-up cycle in Normal mode/ full
                         //   colors.
      SPI_sendCommand(ST7735_PWCTR5);
      SPI_sendData(0x8D);// AP[2:0] Sets Operational Amplifier Bias Current
                         // AP[2:0] | Function
                         //    000b | Off
                         //    001b | Small
                         //    010b | Medium Low
                         //    011b | Medium
                         //    100b | Medium High
                         //    101b | Large          <<<<<
                         //    110b | reserved
                         //    111b | reserved
      SPI_sendData(0xEE);// DC[2:0] Booster Frequency
                         // DC[2:0] | Circuit 1 | Circuit 2,4
                         //    000b | BCLK / 1  | BCLK / 1
                         //    001b | BCLK / 1  | BCLK / 2
                         //    010b | BCLK / 1  | BCLK / 4
                         //    011b | BCLK / 2  | BCLK / 2
                         //    100b | BCLK / 2  | BCLK / 4
                         //    101b | BCLK / 4  | BCLK / 4
                         //    110b | BCLK / 4  | BCLK / 8  <<<<<
                         //    111b | BCLK / 4  | BCLK / 16
    
                         //VMCTR1 (C5h): VCOM Control 1
      SPI_sendCommand(ST7735_VMCTR1);
      SPI_sendData(0x51);// Default: 0x51 => +4.525
                         // VMH[6:0] (0-100) Sets VCOMH
                         // VMH=0x00 => VCOMH= +2.5v
                         // VMH=0x64 => VCOMH= +5.0v
      SPI_sendData(0x4D);// Default: 0x4D => -0.575
                         // VML[6:0] (4-100) Sets VCOML
                         // VML=0x04 => VCOML= -2.4v
                         // VML=0x64 => VCOML=  0.0v
    
                         //GMCTRP1 (E0h): Gamma ‘+’polarity Correction Characteristics Setting
      SPI_sendCommand(ST7735_GAMCTRP1);
      SPI_sendData(0x0a);
      SPI_sendData(0x1c);
      SPI_sendData(0x0c);
      SPI_sendData(0x14);
      SPI_sendData(0x33);
      SPI_sendData(0x2b);
      SPI_sendData(0x24);
      SPI_sendData(0x28);
      SPI_sendData(0x27);
      SPI_sendData(0x25);
      SPI_sendData(0x2C);
      SPI_sendData(0x39);
      SPI_sendData(0x00);
      SPI_sendData(0x05);
      SPI_sendData(0x03);
      SPI_sendData(0x0d);
    
                         //GMCTRN1 (E1h): Gamma ‘-’polarity Correction Characteristics Setting
      SPI_sendCommand(ST7735_GAMCTRN1);
      SPI_sendData(0x0a);
      SPI_sendData(0x1c);
      SPI_sendData(0x0c);
      SPI_sendData(0x14);
      SPI_sendData(0x33);
      SPI_sendData(0x2b);
      SPI_sendData(0x24);
      SPI_sendData(0x28);
      SPI_sendData(0x27);
      SPI_sendData(0x25);
      SPI_sendData(0x2D);
      SPI_sendData(0x3a);
      SPI_sendData(0x00);
      SPI_sendData(0x05);
      SPI_sendData(0x03);
      SPI_sendData(0x0d);
    
                         //COLMOD (3Ah): Interface Pixel Format
                         // * This command is used to define the format of RGB picture
                         //   data, which is to be transferred via the MCU interface.
      SPI_sendCommand(ST7735_COLMOD);
      SPI_sendData(0x06);// Default: 0x06 => 18-bit/pixel
                         // IFPF[2:0] MCU Interface Color Format
                         // IFPF[2:0] | Format
                         //      000b | reserved
                         //      001b | reserved
                         //      010b | reserved
                         //      011b | 12-bit/pixel
                         //      100b | reserved
                         //      101b | 16-bit/pixel
                         //      110b | 18-bit/pixel   <<<<<
                         //      111b | reserved
    
                         //DISPON (29h): Display On
                         // * This command is used to recover from DISPLAY OFF mode. Output
                         //   from the Frame Memory is enabled.
                         // * This command makes no change of contents of frame memory.
                         // * This command does not change any other status.
                         // * The msdelay time between DISPON and DISPOFF needs 120ms at least
      SPI_sendCommand(ST7735_DISPON);//Display On
      msdelay(1);
    
      //MADCTL (36h): Memory Data Access Control
      SPI_sendCommand(ST7735_MADCTL);
      SPI_sendData(0x40);// YXVL RH--
                         // |||| ||||-- Unused: 0
                         // |||| ||---- MH: Horizontal Refresh Order
                         // |||| |        0 = left to right
                         // |||| |        1 = right to left
                         // |||| |----- RGB: RGB vs BGR Order
                         // ||||          0 = RGB color filter panel
                         // ||||          1 = BGR color filter panel
                         // ||||------- ML: Vertical Refresh Order
                         // |||           0 = top to bottom
                         // |||           1 = bottom to top
                         // |||-------- MV: Row / Column Exchange
                         // ||--------- MX: Column Address Order  <<<<<
                         // |---------- MY: Row Address Order
    
      }
    //============================================================================
    void Set_LCD_for_write_at_X_Y(uint16_t x, uint16_t y)
      {
      //CASET (2Ah): Column Address Set
      // * The value of XS [15:0] and XE [15:0] are referred when RAMWR
      //   command comes.
      // * Each value represents one column line in the Frame Memory.
      // * XS [15:0] always must be equal to or less than XE [15:0]
      SPI_sendCommand(ST7735_CASET); //Column address set
      //Write the parameters for the "column address set" command
      SPI_sendData(0x00);     //Start MSB = XS[15:8]
      SPI_sendData(0x02 + x); //Start LSB = XS[ 7:0]
      SPI_sendData(0x00);     //End MSB   = XE[15:8]
      SPI_sendData(0x81);     //End LSB   = XE[ 7:0]
      //Write the "row address set" command to the LCD
      //RASET (2Bh): Row Address Set
      // * The value of YS [15:0] and YE [15:0] are referred when RAMWR
      //   command comes.
      // * Each value represents one row line in the Frame Memory.
      // * YS [15:0] always must be equal to or less than YE [15:0]
      SPI_sendCommand(ST7735_RASET); //Row address set
      //Write the parameters for the "row address set" command
      SPI_sendData(0x00);     //Start MSB = YS[15:8]
      SPI_sendData(0x01 + y); //Start LSB = YS[ 7:0]
      SPI_sendData(0x00);     //End MSB   = YE[15:8]
      SPI_sendData(0x80);     //End LSB   = YE[ 7:0]
      //Write the "write data" command to the LCD
      //RAMWR (2Ch): Memory Write
      SPI_sendCommand(ST7735_RAMWR); //write data
      }
    //============================================================================
    void Fill_LCD(uint16_t R, uint16_t G, uint16_t B)
      {
      register int
        i;
      Set_LCD_for_write_at_X_Y(0, 0);
    
      //Fill display with a given RGB value
      for (i = 0; i < (128 * 128); i++)
        {
        SPI_sendData(B); //Blue
        SPI_sendData(G); //Green
        SPI_sendData(R); //Red
        }
      }
    //============================================================================
    void Put_Pixel(uint16_t x, uint16_t y, uint16_t R, uint16_t G, uint16_t B)
      {
      Set_LCD_for_write_at_X_Y(x, y);
      //Write the single pixel's worth of data
      SPI_sendData(B); //Blue
      SPI_sendData(G); //Green
      SPI_sendData(R); //Red
      }
    //============================================================================
    // From: en.wikipedia.org/.../Midpoint_circle_algorithm
    void LCD_Circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t R, uint16_t G, uint16_t B)
      {
      uint16_t x = radius;
      uint16_t y = 0;
      int16_t radiusError = 1 - (int16_t) x;
    
      while (x >= y)
        {
        //11 O'Clock
        Put_Pixel(x0 - y, y0 + x, R, G, B);
        //1 O'Clock
        Put_Pixel(x0 + y, y0 + x, R, G, B);
        //10 O'Clock
        Put_Pixel(x0 - x, y0 + y, R, G, B);
        //2 O'Clock
        Put_Pixel(x0 + x, y0 + y, R, G, B);
        //8 O'Clock
        Put_Pixel(x0 - x, y0 - y, R, G, B);
        //4 O'Clock
        Put_Pixel(x0 + x, y0 - y, R, G, B);
        //7 O'Clock
        Put_Pixel(x0 - y, y0 - x, R, G, B);
        //5 O'Clock
        Put_Pixel(x0 + y, y0 - x, R, G, B);
    
        y++;
        if (radiusError < 0)
          radiusError += (int16_t)(2 * y + 1);
        else
          {
          x--;
          radiusError += 2 * (((int16_t) y - (int16_t) x) + 1);
          }
        }
      }
    
    //
    // Function to configure SPI A in FIFO mode.
    //
    void initSPI()
    {
        //
        // Must put SPI into reset before configuring it.
        //
        SPI_disableModule(SPIA_BASE);
    
        //
        // SPI configuration. Use a 1MHz SPICLK and 8-bit word size.
        //
        SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA1,
                      SPI_MODE_MASTER, 1000000, 8);
        //SPI_enableLoopback(SPIA_BASE);
        SPI_setEmulationMode(SPIA_BASE, SPI_EMULATION_STOP_AFTER_TRANSMIT);
    
        //
        // Configuration complete. Enable the module.
        //
        SPI_enableModule(SPIA_BASE);
    }
    
    //============================================================================
    void main(void)
    {
        uint16_t i;
        uint16_t x;
        uint16_t sub_x;
        uint16_t y;
        uint16_t sub_y;
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize GPIOs on LaunchPad for LCD SPI and control pins
        //
        // LCD_SPI_MOSI
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SPISIMOA,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SPISIMOA);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SPISIMOA,GPIO_QUAL_ASYNC);
    
        // LCD_SPI_MISO
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SPISOMIA,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SPISOMIA);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SPISOMIA,GPIO_QUAL_ASYNC);
    
        // LCD_SPI_CLK
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SPICLKA,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SPICLKA);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SPICLKA,GPIO_QUAL_ASYNC);
    
        // LCD_SPI_CS
        GPIO_setPadConfig(DEVICE_GPIO_PIN_LCD_SPI_CS,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_LCD_SPI_CS);
        GPIO_setDirectionMode(DEVICE_GPIO_PIN_LCD_SPI_CS,GPIO_DIR_MODE_OUT);
    
        // LCD_RST
        GPIO_setPadConfig(DEVICE_GPIO_PIN_LCD_RST,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_LCD_RST);
        GPIO_setDirectionMode(DEVICE_GPIO_PIN_LCD_RST,GPIO_DIR_MODE_OUT);
    
        // LCD_RS
        GPIO_setPadConfig(DEVICE_GPIO_PIN_LCD_RS,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_LCD_RS);
        GPIO_setDirectionMode(DEVICE_GPIO_PIN_LCD_RS,GPIO_DIR_MODE_OUT);
    
        //
        // Initialize the SPI
        //
        initSPI();
    
    
        //Drive the LCD controls pins to a reasonable starting state.
        LCD_RST_LOW;
        LCD_RST_HIGH;
        LCD_RST_LOW;
        LCD_RS_LOW;
        LCD_SPI_CS_HIGH;
    
        //Initialize the LCD controller
        Initialize_LCD();
    
        while(1)
        {
            //Fill display with a given RGB value
            Fill_LCD(0x00,0x00,0xFF);
            msdelay(1000);
    
            //Draw a cyan circle
            LCD_Circle(64, 64, 63,0x00,0xFF,0xFF);
            //Draw a green circle
            LCD_Circle(21, 64, 20,0x00,0xFF,0x00);
            //Draw a white circle
            LCD_Circle(64, 64, 20,0xFF,0xFF,0xFF);
            //Draw a red circle
            LCD_Circle(107, 64, 20,0xFF,0x00,0x00);
            //Draw a purple circle
            LCD_Circle(64, 107, 16,0xFF,0x00,0xFF);
            //Draw a orange circle
            LCD_Circle(64, 21, 14,0xFF,0xA5,0x00);
            msdelay(1000);
    
            // Fill display with a given RGB value
            Fill_LCD(0x00,0x00,0x00);
            msdelay(1000);
    
            for(i=2;i<60;i+=2)
            {
                LCD_Circle(i+2, 64, i,i<<2,0xff-(i<<2),0x00);
            }
            msdelay(1000);
    
            // Fill display with a given RGB value
            Fill_LCD(0xFF,0x00,0x00);
            msdelay(1000);
    
            //Write a 8x8 checkerboard
            for(x=0;x<=15;x++)
            {
                for(y=0;y<=15;y++)
                {
                    for(sub_x=0;sub_x<=7;sub_x++)
                        for(sub_y=0;sub_y<=7;sub_y++)
                            if(((x&0x01)&&!(y&0x01)) || (!(x&0x01)&&(y&0x01)))
                                Put_Pixel((x<<3)+sub_x,(y<<3)+sub_y, 0x00, 0x00, 0x00);
                            else
                                //Put_Pixel((x<<3)+sub_x,(y<<3)+sub_y, 0xFF, 0xFF-(x<<4), 0xFF-(y<<4));
                                Put_Pixel((x<<3)+sub_x,(y<<3)+sub_y, 0xFF, 0xFF, 0xFF);
                }
            }
            msdelay(1000);
        }
    }
    
    
    

  • Hi Gus,

    Thank you for this example code! It's very helpful.

    By the way, do you know when the example will be released in C2000Ware?

    Best Regards

    Rayna