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

📄 lcd_shrp.c

📁 IAR 开发环境的Cirrus Logic的例程
💻 C
字号:
//****************************************************************************
//
// LCD_shrp.C - Routines to enable and draw on the Sharp LM057QB1T04 LCD 
//              panel (at 320x240 resolution)
//
// Copyright (c) 1998-1999 Cirrus Logic, Inc.
//
//****************************************************************************
#include "ep7312.h"
#include "lib7312.h"

//****************************************************************************
//
// LCDEnable initializes the control logic for the LCD panel.
//
//****************************************************************************
void
LCDEnable(void)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;
    unsigned long ulLcdConfig, ulLineLength, ulVideoBufferSize;

    //
    // Determine the value to be programmed into the LCD controller in the
    // EP7312 to properly drive the Sharp monochrome LCD panel at 320x240,
    // 4 bits per pixel, at 75Hz.
    //
    ulVideoBufferSize = (((320 * 240 * 4) * 2) / 128) - 1;
    ulLineLength = ((320 * 2) / 16) - 1;
    ulLcdConfig = HwLcdControlGreyEnable |
                  HwLcdControlGrey4Or2 |
                  (13 << HwLcdControlAcPrescaleShift) |
                  (1 << HwLcdControlPixelPrescaleShift) |
                  (ulLineLength << HwLcdControlLineLengthShift) |
                  (ulVideoBufferSize << HwLcdControlBufferSizeShift);

    //
    // Configure the palette to be a one-to-one mapping of the pixel values to
    // the available LCD pixel intensities.
    //
    pulPtr[HwPaletteLSW >> 2] = 0x76543210;
    pulPtr[HwPaletteMSW >> 2] = 0xFEDCBA98;

    //
    // Program the LCD controller with the previously determined configuration.
    //
    pulPtr[HwLcdControl >> 2] = ulLcdConfig;

    //
    // Set the LCD frame buffer start address.
    //
    pulPtr[HwLcdFrameBuffer >> 2] = HwLcdBaseAddress >> 28;
}



//****************************************************************************
//
// LCDOn turns on the LCD panel.
//
//****************************************************************************
void
LCDOn(void) 
{
    unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;
    int iDelay;

    //
    // Power up the LCD controller.
    //
    pulPtr[HwControl >> 2] |= HwControlLcdEnable;  

    //
    // Power up the LCD panel.
    //
    ((unsigned char *)pulPtr)[HwPortD] |= HwPortDLCDPower;

    //
    // Delay for a little while.
    //
    for(iDelay = 0; iDelay < 65536 * 4; iDelay++)
    {
    }

    //
    // Power up the LCD DC-DC converter.
    //
    ((unsigned char *)pulPtr)[HwPortD] |= HwPortDLCDDcDcPower;
}

//****************************************************************************
//
// LCDOff turns off the LCD panel.
//
//****************************************************************************
void
LCDOff(void)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;
    int iDelay;

    //
    // Power off the LCD DC-DC converter.
    //
    ((unsigned char *)pulPtr)[HwPortD] &= ~HwPortDLCDDcDcPower;

    //
    // Delay for a little while.
    //
    for(iDelay = 0; iDelay < 65536 * 4; iDelay++)
    {
    }

    //
    // Power off the LCD panel.
    //
    ((unsigned char *)pulPtr)[HwPortD] &= ~HwPortDLCDPower;

    //
    // Power off the LCD controller.
    //
    pulPtr[HwControl >> 2] &= ~HwControlLcdEnable;
}

//****************************************************************************
//
// LCDCls clears the LCD frame buffer.
//
//****************************************************************************
void
LCDCls(void)
{
    unsigned long *pulPtr = (unsigned long *)HwLcdBaseAddress;
    int iIdx;

    //
    // Fill the frame buffer with zeros.
    //
    for(iIdx = 0; iIdx < ((320 * 240) / 4); iIdx++)
    {
        *pulPtr++ = 0;
    }
}


//****************************************************************************
//
// LCD_Fill fills the LCD frame buffer.
//
//****************************************************************************
void LCD_Fill(void)
{
    unsigned long *pulPtr = (unsigned long *)HwLcdBaseAddress;
    int iIdx;

    //
    // Fill the frame buffer with ones.
    //
    for(iIdx = 0; iIdx < ((320 * 240) / 4); iIdx++)
    {
        *pulPtr++ = 15;
    }
}

//****************************************************************************
//
// LCDSetPixel changes the color of the specified pixel to the specified
// color.
//
//****************************************************************************
void
LCDSetPixel(long lX, long lY, char cColor)
{
    unsigned char * volatile pucPtr;

    //
    // Make sure the specified pixel is valid.
    //
    if((lX < 0) || (lX >= 320) || (lY < 0) || (lY >= 240))
    {
        return;
    }

    //
    // Compute the address of the pixel.  For each word of the frame buffer,
    // only the high bytes are visible. So, we only put data into the top two
    // bytes of each word.
    //
    if ((lX % 4) > 1)
    {
	pucPtr = (unsigned char *)(HwLcdBaseAddress + (lY * 320) + (((lX /4) * 4) + 3));
    }
    else
    {
	pucPtr = (unsigned char *)(HwLcdBaseAddress + (lY * 320) + (((lX /4) * 4) + 2));
    }
    
    //
    // Set the appropriate pixel based on the value of lX.
    //
    if(lX & 1)
    {
        *pucPtr = (*pucPtr & 0x0F) | (cColor << 4);
    }
    else
    {
        *pucPtr = (*pucPtr & 0xF0) | cColor;
    }
}

//****************************************************************************
//
// LCDGetPixel returns the color of the specified pixel.
//
//****************************************************************************
char
LCDGetPixel(long lX, long lY)
{
    unsigned char * volatile pucPtr;

    //
    // Make sure the specified pixel is valid.
    //
    if((lX < 0) || (lX >= 320) || (lY < 0) || (lY >= 240))
    {
        return(0);
    }

    //
    // Compute the address of the pixel.  For each word of the frame buffer,
    // only the high bytes are visible. So, we only put data into the top two
    // bytes of each word.
    //
    if ((lX % 4) > 1)
    {
	pucPtr = (unsigned char *)(HwLcdBaseAddress + (lY * 320) + (((lX /4) * 4) + 3));
    }
    else
    {
	pucPtr = (unsigned char *)(HwLcdBaseAddress + (lY * 320) + (((lX /4) * 4) + 2));
    }

    //
    // Return the appropriate pixel based on the value of lX.
    //
    if(lX & 1)
    {
        return((*pucPtr & 0xF0) >> 4);
    }
    else
    {
        return(*pucPtr & 0x0F);
    }
}

//****************************************************************************
//
// LCDBacklightOn turns on the backlighting on the LCD panel.
//
//****************************************************************************
void
LCDBacklightOn(void)
{
    unsigned char * volatile pucPtr = (unsigned char *)HwBaseAddress;

    //
    // The backlighting is controlled on the evaluation board by a bit in the
    // GPIO port D.
    //
    pucPtr[HwPortD] |= HwPortDLCDBacklightPower;
}

//****************************************************************************
//
// LCDBacklightOff turns off the backlighting on the LCD panel.
//
//****************************************************************************
void
LCDBacklightOff(void)
{
    unsigned char * volatile pucPtr = (unsigned char *)HwBaseAddress;

    //
    // The backlighting is controlled on the evaluation board by a bit in the
    // GPIO port D.
    //
    pucPtr[HwPortD] &= ~HwPortDLCDBacklightPower;
}

⌨️ 快捷键说明

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