📄 lcd.c
字号:
//*****************************************************************************
//
// lcd.c - Driver for the 320x240 LCD panel.
//
// Copyright (c) 2006-2007 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 220 of sw01246.
//
//*****************************************************************************
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "ssi.h"
#include "lcd.h"
#include "sed1335.h"
//*****************************************************************************
//
//! \page ui_lcd_intro Introduction
//!
//! A Microtips MTG-32240N LCD panel is used for the user interface. It
//! consists of a 320x240 monochrome LCD controlled by an SED1335 (or clone)
//! LCD controller, with a AD7843 (or clone) touch screen controller. The LCD
//! controller has an 8-bit parallel data bus connection to the LM3S316, and
//! the touch screen controller has a SPI connection.
//!
//! This driver handles the LCD controller portion of the panel. The LCD
//! controller supports a pair of frame buffers that can be XOR-ed together
//! while scanning the display. These two frame buffers are utilized to
//! provide the main display image in one buffer and a optional set of blocks
//! in the other buffer. The blocks in the second buffer are used to invert
//! the display image in the first frame buffer, allowing easy highlighting of
//! screen elements (such as an invert to indicate a selection for an on-screen
//! push button).
//!
//! The code for driving the LCD controller is contained in
//! <tt>ui_micro/lcd.c</tt>, with <tt>ui_micro/lcd.h</tt> containing the API
//! definitions for use by the remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup ui_lcd_api Definitions
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! The GPIO pin on port B to which the LCD backlight control is connected.
//
//*****************************************************************************
#define PIN_BACKLIGHT GPIO_PIN_1
//*****************************************************************************
//
//! The GPIO pin on port B to which the LCD A0 signal is connected.
//
//*****************************************************************************
#define PIN_A0 GPIO_PIN_4
//*****************************************************************************
//
//! The GPIO pin on port B to which the LCD WRn signal is connected.
//
//*****************************************************************************
#define PIN_WRn GPIO_PIN_5
//*****************************************************************************
//
//! The GPIO pin on port B to which the LCD E signal is connected.
//
//*****************************************************************************
#define PIN_E GPIO_PIN_6
//*****************************************************************************
//
//! Write a command byte to the LCD panel.
//!
//! \param ucCmd is the command to be sent to the panel.
//!
//! Write a command byte to the SED1335 LCD controller on the panel. The
//! procedure call overhead of calling GPIOPinWrite() provides the timing
//! delays required by the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
LCDCommandWrite(unsigned char ucCmd)
{
//
// Set the address pin high to indicate a command byte.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_A0, PIN_A0);
//
// Drive the E clock high.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_E, PIN_E);
//
// Write the command byte to the data pins.
//
GPIOPinWrite(GPIO_PORTD_BASE, 0xff, ucCmd);
//
// Drive the E clock low.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_E, 0);
}
//*****************************************************************************
//
//! Write a data byte to the LCD panel.
//!
//! \param ucData is the data to be sent to the panel.
//!
//! Write a data byte to the SED1335 LCD controller on the panel. The
//! procedure call overhead of calling GPIOPinWrite() provides the timing
//! delays required by the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
LCDDataWrite(unsigned char ucData)
{
//
// Set the address pin low to indicate a data byte.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_A0, 0);
//
// Drive the E clock high.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_E, PIN_E);
//
// Write the data byte to the data pins.
//
GPIOPinWrite(GPIO_PORTD_BASE, 0xff, ucData);
//
// Drive the E clock low.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_E, 0);
}
//*****************************************************************************
//
//! Initializes the LCD panel.
//!
//! Configure the interface to the LCD panel and initialize the LCD controller
//! on the panel. The panel is configured with two 320x240 frame buffers which
//! are XORed together. The first frame buffer contains the actual display and
//! the second frame buffer is used to provide inversion of selected portions
//! of the display.
//!
//! \return None.
//
//*****************************************************************************
void
LCDInit(void)
{
unsigned long ulIdx;
//
// Set the GPIO pins connected to the LCD panel as outputs.
//
GPIODirModeSet(GPIO_PORTB_BASE, PIN_BACKLIGHT | PIN_A0 | PIN_WRn | PIN_E,
GPIO_DIR_MODE_OUT);
GPIODirModeSet(GPIO_PORTD_BASE, 0xff, GPIO_DIR_MODE_OUT);
//
// Turn on the backlight.
//
GPIOPinWrite(GPIO_PORTB_BASE, PIN_BACKLIGHT, PIN_BACKLIGHT);
//
// Set the data pins, E clock, and RD/WRn pin to zero.
//
GPIOPinWrite(GPIO_PORTD_BASE, 0xff, 0);
GPIOPinWrite(GPIO_PORTB_BASE, PIN_E, 0);
GPIOPinWrite(GPIO_PORTB_BASE, PIN_WRn, 0);
//
// Send the SYSTEM_SET command, which configures the size of the physical
// panel and the logical display buffer.
//
LCDCommandWrite(CMD_SYSTEM_SET);
LCDDataWrite(0x32);
LCDDataWrite(0x07);
LCDDataWrite(0x07);
LCDDataWrite(0x27);
LCDDataWrite(0x2b);
LCDDataWrite(0xef);
LCDDataWrite(0x28);
LCDDataWrite(0x00);
//
// Send the SCROLL command, which configures the address in the LCD
// controller's memory of the two frame buffers.
//
LCDCommandWrite(CMD_SCROLL);
LCDDataWrite(0x00);
LCDDataWrite(0x00);
LCDDataWrite(0xef);
LCDDataWrite(0x00);
LCDDataWrite(0x30);
LCDDataWrite(0xef);
//
// Send the OVLAY command, which configures the first frame buffer in
// graphics mode and sets the frame buffer combination operation to XOR.
//
LCDCommandWrite(CMD_OVLAY);
LCDDataWrite(0x0d);
//
// Send the DISPLAY_OFF command to turn off the display.
//
LCDCommandWrite(CMD_DISPLAY_OFF);
LCDDataWrite(0x00);
//
// Send the CSR_RIGHT command, which set the auto-increment of the frame
// buffer data pointer to +1 (i.e. each subsequent data write will be
// one byte to the right of the previous).
//
LCDCommandWrite(CMD_CSR_RIGHT);
//
// Send the CSRW command, which sets the write cursor address to the
// beginning of the first frame buffer.
//
LCDCommandWrite(CMD_CSRW);
LCDDataWrite(0x00);
LCDDataWrite(0x00);
//
// Send the MWRITE command, which is used to fill the first frame buffer
// memory with all zeros (i.e. a blank display).
//
LCDCommandWrite(CMD_MWRITE);
for(ulIdx = 0; ulIdx < (40 * 240); ulIdx++)
{
LCDDataWrite(0x00);
}
//
// Send the CSRW command, which sets the write cursor address to the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -