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

📄 dc550_display.c

📁 一款经典的数字电话设计资料
💻 C
📖 第 1 页 / 共 5 页
字号:
  LCDDATA_DIR = 0xFF;                 // Set data port for output again
  
  // Set Display Mode
  display_instr_displaymode();

  // Enable LEDs over LCD
  display_usingbus = FALSE;
}


/******************************************************************************
 *  FUNCTION: void display_util_setcoordinates(DC550LCDCoordinate y,
 *                                              DC550LCDCoordinate x)
 ******************************************************************************
 *  DESCRIPTION:
 *  display_util_setcoordinates(.) is an internal utility function used to set
 *  the coordinates of the cursor.  It takes two parameters:
 *  +  x goes from 0 to 23 and indicates how far across the cursor should go
 *  +  y goes from 0 to 1 and indicates the line the cursor should go on
 *****************************************************************************/
void display_util_setcoordinates(DC550LCDCoordinate y, DC550LCDCoordinate x) {
  // Declare local variables
  int i;
  DC550LCDCoordinate address;
  
  // Calculate LCD Coordinate address
  if(x < 12)
    address = (x + (y * 20));
  else
    address = (60 + x + (y * 20));
  
  // Enable LCD over LEDs
  display_usingbus = TRUE;

  // Check if LCD is ready
  LCDCTRL_OUT &= ~(LCD_RS);           // Clear RS bit
  LCDCTRL_OUT |= LCD_RNW;             // Set R/W bit
  LCDDATA_DIR = 0x00;                 // Temporarily set data port for input
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();

  // If LCD is not ready, wait for 12 microseconds at a time
  while(LCDDATA_IN & 0x80) {
    LCDCTRL_OUT &= ~(LCD_E);          // Clock bit low
    for(i = 12; i > 0; i--);
    LCDCTRL_OUT |= LCD_E;
  }
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low again
  LCDDATA_DIR = 0xFF;                 // Set data port for output again
  
  // Set DDRAM Address
  LCDCTRL_OUT &= ~(LCD_RS | LCD_RNW); // Clear RS and RNW bits
  LCDDATA_OUT = 0x80;                 // DDRAM Address command bit
  LCDDATA_OUT |= address;      // DDRAM Address address bits
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low

  // Enable LEDs over LCD
  display_usingbus = FALSE;
}


/******************************************************************************
 *  FUNCTION: void display_util_writedata(char output)
 ******************************************************************************
 *  DESCRIPTION:
 *  display_util_writedata(.) is an internal utility function that writes a
 *  single character at the current cursor location.
 *****************************************************************************/
void display_util_writedata(char output) {
  // Declare local variables
  int i;
  
  // Enable LCD over LEDs
  display_usingbus = TRUE;

  // Check if LCD is ready
  LCDCTRL_OUT &= ~(LCD_RS);           // Clear RS bit
  LCDCTRL_OUT |= LCD_RNW;             // Set R/W bit
  LCDDATA_DIR = 0x00;                 // Temporarily set data port for input
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();

  // If LCD is not ready, wait for 12 microseconds at a time
  while(LCDDATA_IN & 0x80) {
    LCDCTRL_OUT &= ~(LCD_E);          // Clock bit low
    for(i = 12; i > 0; i--);
    LCDCTRL_OUT |= LCD_E;
  }
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low again
  LCDDATA_DIR = 0xFF;                 // Set data port for output again

  // Write byte out to DDRAM
  LCDCTRL_OUT &= ~(LCD_RNW);          // Clear RNW bit
  LCDCTRL_OUT |= LCD_RS;              // Set RS bit
  LCDDATA_OUT = output;               // DDRAM output bit
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low

  // Enable LEDs over LCD
  display_usingbus = FALSE;
}


/******************************************************************************
 *  FUNCTION: char display_util_readdata(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  display_util_readdata(.) is an internal utility function that reads a
 *  single character from the current cursor location.  It is primarily
 *  used to ensure that a static discharge has not set the LCD in an unusual
 *  state.
 *****************************************************************************/
char display_util_readdata(void) {
  // Declare local variables
  int i;
  char lcdchar;
  
  // Enable LCD over LEDs
  display_usingbus = TRUE;

  // Check if LCD is ready
  LCDCTRL_OUT &= ~(LCD_RS);           // Clear RS bit
  LCDCTRL_OUT |= LCD_RNW;             // Set R/W bit
  LCDDATA_DIR = 0x00;                 // Temporarily set data port for input
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  
  // If LCD is not ready, wait for 12 microseconds at a time
  while(LCDDATA_IN & 0x80) {
    LCDCTRL_OUT &= ~(LCD_E);          // Clock bit low
    for(i = 12; i > 0; i--);
    LCDCTRL_OUT |= LCD_E;
  }
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low again

  // Read from DRAM Address
  LCDCTRL_OUT |= (LCD_RNW | LCD_RS);  // Set RNW and RS bits
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  lcdchar = LCDDATA_IN;               // Set LCDDATA_IN as return value
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low
  LCDDATA_DIR = 0xFF;                 // Set data port for output again
  
  // Enable LEDs over LCD
  display_usingbus = FALSE;

  return lcdchar;
}


