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

📄 lcddriver_ts136.c

📁 uc/os运行在tms320lf2407a上
💻 C
📖 第 1 页 / 共 2 页
字号:

/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/
#include "global.c" 
#include "lcd_font.h"
#include "os_cpu.h"

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/
#define LCD_CMD_SET_BIAS                (0xe8)
#define LCD_CMD_SYSTEM_RESET            (0xe2)
#define LCD_CMD_SET_DISPLAY             (0xae)
#define LCD_CMD_SET_PAGE_ADDRESS        (0xb0)
#define LCD_CMD_SET_COLUMN_MSB          (0x10)
#define LCD_CMD_SET_COLUMN_LSB          (0x00)

/****************************************************************************/
/***        Type Definitions                                              ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Function Prototypes                                     ***/
/****************************************************************************/

/****************************************************************************/
/***        Exported Variables                                            ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/
 unsigned int au16Shadow[1024];

/****************************************************************************/
/***        Exported Functions                                            ***/
/****************************************************************************/
/****************************************************************************
 *
 * NAME: vLcdReset
 *
 * DESCRIPTION:
 * Called when bringing LCD out of reset.
 *
 * PARAMETERS:      Name      RW  Usage
 *                  u16Bias    R   Bias value to use (see data sheet) (0-3)
 *                  u16Gain    R   Gain value to use (see data sheet) (0-7)
 *
 * NOTES:
 * Default values are used for most things.
 * It is assumed that a reasonable time has passed since power was applied
 * as 20~30ms is required by LCD.
 *
 ****************************************************************************/
 void vLcdReset(void)
{
    /* Put LCD in to reset */

    /* Clear shadow area to blank */
    vLcdClear();
    vGrabSpiBus(); 
	//new setup command
	vSendCommand(0xe2);
	vSendCommand(0xae);
	vSendCommand(0xc8);
	vSendCommand(0x60);
	vSendCommand(0xa6);
	vSendCommand(0xa2);
	vSendCommand(0xac);
	vSendCommand(0x24);
	vSendCommand(0x81);
	vSendCommand(0x28);
	vSendCommand(0x2f);
	vSendCommand(0xaf);

    /* Refresh display */
    vLcdRefreshAll();
}

/****************************************************************************
 *
 * NAME: vLcdStop
 *
 * DESCRIPTION:
 * Turns off LCD and allows it to power down correctly.
 *
 * NOTES:
 * Should be called before powering down LCD panel.
 *
 ****************************************************************************/
 void vLcdStop(void)
{
    vSendCommand(LCD_CMD_SYSTEM_RESET);
}

/****************************************************************************
 *
 * NAME: vLcdClear
 *
 * DESCRIPTION:
 * Clears the LCD shadow. Does not refresh the display itself
 *
 ****************************************************************************/
 void vLcdClear(void)
{
    unsigned int i, *j;
	
	j = &au16Shadow[0];

    for (i = 0; i < 1024; i++)
    {
        *j = 0;
		j++;
    }

}

/****************************************************************************
 *
 * NAME: vLcdRefreshAll
 *
 * DESCRIPTION:
 * Copies the contents of the shadow memory to the LCD
 *
 * NOTES:
 * Takes a certain amount of time!
 *
 ****************************************************************************/
 void vLcdRefreshAll(void)
{
    unsigned int u16Row;
    unsigned int u16Col;
    unsigned int *pu16Shadow = au16Shadow;

    vGrabSpiBus();

    /* Set row to 0 and column to 0 */

    for (u16Row = 0; u16Row < 8; u16Row++)
    {
    	vSetCDline(0);
    	vSendCommand((unsigned int)(LCD_CMD_SET_PAGE_ADDRESS | u16Row));
        vSendCommand((unsigned int)(LCD_CMD_SET_COLUMN_MSB ));
        vSendCommand((unsigned int)(LCD_CMD_SET_COLUMN_LSB ));
 
        /* Send one word of dummy data (controller has 132 column memory) */
        vSetCDline(1);
        vSendData(0);			//TS136 use 2-129 column,so insert one byte;

        /* Send line of data */
        for (u16Col = 0; u16Col < 128; u16Col += 1)
        {
            /* Send data in 32 bit chunks. Fortunately the byte ordering
               is correct so no swapping about required */
            vSendData(*(unsigned int *)pu16Shadow);
            pu16Shadow += 1;
        }
        
        vSendData(0);
        vSendData(0);
        vSendData(0);
        
    }
    vSetCDline(0);

    vFreeSpiBus();
}

/****************************************************************************
 *
 * NAME: vLcdWriteText
 *
 * DESCRIPTION:
 * Puts text into shadow buffer. Text is aligned to a character row but can
 * be at any column. Characters are variable width but 8 pixels high.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  pcString        R   Pointer to zero-terminated string
 *                  u16Row           R   Character row (0-7)
 *                  u16Column        R   Start column (0-127)
 *
 * NOTES:
 * To see text, perform a refresh
 *
 ****************************************************************************/
 void vLcdWriteText( char *pcString, unsigned int u16Row, unsigned int u16Column)
{
    unsigned int u16Columns;
    unsigned int *pu16CharMap;
    unsigned int *pu16Shadow = &au16Shadow[u16Row * 128 + u16Column];

    /* Column before first character */
    *pu16Shadow = 0;
    pu16Shadow++;

    while (*pcString != 0)
    {
		while(1)
		{
		    if ((*pcString >= '0') && (*pcString <= 'z'))
		    {
		        pu16CharMap = (unsigned int *)au16LcdFont[*pcString - '0'];
				break;
		    }

		    if ((*pcString >= '%') && (*pcString <= ','))
		    {
		        pu16CharMap = (unsigned int *)au16LcdFontWide[*pcString - '%'];
				break;
		    }

		    /* Default is to return a space character */
		    pu16CharMap = (unsigned int *)au16LcdFont[46];
			break;

		}


        u16Columns = *pu16CharMap;

        /* Copy character bitmap to shadow memory */
        do
        {
            pu16CharMap++;
            *pu16Shadow = *pu16CharMap;
            pu16Shadow++;
            u16Columns--;
        } while (u16Columns > 0);

        /* Add a column spacing */
        *pu16Shadow = 0;
        pu16Shadow++;

        pcString++;
    }
}

/****************************************************************************
 *
 * NAME: vLcdWriteInvertedText
 *
 * DESCRIPTION:
 * Puts text into shadow buffer. Text is aligned to a character row but can
 * be at any column. Characters are variable width but 8 pixels high. Text is
 * inverted (black <-> white).
 *
 * PARAMETERS:      Name            RW  Usage
 *                  pcString        R   Pointer to zero-terminated string
 *                  u16Row           R   Character row (0-7)
 *                  u16Column        R   Start column (0-127)
 *
 * NOTES:
 * To see text, perform a refresh
 *
 ****************************************************************************/
 void vLcdWriteInvertedText(char *pcString, unsigned int u16Row, unsigned int u16Column)
{
    unsigned int u16Columns;
    unsigned int *pu16CharMap;
    unsigned int *pu16Shadow = &au16Shadow[u16Row * 128 + u16Column];

    /* Column before first character */
    *pu16Shadow = 0xff;
    pu16Shadow++;

    while (*pcString != 0)
    {

		while(1)
		{

		    if ((*pcString >= '0') && (*pcString <= 'z'))
		    {
		        pu16CharMap = (unsigned int *)au16LcdFont[*pcString - '0'];
				break;
		    }

		    if ((*pcString >= '%') && (*pcString <= ','))

⌨️ 快捷键说明

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