⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kitronix320x240x16_ssd2119_8bit.c

📁 基于TI公司Cortex-M3的uart超级通信开发
💻 C
📖 第 1 页 / 共 3 页
字号:

    //
    // Set the LCD control pins to their default values.  This also asserts the
    // LCD reset signal.
    //将控制线设置为默认值,同时声明一个复位信号
    GPIOPinWrite(LCD_DATAH_BASE, LCD_DATAH_PINS, 0x00);
    GPIOPinWrite(LCD_DC_BASE, LCD_DC_PIN, 0x00);
    GPIOPinWrite(LCD_RD_BASE, LCD_RD_PIN, LCD_RD_PIN);
    GPIOPinWrite(LCD_WR_BASE, LCD_WR_PIN, LCD_WR_PIN);
    GPIOPinWrite(LCD_RST_BASE, LCD_RST_PIN, 0x00);

    //
    // Delay for 1ms.
    //
    SysCtlDelay(ulClockMS);

    //
    // Deassert the LCD reset signal.
    //清除rest 信号
    GPIOPinWrite(LCD_RST_BASE, LCD_RST_PIN, LCD_RST_PIN);

    //
    // Delay for 1ms while the LCD comes out of reset.
    //
    SysCtlDelay(ulClockMS);
}

//*****************************************************************************
//
// Initialize the low level LCD communication when the SRAM/Flash daughter
// board is connected.
//
// This function sets up the low level LCD access function pointers correctly
// when the SRAM/Flash daughter board is present.  In this case, communication
// with the LCD panel is via the EPI rather than via the basic GPIO interface.
// On exit, the LCD controller has been reset and is ready to receive command
// and data writes.
//
// \return None.
//
//*****************************************************************************
static void
InitSRAMDaughterLCDInterface(unsigned long ulClockMS)
{
    //
    // Set the low level access function pointers so that the EPI interface is
    // used to access the LCD controller.
    //
    WriteData = WriteDataEPI;
    WriteCommand = WriteCommandEPI;

    //
    // Asserts the LCD reset signal.
    //声明一个LCD复位信号
    HWREGB(LCD_CONTROL_CLR_REG) = LCD_CONTROL_NRESET;

    //
    // Delay for 1ms.
    //
    SysCtlDelay(ulClockMS);

    //
    // Deassert the LCD reset signal
    //取消复位信号
    HWREGB(LCD_CONTROL_SET_REG) = LCD_CONTROL_NRESET;

    //
    // Delay for 1ms while the LCD comes out of reset.
    //
    SysCtlDelay(ulClockMS);

    //
    // Turn on the backlight.
    //打开背光
    GPIOPinTypeGPIOOutput(LCD_BACKLIGHT_BASE, LCD_BACKLIGHT_PIN);
    GPIOPinWrite(LCD_BACKLIGHT_BASE, LCD_BACKLIGHT_PIN, LCD_BACKLIGHT_PIN);
}

//*****************************************************************************
//
//! Initializes the display driver.
//!
//! This function initializes the SSD2119 display controller on the panel,
//! preparing it to display data.
//!
//! \return None.
//
//*****************************************************************************
void
Kitronix320x240x16_SSD2119Init(void)
{
    unsigned long ulClockMS, ulCount;

    //
    // Get the current processor clock frequency.
    //获取当前始终频率
    ulClockMS = SysCtlClockGet() / (3 * 1000);

    //
    // Perform low level interface initialization depending upon how the LCD
    // is connected to the Stellaris microcontroller.  This varies depending
    // upon the daughter board connected it is possible that a daughter board
    // can drive the LCD directly rather than via the basic GPIO interface.
    //根据不同的开发板进行不同的初始化设置
    switch(g_eDaughterType)
    {
        case DAUGHTER_NONE://通过GPIO接口进行驱动
        default:
        {
            //
            // Initialize the GPIOs used to interface to the LCD controller.
            //
            InitGPIOLCDInterface(ulClockMS);
            break;
        }

        case DAUGHTER_SRAM_FLASH://直接进行驱动,通过EPI接口
        {
            //
            // Initialize the display via the EPI interface to the LCD.
            //
            InitSRAMDaughterLCDInterface(ulClockMS);
            break;
        }
    }
    
    // POWER ON SEQUENCE依次顺序通电
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x001C);
    WriteCommand(S6D0154_PWR_CTRL_3_REG);
    WriteData(0x1212);
    WriteCommand(S6D0154_PWR_CTRL_4_REG);
    WriteData(0x0041);
    WriteCommand(S6D0154_PWR_CTRL_5_REG);
    WriteData(0x426A);
    WriteCommand(S6D0154_PWR_CTRL_1_REG);
    WriteData(0x0C00);
    SysCtlDelay(20 * ulClockMS);
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x011C);
    SysCtlDelay(10 * ulClockMS);
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x011C);
    SysCtlDelay(10 * ulClockMS);
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x031C);
    SysCtlDelay(10 * ulClockMS);
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x071C);
    SysCtlDelay(10 * ulClockMS);
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x0F1C);
    SysCtlDelay(20 * ulClockMS);
    WriteCommand(S6D0154_PWR_CTRL_2_REG);
    WriteData(0x0F3C);
    SysCtlDelay(30 * ulClockMS);
    
    // OTHER MODE SET
    WriteCommand(S6D0154_DRIVER_OPT_CTRL_REG);
    WriteData(0x0128);
    WriteCommand(S6D0154_DRV_WAVEFORM_CTRL_REG);
    WriteData(0x0100);
    WriteCommand(S6D0154_ENTRY_MODE_REG);
    WriteData(0x1028);
    WriteCommand(S6D0154_BLANK_PERIOD_CTRL_REG);
    WriteData(0x0808);
    WriteCommand(S6D0154_FRAME_CYCLE_CTRL_REG);
    WriteData(0x1105); 
    WriteCommand(S6D0154_EXTERNAL_IF_CTRL_REG);
    WriteData(0x0000);
    WriteCommand(S6D0154_MODE_REG);
    WriteData(0x0200);
    WriteCommand(S6D0154_START_OSC_REG);
    WriteData(0x1801);
    WriteCommand(S6D0154_VCI_RECYCLING_REG);
    WriteData(0x0020); 
    
    // Gamma set
    WriteCommand(S6D0154_GAMMA_CTRL_1_REG);
    WriteData(0x0101);
    WriteCommand(S6D0154_GAMMA_CTRL_2_REG);
    WriteData(0x0903);
    WriteCommand(S6D0154_GAMMA_CTRL_3_REG);
    WriteData(0x0E0E);
    WriteCommand(S6D0154_GAMMA_CTRL_4_REG);
    WriteData(0x0001);
    WriteCommand(S6D0154_GAMMA_CTRL_5_REG);
    WriteData(0x0101);
    WriteCommand(S6D0154_GAMMA_CTRL_6_REG);
    WriteData(0x0D06);
    WriteCommand(S6D0154_GAMMA_CTRL_7_REG);
    WriteData(0x0E0E);
    WriteCommand(S6D0154_GAMMA_CTRL_8_REG);
    WriteData(0x0100);
    WriteCommand(S6D0154_GAMMA_CTRL_9_REG);
    WriteData(0x081F);
    WriteCommand(S6D0154_GAMMA_CTRL_10_REG);
    WriteData(0x0200);

    // Display on sequence
    WriteCommand(S6D0154_DISPLAY_CTRL_REG);
    WriteData(0x0010);
    WriteCommand(S6D0154_DISPLAY_CTRL_REG);
    WriteData(0x0012);
    SysCtlDelay(10 * ulClockMS);
    WriteCommand(S6D0154_DISPLAY_CTRL_REG);
    WriteData(0x0012);
    WriteCommand(S6D0154_DISPLAY_CTRL_REG);
    WriteData(0x0013);
    SysCtlDelay(10 * ulClockMS);
    WriteCommand(S6D0154_DISPLAY_CTRL_REG);
    WriteData(0x0017);

    
    WriteCommand(S6D0154_H_WINDOW_END_REG);
    WriteData(0x00ef);
    WriteCommand(S6D0154_H_WINDOW_START_REG);
    WriteData(0x0000);

    WriteCommand(S6D0154_V_WINDOW_END_REG);
    WriteData(0x013f);
    WriteCommand(S6D0154_V_WINDOW_START_REG);
    WriteData(0x0000);

    WriteCommand(S6D0154_H_RAM_ADDR_REG);
    WriteData(0x00ef);
    WriteCommand(S6D0154_V_RAM_ADDR_REG);
    WriteData(0x0000);

    WriteCommand(S6D0154_RAM_DATA_REG);

    for(ulCount = 0; ulCount < (320 * 240); ulCount++)
    {
        WriteData(0x0000);
    }
}

