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

📄 lcd_st7032.c

📁 7032显示屏的驱动源码。经过测试可以放心使用。
💻 C
字号:
/** * @file lcd_st7032.c * * @ingroup AlphaNumeric LCD Drivers * * @brief This is the software driver for Sitronix ST7032 Compatible LCD devices *        It supports 4-bit and 8-bit variants of the display - 2 line *         *//**************************** INCLUDES ****************************************/#if defined (LCD_TYPE_ST7032_4BIT) || defined(LCD_TYPE_ST7032_8BIT)/*** Include these before any other include to ensure TBI used correctly** All METAG and METAC values from machine.inc and then tbi.*/#define METAG_ALL_VALUES#define METAC_ALL_VALUES#include <metag/machine.inc>#include <metag/metagtbi.h>#include <MeOS.h>#include "fsdefs.h"#include "section.h"#include "chorus2_hw.h"#include "lcd_alphadrv.h"#include "lcd_api.h"#include "lcd_data.h"#ifndef TRUE#define TRUE  (1)#endif/**************************** PRIVATE MACROS **********************************//**************************** PRIVATE (GLBL) DATA DECLARATIONS ****************//*! QIO device descriptor */static QIO_DEVICE_T lcdDevice;/*! MeOS pool containing unused transaction buffers */static KRN_POOL_T transBufferPool;/*! QIO control blocks */static QIO_IOCB_T iocb[MAX_TRANSACTION];/*! MeOS pool containing unused QIO control blocks */static KRN_POOL_T iocbPool;#ifdef LCD_TYPE_ST7032_8BIT//Initialisation sequence for 8 bit devicestatic const unsigned int initLength = LCD_INIT_LENGTH_8_BIT;static unsigned char lcdInitString[LCD_INIT_LENGTH_8_BIT] ={ LCD_INIT8_CMD0, LCD_INIT8_CMD1, LCD_INIT8_CMD2, LCD_INIT8_CMD3,  LCD_INIT8_CMD4, LCD_INIT8_CMD5, LCD_INIT8_CMD6 };#elif defined (LCD_TYPE_ST7032_4BIT)//Initialisation sequence for 4 bit deviceconst static unsigned int initLength = LCD_INIT_LENGTH_4_BIT;static unsigned char lcdInitString[LCD_INIT_LENGTH_4_BIT] ={ LCD_INIT4_CMD0, LCD_INIT4_CMD1, LCD_INIT4_CMD2, LCD_INIT4_CMD3,  LCD_INIT4_CMD4, LCD_INIT4_CMD5, LCD_INIT4_CMD6, LCD_INIT4_CMD7, LCD_INIT4_CMD8, LCD_INIT4_CMD9};#else#error Unknown LCD type#endif/// Instructions required to reset cursor to start of each display linestatic const unsigned char lcdResetCursor[] ={ LCD_LINE0_BASE, LCD_LINE1_BASE, LCD_LINE2_BASE, LCD_LINE3_BASE };/**************************** PRIVATE FUNCTION DEFINITIONS  *******************//** * QIO Completion function for LCD Transaction data transfers for ST7032 * * QIO completion function, returns iocb and transaction buffers to their pools * on completion of a transaction. * * @param     *dev                Standard QIO device parameter. * @param     *iocb               Standard QIO IOCB parameter. * @param     *ioPars             Standard QIO IO pars parameter. * @param     *status             Standard QIO status parameter. * @return                        TRUE (to satisfy QIO) */static int LCD_ST7032_CompFunc(QIO_DEVICE_T *dev, QIO_IOCB_T *iocb, QIO_IOPARS_T *ioPars, QIO_STATUS_T status){    (void)dev;      // make compiler happy as this parameter is not used    (void)status;   // make compiler happy as this parameter is not used    //Ensure that the IOCB and transaction buffer are released to the pool in    //the same order that they are taken!    KRN_returnPool(iocb);    KRN_returnPool(ioPars->pointer);    return TRUE;}/**************************** PUBLIC FUNCTION DEFINITIONS  ********************/LCD_RETURN_T LCD_ST7032_AlphaInit (const LCD_DEVICE_T *info){    unsigned long  i;               //temporary 32-bit variable    unsigned char *transPtr;        //temporary pointer to buffer    LCD_TBUF_T    *transBuf;        //pointer to transaction buffer    QIO_IOPARS_T   iopars;          //IO parameter block    QIO_IOCB_T    *iocbPtr;         //pointer to IO control block    LCD_INIT_PARAM_T initParam;    //Copy over device parameters    lcdInfo = *info;    /* Fill in other fields */    lcdInfo.blankChar = LCD_BLANK_CHAR;    //decolare special character controls (if supported)    lcdInfo.specChar.maxCode = LCD_SPECCHAR_MAX_CODE;    lcdInfo.specChar.baseInst = LCD_SPECCHAR_BASE_INST;    lcdInfo.specChar.baseCode = LCD_SPECCHAR_BASE_CODE;    if ((lcdInfo.width > PLATFORM_LCD_WIDTH) || (lcdInfo.height > PLATFORM_LCD_HEIGHT))        return LCD_ERR_PARAM;    initParam.inst[0] = LCD_REG0_VALUE(P_H_WIDTH_INST, P_H_DELAY_INST, D_PERIOD_INST);    initParam.data[0] = LCD_REG0_VALUE(P_H_WIDTH_DATA, P_H_DELAY_DATA, D_PERIOD_DATA);    initParam.inst[1] = LCD_REG1_VALUE(T_DIVISOR_INST);    initParam.data[1] = LCD_REG1_VALUE(T_DIVISOR_DATA);#ifdef LCD_TYPE_ST7032_8BIT    //Set up 8-bit instruction and data commands    initParam.inst[2] = LCD_REG2_VALUE(RS_INSTRUCTION, BYTE_MODE, NO_SWAP);    initParam.data[2] = LCD_REG2_VALUE(RS_DATA, BYTE_MODE, NO_SWAP);#else // ifdef LCD_TYPE_ST7032_4BIT   Set up 4-bit instruction and data commands    initParam.inst[2] = LCD_REG2_VALUE(RS_INSTRUCTION, NIBBLE_MODE, NIBBLE_SWAP);    initParam.data[2] = LCD_REG2_VALUE(RS_DATA, NIBBLE_MODE, NIBBLE_SWAP);#endif // end of LCD_TYPE_ST7032S0066U_8BIT    initParam.dmaChannel = info->dmaChannel;    //Initialise the device driver    QIO_init(&lcdDevice, "LCD device", (unsigned int)&initParam, &LCD_driver);    //Enable the device in QIO    QIO_enable(&lcdDevice);    //initialise pool of transaction buffers.	KRN_initPool(&transBufferPool, (void*)lcdTransBuffer, MAX_TRANSACTION, sizeof(LCD_TBUF_T));    //initialise pool of IOCBs    KRN_initPool(&iocbPool, iocb, MAX_TRANSACTION, sizeof(QIO_IOCB_T));    //Send initialisation sequence to LCD driver    //Get IOCB and transaction buffer    iocbPtr = KRN_takePool(&iocbPool, -1);    transBuf = KRN_takePool(&transBufferPool, -1);    //Assign IO parameters and copy initialisation command sequence to transaction buffer    iopars.pointer = transBuf;    iopars.counter = 0;    transPtr = transBuf->buffer;    iopars.opcode  = initLength;    for (i = 0; i < initLength; i++)        *transPtr++ = lcdInitString[i];    //Send initialisation transaction to the QIO    QIO_qio(&lcdDevice, iocbPtr, &iopars, NULL, LCD_ST7032_CompFunc, -1);    return LCD_OK;}LCD_RETURN_T LCD_ST7032_AlphaSpecialChar (const unsigned long  code, const unsigned char *buf){    unsigned long  i;               //loop counter    signed long    codeUsed;        //ASCII code to access character (signed for error reporting)    unsigned long  instUsed;        //instruction for LCD controller    unsigned char *transPtr;        //temporary pointer to buffer    LCD_TBUF_T    *transBuf;        //pointer to transaction buffer    QIO_IOPARS_T   iopars;          //IO parameter block    QIO_IOCB_T    *iocbPtr;         //pointer to IO control block    //Check that code is valid    if (code > lcdInfo.specChar.maxCode)    {        return LCD_ERR_CODE;    }    else    {        //CGRAM range for character 0 is: 000000b -> 000111b        //assume that for character 1 is: 001000b -> 001111b        //etc... up to character 7 being: 111000b -> 111111b        //Hence offset for character X is: (X << 3)        instUsed = (lcdInfo.specChar.baseInst + (code << 3));        //Code used to access programmed character is 0x08 -> 0x0F (ST7032)        codeUsed = (lcdInfo.specChar.baseCode + code);        //Get IOCB and transaction buffer        iocbPtr = KRN_takePool(&iocbPool, -1);        transBuf = KRN_takePool(&transBufferPool, -1);        //Assign IO parameters        iopars.pointer = transBuf;          //transaction buffer        iopars.opcode = 2;                  //Number of instruction bytes        iopars.counter = 8;                 //Number of data bytes        //Copy command and data sequence to transaction buffer        transPtr = transBuf->buffer;#ifdef LCD_TYPE_ST7032_8BIT        *transPtr++ = 0x80;        *transPtr++ = instUsed;#else   // LCD_TYPE_ST7032_4BIT        *transPtr++ = LCD_INIT4_CMD2 & ~1;        *transPtr++ = instUsed;#endif // LCD_TYPE_ST7032_8BIT        for (i = 0; i < 8; i++)        {            *transPtr++ = *buf++;        }        //Send transaction to the QIO system        QIO_qio(&lcdDevice, iocbPtr, &iopars, NULL, LCD_ST7032_CompFunc, -1);        return codeUsed;    }}LCD_RETURN_T LCD_ST7032_Transaction (const short x, const short y, const unsigned short numChar, const unsigned char *str){    unsigned long  i;    unsigned char  cursor;    unsigned char *transPtr;        //temporary pointer to buffer    LCD_TBUF_T    *transBuf;        //pointer to transaction buffer    QIO_IOPARS_T   iopars;          //IO parameter block    QIO_IOCB_T    *iocbPtr;         //pointer to IO control block    //check length of string    if (numChar > PLATFORM_LCD_WIDTH)        return LCD_ERR_LENGTH;    //Get IOCB and transaction buffer    iocbPtr = KRN_takePool(&iocbPool, -1);    transBuf = KRN_takePool(&transBufferPool, -1);    //Assign IO parameters    iopars.pointer = transBuf;      //transaction buffer    iopars.opcode  = 1;             //number of instruction bytes    iopars.counter = numChar;       //number of data bytes    //Set cursor to correct line on the LCD    cursor = lcdResetCursor[y];    //Move cursor to 1st location in window    cursor += x;    //Set up transaction buffer: first assign the cursor location (instruction)    transPtr = transBuf->buffer;    *transPtr++ = cursor;    //Next fill in data to be displayed    if (str == NULL)    {        //Fill with blanks if no string ('clear' command)        for (i = 0; i < numChar; i++)            *transPtr++ = lcdInfo.blankChar;    }    else    {        //Copy in string to be displayed        for (i = 0; i < numChar; i++)            *transPtr++ = *str++;    }    //Send transaction to the QIO system    QIO_qio(&lcdDevice, iocbPtr, &iopars, NULL, LCD_ST7032_CompFunc, -1);    return LCD_OK;}void LCDContrast(unsigned long contrastValue IGNORE_NON_USE){}#endif // defined(LCD_TYPE_ST7032_8BIT) || defined(LCD_TYPE_ST7032_4BIT)

⌨️ 快捷键说明

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