/******************************************************************************
 *  FUNCTION: char display_util_translatechar(char ascii)
 ******************************************************************************
 *  DESCRIPTION:
 *  display_util_translatechar(.) translates a character from ascii to the
 *  font table on the LCD module provided by Galaxy.  Specifically, it
 *  translates all ASCII characters from 0x20 to 0x7E, plus any other extended
 *  characters that are used in the code.
 *****************************************************************************/
char display_util_translatechar(char ascii) {
  switch(ascii) {
    case 0x24:
      return 0xA2;
    case 0x40:
      return 0xA0;
    case 0x5B:
      return 0xFA;
    case 0x5C:
      return 0xFB;
    case 0x5D:
      return 0xFC;
    case 0x5E:
      return 0x1D;
    case 0x5F:
      return 0xC4;
    case 0x7B:
      return 0xFD;
    case 0x7C:
      return 0xFE;
    case 0x7D:
      return 0xFF;
    case 0x7E:
      return 0xCE;
    case 0x7F:
      return 0x20;

    case 0xBF:
      return 0x60;
    case 0xC0:
      return 'A';
    case 0xC1:
      return 0xE2;
    case 0xC2:
      return 'A';
    case 0xC3:
      return 'A';
    case 0xC4:
      return 0x5B;
    case 0xC5:
      return 0xAE;
    case 0xC6:
      return 'E';
    case 0xC7:
      return 0xA9;
    case 0xC8:
      return 0xC5;
    case 0xC9:
      return 0xBF;
    case 0xCA:
      return 0xC6;
    case 0xCB:
      return 'E';
    case 0xCC:
      return 'I';
    case 0xCD:
      return 0xE3;
    case 0xCE:
      return 'I';
    case 0xCF:
      return 'I';
    case 0xD0:
      return 'D';
    case 0xD1:
      return 0x5D;
    case 0xD2:
      return 'O';
    case 0xD3:
      return 0xE4;
    case 0xD4:
      return 0xEC;
    case 0xD5:
      return 'O';
    case 0xD6:
      return 'O';
    case 0xD7:
      return 'x';
    case 0xD8:
      return 'O';
    case 0xD9:
      return 'U';
    case 0xDA:
      return 0xE5;
    case 0xDB:
      return 'U';
    case 0xDC:
      return 0x5E;
    case 0xDD:
      return 0xE6;
    case 0xDE:
      return 'b';
    case 0xDF:
      return 0xBE;
    case 0xE0:
      return 0x7F;
    case 0xE1:
      return 0xE7;
    case 0xE2:
      return 'a';
    case 0xE3:
      return 'a';
    case 0xE4:
      return 0x7B;
    case 0xE5:
      return 0xAF;
    case 0xE6:
      return 0xBD;
    case 0xE7:
      return 0xC8;
    case 0xE8:
      return 0xA4;
    case 0xE9:
      return 0xA5;
    case 0xEA:
      return 0xC7;
    case 0xEB:
      return 'e';
    case 0xEC:
      return 0xA7;
    case 0xED:
      return 0xE8;
    case 0xEE:
      return 'i';
    case 0xEF:
      return 'i';
    case 0xF0:
      return 'o';
    case 0xF1:
      return 0x7D;
    case 0xF2:
      return 0xA8;
    case 0xF3:
      return 0xE9;
    case 0xF4:
      return 0xED;
    case 0xF5:
      return 'o';
    case 0xF6:
      return 0x7C;
    case 0xF7:
      return '/';
    case 0xF8:
      return 0xAC;
    case 0xF9:
      return 0xA6;
    case 0xFA:
      return 0xE5;
    case 0xFB:
      return 'u';
    case 0xFC:
      return 0x7E;
    case 0xFD:
      return 0xEB;
    case 0xFE:
      return 'b';
    case 0xFF:
      return 'y';

    default:
      return ascii;
  }
}

/******************************************************************************
 *  FUNCTION: void display_util_tempdisablecursor(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  display_util_tempdisablecursor(void) temporarily disables the cursor
 *  while the display driver writes characters to the display or reads
 *  characters from the display to check for static discharge.
 *****************************************************************************/
void display_util_tempdisablecursor(void) {
  // If we were about to change the cursor status anyway, just disable cursor
  if(display_statuschange_cursor) {
    display_util_setcursormode(FALSE, FALSE);
    // If the cursor was about to be disabled anyway, mark that as done
    if( !display_new_cursorblink )
      display_statuschange_cursor = FALSE;
  }
  
  // Otherwise, disable the cursor and insert a command to restore it later
  else {
    display_util_setcursormode(FALSE, FALSE);
    display_statuschange_cursor = TRUE;
    display_new_cursorblink = TRUE;
    display_new_cursorx = display_current_cursorx;
    display_new_cursory = display_current_cursory;
  }
}

⌨️ 快捷键说明

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