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

📄 lcd_3200.c

📁 DK3200 USB DEMO for KEIL C
💻 C
字号:
 /* `=========================================================================`

                    ***************************************
                  ****   *                           *   ****
                                Title: LCD_3200
                             File name: lcd_3200.c
                           Project name: DK3200 demo
                  ***                                    ****
                    ****************** * ******************
                  ****                                   ****
                              Author: Petr PFEIFER
                           MPG Prague, Czech Republic
                  ****   *                           *   ****
                    ***************************************

                 $Version:  0.029   Build: 2004-03-22,15:42:47




                                  Description:
                                  ============

                               Universal Version

                        *** LCD IO with copy buffer ***

                          USB/IAP project source file

                   Version >= 0.28 reentrant functions added.




                                     Notes:
                                     ======
                      Version 0.020 - Universal structure
                  Version 0.019 - fixed bug in PrinfLC \n part




                           ..........................
                          .                          .
                          .      ******************  .
                          .     **PPPPPPPPPPPPPPPP   .
                          .     *PPPP*******PP****   .
                          .    **PPP********PP***    .
                          .    ***PPP******PP****    .
                          .   *****PPP****PP****     .
                          .   *****PPP****PP****     .
                          .  PPPPPPPP****PP****  (R) .
                          .                          .
                           ..........................


                                  =-=-=-=-=-=
                           =-=-=-=-=-=-=-=-=-=-=-=-=
                =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

                       Copyright 2004 ST Microelectronics

             This code/file is provided as is and has no warranty,
     implied or otherwise.  You are free to use/modify any of the provided
    code at your own risk in your applications with the expressed limitation
        of liability (see below) so long as your product using the code
                 contains at least one uPSD products (device).

                            LIMITATION OF LIABILITY:
                            ========================
              NEITHER STMicroelectronics NOR ITS VENDORS OR AGENTS
      SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
       INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
       CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
         OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

                =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                           =-=-=-=-=-=-=-=-=-=-=-=-=
                                  =-=-=-=-=-=

                   For current information on uPSD products,
                please consult our pages on the World Wide Web:

                                 www.st.com/psm

                            - - - - - - - - - - - -

                     STMicroelectronics GROUP OF COMPANIES
    Australia - Brazil - China - Czech Republic - Finland - France - Germany
   Hong Kong - India - Italy - Japan - Malaysia - Malta - Morocco - Singapore
             Spain - Sweden - Switzerland - United Kingdom - U.S.A.

                               http://www.st.com


 `========================================================================` */

#pragma NOAREGS

#include "upsd3200.h"
#include "lcd_3200.h"
#include "app_intr.h"



// LCD Display copy buffer

xdata DISPLAY LCD_reg _at_ LCD_BASE_ADDR;    // XDATA address for display

#ifdef LCD_BCBuffer
data char LCD_buffer[LCD_ColNumBuf*LCD_RowNum];                    // IAP&D Memory
#endif

data unsigned char LCDDisp_XPos,LCDDisp_YPos;// Actual cursor position

static data uchar Cursor_LCD;

// User design CG data
static uchar code cg_data[] =
 {

  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,

  -1                                         // Terminator, end of data char
 }
  ;





void LCD_delay_ms(int cnt)
/******************************************************************************
 Function   : void delay_xms()
 Parameters : (int cnt)
 Description: Delay
 ******************************************************************************/
 {

  int w;
  while (cnt>0)
   {
    for (w = 0; w<600; w++);                 // 5T/cycle(.33us) =>1.67
    cnt--;
   }
 }





void BusyCheck(void)
/******************************************************************************
 Function   : void BusyCheck()
 Parameters : (void)
 Description: Tests LCD Busy flag, waits until BF is cleared
 ******************************************************************************/
 {
  while (LCD_reg.LCD_CMD_RD & BF_BIT);
 }



void SetUserCG(unsigned char *data_ptr)
/******************************************************************************
 Function   : void SetUserCG()
 Parameters : (unsigned char *data_ptr)
 Description: Sets user character set / initialize user character pattern
 ******************************************************************************/
 {
  BusyCheck();                               // Check display ability to comm.
  LCD_reg.LCD_CMD_WR = CG_ADDR;              // | (8*0);
                                         //start custom char.set from character #0
  while (*data_ptr != -1)
   {
    BusyCheck();
    LCD_reg.LCD_RAM_WR = *data_ptr++;
   }
 }





static char htoa_lo(byte) uchar byte;
/******************************************************************************
 Function   : static char htoa_lo()
 Parameters : (byte)
 Description: converts low nibble of unsigned byte
 ******************************************************************************/
 {
  byte = byte & 0x0F;                        // keep lower nibble only
  if (byte <= 0x09)
  return(byte + 0x30);
  else
  return (byte + 0x37);
 }


static char htoa_hi(byte) uchar byte;
/******************************************************************************
 Function   : static char htoa_hi()
 Parameters : (byte)
 Description: converts hi nibble of unsigned byte
 ******************************************************************************/
 {
  byte = byte & 0xF0;                        // keep upper nibble only
  byte = byte >> 4;
  if (byte <= 0x09)
  return(byte + 0x30);
  else
  return (byte + 0x37);
 }





void initLCD(void)
/******************************************************************************
 Function   : void initLCD()
 Parameters : (void)
 Description: initialize LCD module per specs
 ******************************************************************************/
 {
  #ifdef LCD_BCBuffer
  int i;
  #endif

  LCD_delay_ms(15);
  LCD_reg.LCD_CMD_WR = 0x30;
  LCD_delay_ms(4);
  LCD_reg.LCD_CMD_WR = 0x30;
  LCD_delay_ms(1);
  LCD_reg.LCD_CMD_WR = 0x30;
  LCD_delay_ms(1);

  LCD_reg.LCD_CMD_WR = 0x38;                 // 8 bits, 2 lines, 5 x 7 font
  LCD_delay_ms(4);                           // delay 4 ms
  BusyCheck();
  LCD_reg.LCD_CMD_WR = 0x0C;                 //Display on, Cursor off, Non-Blink
  BusyCheck();
  LCD_reg.LCD_CMD_WR = 0x01;                 //Clear display
  BusyCheck();
  LCD_reg.LCD_CMD_WR = 0x02;                 //Cursor home
  BusyCheck();
  LCD_reg.LCD_CMD_WR = 0x06;                 //Cursor inc, no shift/cursor move

  SetUserCG(&cg_data);                       //set user desfined character

  Cursor_LCD = DD_ADDR;                      //Display from 1st row, 1st column
  BusyCheck();
  LCD_reg.LCD_CMD_WR = Cursor_LCD;

  #ifdef LCD_BCBuffer
                                             // Initialize mirror buffer
  for (i=0;i<LCD_ColNumBuf*LCD_RowNum;i++)   // Clear IAP&D display memory
   {
    LCD_buffer[i] = ' ';
   }
                                           //add user character at the end of line
  LCD_buffer[LCD_ColNum+0] = 13;
  LCD_buffer[LCD_ColNum+1] = 10;          //new line indicator for WinApp terminal

  LCD_buffer[LCD_ColNumBuf+LCD_ColNum+0] = 0;
  LCD_buffer[LCD_ColNumBuf+LCD_ColNum+1] = 0;// END OF STRING
  #endif

  LCDDisp_XPos = 0;                          // Cursor position at home
  LCDDisp_YPos = 0;

//please see LCD_3200.H for more details about the buffer

 }




void putch_LCD(unsigned char ch) 
/******************************************************************************
 Function   : void putch_LCD()
 Parameters : (unsigned char ch)
 Description: basic char out function
 ******************************************************************************/
 {
  BusyCheck();
  LCD_reg.LCD_RAM_WR = ch;

  #ifdef LCD_BCBuffer
  if (LCDDisp_XPos<LCD_ColNum)
   {
    LCD_buffer[LCDDisp_YPos*LCD_ColNumBuf+LCDDisp_XPos] = ch;
   }
  #endif

  if (LCDDisp_XPos <= LCD_ColNum)
   {
    LCDDisp_XPos++;
   }

 }





void printfLCD(uchar *chr_ptr, ...)
/******************************************************************************
 Function   : void printfLCD()
 Parameters : (uchar *chr_ptr, ...)
 Description: works as prinf, but for LCD
 ******************************************************************************/
 {

  unsigned char *var_ptr=&chr_ptr+1;
  unsigned char var;
  unsigned int i;

  while (*chr_ptr != NULL)
   {
    BusyCheck();
    if (*chr_ptr == '\r')
     {
      chr_ptr++;
      Cursor_LCD &= 0xC0;                   //return to position 0 at current line
      LCD_reg.LCD_CMD_WR = Cursor_LCD;

      LCDDisp_XPos = 0;
     }
    else
    if (*chr_ptr == '\n')
     {
      chr_ptr++;
      Cursor_LCD ^= 0x40;                    //goto next line
      Cursor_LCD &= 0xC0;                    //return to position 0
      LCD_reg.LCD_CMD_WR = Cursor_LCD;

      LCDDisp_XPos = 0;
      LCDDisp_YPos = LCDDisp_YPos < LCD_RowNum-1 ? LCDDisp_YPos+1:0;
     }
    else
    if (*chr_ptr == '%')
     {
      chr_ptr++;
      if (*chr_ptr == 'd')                   // display 1 digit decimal 0-9
       {
        chr_ptr++;
        var = *var_ptr++;
        putch_LCD((var & 0x0F)+'0');         // Out character to LCD Display RAM
       }
      else
      if (*chr_ptr == 'x')                   // display 1 byte hex 00-FF
       {
        chr_ptr++;
        var = *var_ptr++;
        putch_LCD(htoa_hi(var));             // Out character to LCD Display RAM
        putch_LCD(htoa_lo(var));             // Out character to LCD Display RAM
       }
      else
      if (*chr_ptr == 'w')                   // display 1 word hex 0000-FFFF
       {
        chr_ptr++;
        var = *var_ptr++;
        putch_LCD(htoa_hi(var));             // Out character to LCD Display RAM
        putch_LCD(htoa_lo(var));             // Out character to LCD Display RAM
        var = *var_ptr++;
        putch_LCD(htoa_hi(var));             // Out character to LCD Display RAM
        putch_LCD(htoa_lo(var));             // Out character to LCD Display RAM
       }
      else
      if (*chr_ptr == 'c')                   // Display 1 character
       {
        chr_ptr++;
        var = *var_ptr++;
        putch_LCD(var);                      // Out character to LCD Display RAM
       }
      else
      if (*chr_ptr == 'B')                   // display 1 byte
       {
        chr_ptr++;
        var = *var_ptr++;
        putch_LCD(48+(var/100));             // Out character to LCD Display RAM
        var = var % 100;
        putch_LCD(48+(var/10));              // Out character to LCD Display RAM
        var = var % 10;
        putch_LCD(48+var);                   // Out character to LCD Display RAM
       }
      else
      if (*chr_ptr == 'W')                   // display 1 word
       {
        chr_ptr++;
        i = (*var_ptr++);
        i = i*256;
        i = i+(*var_ptr++);
        putch_LCD(48+(i/10000));             // Out character to LCD Display RAM
        i = i % 10000;
        putch_LCD(48+(i/1000));              // Out character to LCD Display RAM
        i = i % 1000;
        putch_LCD(48+(i/100));               // Out character to LCD Display RAM
        i = i % 100;
        putch_LCD(48+(i/10));                // Out character to LCD Display RAM
        i = i % 10;
        putch_LCD(48+i);                     // Out character to LCD Display RAM
       }


      else
       {
        putch_LCD(*chr_ptr++);               // Out character to LCD Display RAM
       }

     }
    else
     {
      putch_LCD(*chr_ptr++);                 // Out character to LCD Display RAM
     }
   }
 }



⌨️ 快捷键说明

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