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

📄 display.c

📁 这项工程将让您把自己的MP3播放器平台
💻 C
📖 第 1 页 / 共 2 页
字号:
  WaitBusy();  DisplayWrite(VFD_ESCAPE);
  WaitBusy();  DisplayWrite(VFD_FLICKERLESS);
  WaitBusy();
#endif
  DBGOUT(("Display initialized ...\n"));
}


//++
// Erase (clear) the entire display and move the cursor to (0,0).
//--
PUBLIC void ClearDisplay(void)
{
#ifdef LCD
  WaitBusy();  DisplayWrite(CONTROL_REGISTER, LCD_CLEAR_DISPLAY);
  WaitBusy();  DisplayWrite(CONTROL_REGISTER, LCD_CURSOR_HOME);  
#endif
#ifdef VFD
  WaitBusy();  DisplayWrite(VFD_CURSOR_HOME);
  WaitBusy();  DisplayWrite(VFD_CLEAR_DISPLAY);
  WaitBusy();
#endif
  //DBGOUT(("Clear display\n"));
}


//++
//   Move the display's cursor (which isn't necessarily visible!) to the 
// selected row and column, the upper left being (0,0).  The behaviour is
// undefined (although generally it's a NOP) if bRow > DISPLAY_HEIGHT-1 or
// bCol > DISPLAY_WIDTH-1.
//--
PUBLIC void DisplayAt(BYTE bRow, BYTE bCol)
{
  BYTE bPos;
  if ((bRow >= DISPLAY_HEIGHT) || (bCol >= DISPLAY_WIDTH)) {
    DBGOUT(("???Bad cursor position bRow=%bd, bCol=%bd\n", bRow, bCol));
    return;
  }
#ifdef LCD
  //   Cursor addressing on the LCD is really ugly!  For 2x40 displays, the
  // cursor position ranges from 0x00..0x27 (39 decimal) for the first line
  // and 0x40..0x67 for the second line.  Four 4x20 displays, however, the
  // first line is 0x00..0x13, the second line is 0x40..0x53, the third line
  // is 0x14..0x27 (i.e. it's the second half of the first line!) and the
  // fourth line is 0x54..0x67.  Uggh!
#if (DISPLAY_HEIGHT == 2)
  bPos = (bRow == 0 ? 0x00 : 0x40) | bCol;
#elif (DISPLAY_HEIGHT == 4)
  switch (bRow) {
    case 0: bPos = bCol;			break;
    case 1: bPos = 0x40 | bCol;			break;
    case 2: bPos = DISPLAY_WIDTH+bCol;          break;
    case 3: bPos = 0x40 | (DISPLAY_WIDTH+bCol);	break;
  }
#else
  bPos = bCol;
#endif
  WaitBusy();  DisplayWrite(CONTROL_REGISTER, LCD_SET_DDRAM_ADDRESS | bPos);
#endif
#ifdef VFD
  //   For VFD displays it's much easier.  First, all display positions are
  // numbered sequentially (e.g. the first character of the first line is at
  // location 0, the first character of the second line is at DISPLAY_WIDTH,
  // DISPLAY_WIDTH*2 for the third line, etc).
  bPos = (bRow * DISPLAY_WIDTH) + bCol;
  WaitBusy();  DisplayWrite(VFD_ESCAPE);
  WaitBusy();  DisplayWrite(VFD_SET_CURSOR);
  WaitBusy();  DisplayWrite(bPos);
  WaitBusy();
#endif
  //DBGOUT(("Set Display Cursor Row=%bd, Column=%bd (bPos=0x%02bX)\n", bRow, bCol, bPos));
}

#ifdef UNUSED
//++
//   Turn the actual cursor display on (bShow=TRUE) or off (bShow=FALSE).  This
// is strictly a visual effect - text output, including DisplayAt(), is not
// affected.
//--
PUBLIC void DisplayCursor (BOOL bShow)
{
#ifdef LCD
  BYTE bCursor =  LCD_DISPLAY_CONTROL|LCD_DISPLAY_ON;
  if (bShow) bCursor |= LCD_CURSOR_ON|LCD_CURSOR_BLINK;
  WaitBusy();  DisplayWrite(CONTROL_REGISTER, bCursor);
#endif
#ifdef VFD
  WaitBusy();  DisplayWrite (bShow ? VFD_CURSOR_ON : VFD_CURSOR_OFF);
#endif
  //DBGOUT(("Display Cursor, bShow=%bd\n", bShow));
}
#endif

//++
//   Display a single character at the current cursor location and move the
// cursor left one position.  What happens when the cursor exceeds the display
// width is undefined (and in the case of most multi-line LCD displays, at
// least, can be quite creative :-)
//--
PUBLIC void DisplayChar (char bChar)
{
#ifdef LCD
  WaitBusy();  DisplayWrite(DATA_REGISTER, bChar);
#endif
#ifdef VFD
  WaitBusy();  DisplayWrite(bChar);  /*WaitBusy();*/
#endif
  //DBGOUT(("DisplayChar, bChar=%bd ('%c')\n", bChar, bChar));
}

#ifdef UNUSED
//++
//   This function is equivalent to a call to DisplayChar() with an implied
// call to DisplayCursor() first...
//--
PUBLIC void DisplayCharAt (BYTE bRow, BYTE bCol, char bChar)
{
  DisplayAt(bRow, bCol);  DisplayChar(bChar);
}
#endif

//++
//   This routine simply calls DisplayChar() multiple times.  Note that the
// string pointer parameter is deliberately an "un-spaced" declaration, so
// that it can accomodate argument strings in the CODE, DATA, IDATA or XDATA
// memory spaces..
//--
PUBLIC void DisplayString (char *pString)
{
  while (*pString != '\0') DisplayChar(*pString++);
  //DBGOUT(("DisplayString, pString=\"%s\"\n", pString));
}

//++
// Just like DisplayString(), but with a call to DisplayCursor() first...
//--
PUBLIC void DisplayStringAt (BYTE bRow, BYTE bCol, char *pString)
{
  DisplayAt(bRow, bCol);  DisplayString(pString);
}


#ifdef UNUSED
//++
//   This procedure outputs an sprintf() formatted string to the display 
// starting at the current cursor position.  It assumes that the string
// length never exceeds the DISPLAY_WIDTH - bad, bad, bad things will
// happen if you violate this rule!!
//--
PUBLIC void DisplayText (char *pFormat, ...)
{
  va_list arg_ptr;  WORD wCount;
  va_start (arg_ptr, pFormat);
  wCount = vsprintf(m_acDisplayBuffer, pFormat, arg_ptr);
  ASSERT((wCount <= DISPLAY_WIDTH+1), ("DisplayText: \"%s\" too long (%d chars)\n", pFormat, wCount));
  va_end (arg_ptr);
  DisplayString(m_acDisplayBuffer);
  //DBGOUT(("DisplayText, text=\"%s\"\n", m_acDisplayBuffer));
}
#endif

//++
//  The same as DisplayText() with a call to DisplayCursor() first...
//--
PUBLIC void DisplayTextAt (BYTE bRow, BYTE bCol, char *pFormat, ...)
{
  va_list arg_ptr;  WORD wCount;
  va_start (arg_ptr, pFormat);
  wCount = vsprintf(m_acDisplayBuffer, pFormat, arg_ptr);
  ASSERT((wCount <= DISPLAY_WIDTH+1), ("DisplayTextAt: \"%s\" too long (%d chars)\n", pFormat, wCount));
  va_end (arg_ptr);
  DisplayStringAt(bRow, bCol, m_acDisplayBuffer);
  //DBGOUT(("DisplayText, text=\"%s\"\n", m_acDisplayBuffer));
}


#if 0
PUBLIC void DisplayTest (void)
{
  BYTE x=1, y=2;
  ClearDisplay();
  DisplayStringAt(0,0,"ROW 1!!");
  printf("Press a key...");  _getkey();
  DisplayStringAt(1,1,"ROW 2!!");
  printf("Press a key...");  _getkey();
  DisplayStringAt(2,2,"ROW 3!!");
  printf("Press a key...");  _getkey();
  DisplayStringAt(3,3,"ROW 4!!");
  printf("Press a key...");  _getkey();

  ClearDisplay();
  DisplayCharAt(0,18,'X');  DisplayChar('Y');
  DisplayStringAt(1,0,"CURSOR ON!");  DisplayCursor(TRUE);
  printf("Press a key...");  _getkey();
  DisplayStringAt(2,0,"CURSOR OFF!");  DisplayCursor(FALSE);
  printf("Press a key...");  _getkey();

  ClearDisplay();
  DisplayStringAt(0,0,"DisplayText() Test");
  DisplayTextAt(1,4,"x=%bd", x);
  DisplayText(", y=%bd", y);
  DisplayTextAt(2,10,"x+y=%bd", (BYTE) (x+y));
  //BYTE b;
  //DisplayString("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG\n");
  //DisplayString("test");
  //for (b = 1;  b < 32;  ++b)  DisplayWrite(1, 96+b);
}
#endif

⌨️ 快捷键说明

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