//*****************************************************************************
//
//! Draws a pixel on the screen.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX is the X coordinate of the pixel.
//! \param lY is the Y coordinate of the pixel.
//! \param ulValue is the color of the pixel.
//!
//! This function sets the given pixel to a particular color.  The coordinates
//! of the pixel are assumed to be within the extents of the display.
//!
//! \return None.
//在屏幕(x,y)处显示一个像素值为uValue的点
//*****************************************************************************
static void
Kitronix240x320x16_SD60154PixelDraw(void *pvDisplayData, long lX, long lY,
                                   unsigned long ulValue)
{
 
    //
    // Set the X address of the display cursor.
    //
    WriteCommand(S6D0154_H_RAM_ADDR_REG);
    WriteData(MAPPED_X(lX, lY));

    //
    // Set the Y address of the display cursor.
    //
    WriteCommand(S6D0154_V_RAM_ADDR_REG);
    WriteData(MAPPED_Y(lX, lY));

    //
    // Write the pixel value.
    //
    WriteCommand(S6D0154_RAM_DATA_REG);
    WriteData(ulValue);

}

//*****************************************************************************
//
//! Draws a horizontal sequence of pixels on the screen.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX is the X coordinate of the first pixel.
//! \param lY is the Y coordinate of the first pixel.
//! \param lX0 is sub-pixel offset within the pixel data, which is valid for 1
//! or 4 bit per pixel formats.
//! \param lCount is the number of pixels to draw.
//! \param lBPP is the number of bits per pixel; must be 1, 4, or 8.
//! \param pucData is a pointer to the pixel data.  For 1 and 4 bit per pixel
//! formats, the most significant bit(s) represent the left-most pixel.
//! \param pucPalette is a pointer to the palette used to draw the pixels.
//!
//! This function draws a horizontal sequence of pixels on the screen, using
//! the supplied palette.  For 1 bit per pixel format, the palette contains
//! pre-translated colors; for 4 and 8 bit per pixel formats, the palette
//! contains 24-bit RGB values that must be translated before being written to
//! the display.
//!
//! \return None.
//
//*****************************************************************************
static void
Kitronix240x320x16_SD60154PixelDrawMultiple(void *pvDisplayData, long lX,
                                           long lY, long lX0, long lCount,
                                           long lBPP,
                                           const unsigned char *pucData,
                                           const unsigned char *pucPalette)
{
    unsigned long ulByte;

    //
    // Set the cursor increment to left to right, followed by top to bottom.
    //
    WriteCommand(S6D0154_ENTRY_MODE_REG);
    WriteData(MAKE_ENTRY_MODE(HORIZ_DIRECTION));

    //
    // Set the starting X address of the display cursor.
    //
    WriteCommand(S6D0154_H_RAM_ADDR_REG);
    WriteData(MAPPED_X(lX, lY));

    //
    // Set the Y address of the display cursor.
    //
    WriteCommand(S6D0154_V_RAM_ADDR_REG);
    WriteData(MAPPED_Y(lX, lY));

    //
    // Write the data RAM write command.
    //
    WriteCommand(S6D0154_RAM_DATA_REG);

    //
    // Determine how to interpret the pixel data based on the number of bits
    // per pixel.
    //根据不同的像素位数,执行不同的操作
    switch(lBPP)
    {
        //
        // The pixel data is in 1 bit per pixel format.
        //
        case 1:
        {
            //
            // Loop while there are more pixels to draw.
            //
            while(lCount)
            {
                //
                // Get the next byte of image data.
                //
                ulByte = *pucData++;

                //
                // Loop through the pixels in this byte of image data.
                //
                for(; (lX0 < 8) && lCount; lX0++, lCount--)
                {
                    //
                    // Draw this pixel in the appropriate color.
                    //
                    WriteData(((unsigned long *)pucPalette)[(ulByte >>
                                                             (7 - lX0)) & 1]);
                }

                //
                // Start at the beginning of the next byte of image data.
                //
                lX0 = 0;
            }

            //
            // The image data has been drawn.
            //
            break;
        }

        //
        // The pixel data is in 4 bit per pixel format.
        //
        case 4:
        {
            //
            // Loop while there are more pixels to draw.  "Duff's device" is
            // used to jump into the middle of the loop if the first nibble of
            // the pixel data should not be used.  Duff's device makes use of
            // the fact that a case statement is legal anywhere within a
            // sub-block of a switch statement.  See
            // http://en.wikipedia.org/wiki/Duff's_device for detailed
            // information about Duff's device.
            //
            switch(lX0 & 1)
            {
                case 0:
                    while(lCount)
                    {
                        //
                        // Get the upper nibble of the next byte of pixel data
                        // and extract the corresponding entry from the
                        // palette.
                        //
                        ulByte = (*pucData >> 4) * 3;
                        ulByte = (*(unsigned long *)(pucPalette + ulByte) &
                                  0x00ffffff);

                        //
                        // Translate this palette entry and write it to the
                        // screen.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -