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

📄 dc550_display.c

📁 一款经典的数字电话设计资料
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************/
/*  CONFIDENTIAL                                                             */
/*  Sigpro Copyright 2003, All rights reserved                               */
/*****************************************************************************/
/*  CLIENT:  Telematrix                                                      */
/*  PROJECT: DC550 Digital Centrex Phone                                     */
/*  FILE:    dc550_display.c                                                 */
/*****************************************************************************/
/*  This file contains the code for the LCD display driver.  The actual      */
/*  LCD model may change over time; currently, the hardware engineering team */
/*  is planning to use a 2x24 character display from Okaya.                  */
/*****************************************************************************/

#define __DC550_DISPLAY_EXTERN__
#include "dc550_interrupt.h"
#include "dc550_display.h"
#include "dc550_hwinit.h"
// #include "dc550_usartdriver.h"


/******************************************************************************
 *  GLOBAL VARIABLES
 *****************************************************************************/
// Semaphore for LED/LCD lines
BOOL display_usingbus;

// Settings variables
BOOL display_displaymode;
BOOL display_cursormode;
BOOL display_cursorblink;

// State variables
DISPLAY_STATE_E display_current_state;

char display_current_lineone[25];
char display_current_linetwo[25];
DC550LCDCoordinate display_current_updatex;

DC550LCDCoordinate display_current_cursorx;
DC550LCDCoordinate display_current_cursory;

DC550InterruptCounter display_verify_counter;

// Pending changes variables
BOOL display_statuschange_lineone;
BOOL display_statuschange_linetwo;
BOOL display_statuschange_cursor;

char display_new_lineone[25];
char display_new_linetwo[25];

BOOL display_new_cursorblink;
DC550LCDCoordinate display_new_cursorx;
DC550LCDCoordinate display_new_cursory;


/******************************************************************************
 *  FUNCTION: void display_init(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called during the initialization phase to initialize all
 *  of the display driver variables.  The LCD ports are configured as follows:
 *  A. P2 is connected to LCD DB0 through LCD DB7 (for input and output)
 *  B. P3.0 is connected to LCD_RS (for output)
 *  C. P3.1 is connected to LCD_RnW (for output)
 *  D. P3.2 is connected to LCD_E (toggle to clock data in and out)
 *  E. P4.5 is connected to nLED_EN (0=LEDs selected, 1=LCDs selected)
 *
 *  The initialization sequence does a few other jobs:
 *  1. It initializes the display driver variables
 *  2. It follows the initializes the LCD according to the initialization
 *     sequence listed on page 44 of the Hantronix LCD module specification
 *****************************************************************************/
void display_init(void) {
  // Declare temporary variable
  int i;

  // Initialize global settings variables
  display_displaymode = TRUE;  // Turns display on
  display_cursormode = FALSE;  // Turns cursor off
  display_cursorblink = FALSE; // Turns cursor blink off
  
  // Initialize global state variables
  display_current_state = DISPLAY_STATE_IDLE;
  for(i=0; i<25; i++) {
    display_current_lineone[i] = 0;
    display_current_linetwo[i] = 0;
  }
  display_current_updatex = 0;
  display_current_cursorx = 0;
  display_current_cursory = 0;
  display_verify_counter = 0;
  
  // Initialize global pending changes variables
  display_statuschange_lineone = TRUE;
  display_statuschange_linetwo = TRUE;
  for(i=0; i<24; i++) {
    display_new_lineone[i] = ' ';
    display_new_linetwo[i] = ' ';
  }
  display_statuschange_cursor = FALSE;
  display_new_lineone[24] = 0;
  display_new_linetwo[24] = 0;
  display_new_cursorblink = FALSE;
  display_new_cursorx = 0;
  display_new_cursory = 0;

  // Make sure ports are set up correctly
  LCDCTRL_DIR |= (LCD_RS | LCD_RNW | LCD_E);
  LCDCTRL_OUT &= ~(LCD_E); // LCD_E is raised and lowered for each command
  LCDDATA_DIR = 0xFF;
  
  // Enable LCD over LEDs
  display_usingbus = TRUE;
  
  // Function Set (LCD function)
  display_instr_functionset();
  
  // Wait for 1.6ms
  for(i = 0x4000; i > 0; i--) hwinit_reset_watchdog();

  // Function Set (LCD function)
  display_instr_functionset();
  
  // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Function Set (LCD function)
  display_instr_functionset();
  
  // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Display On (LCD function)
  display_instr_displaymode();
  
  // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Display Clear
  display_instr_displayclear();

  // Wait for 1.6 milliseconds
  for(i = 0x4000; i > 0; i--) hwinit_reset_watchdog();

  // Entry Mode Set
  display_instr_entrymode();
  
  // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Program Character 1 into CGRAM
  display_instr_cgramaddress(0x01);    // CGRAM address 1
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_chartop_emptybox();     // Write top of character
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_charbottom_emptybox();  // Write bottom of character

 // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Program Character 2 into CGRAM
  display_instr_cgramaddress(0x02);    // CGRAM address 2
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_chartop_fullbox();      // Write top of character
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_charbottom_fullbox();   // Write bottom of character

 // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Program Character 3 into CGRAM
  display_instr_cgramaddress(0x03);    // CGRAM address 3
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_chartop_uparrow();      // Write top of character
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_charbottom_uparrow();   // Write bottom of character

 // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Program Character 4 into CGRAM
  display_instr_cgramaddress(0x04);    // CGRAM address 4
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_chartop_downarrow();    // Write top of character
  for(i = 48; i > 0; i--);             // Wait for 40 microseconds
  display_util_charbottom_downarrow(); // Write bottom of character

  // Enable LEDs over LCD
  display_usingbus = FALSE;
}


/******************************************************************************
 *  FUNCTION: void display_instr_functionset(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function sends the "Function Set" instruction to the LCD controller.
 *****************************************************************************/
void display_instr_functionset(void) {
  LCDCTRL_OUT &= ~(LCD_RS | LCD_RNW); // Clear RS and RNW bits
  LCDDATA_OUT = 0x20;                 // Function set command bit
  LCDDATA_OUT |= ( (LCD_DISPLAYMODE ? LCD_BIT_DL : 0) | // Display mode bit
                   (LCD_NUMLINES ? LCD_BIT_N : 0) |     // Number of lines bit
                   (LCD_FONT ? LCD_BIT_F : 0) |         // Font bit
                   (LCD_24x4 ? LCD_BIT_POUND : 0) );    // 24x4 bit
  LCDCTRL_OUT |= LCD_E;    // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E); // Clock bit low
}


/******************************************************************************
 *  FUNCTION: void display_instr_displaymode(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function sends the "Display On/Off" instruction to the LCD
 *  controller.
 *****************************************************************************/
void display_instr_displaymode(void) {
  LCDCTRL_OUT &= ~(LCD_RS | LCD_RNW); // Clear RS and RNW bits
  LCDDATA_OUT = 0x08;                 // Display On command bit
  LCDDATA_OUT |= ( (display_displaymode ? LCD_BIT_D : 0) |
                   (display_cursormode ? LCD_BIT_C : 0) |
                   (display_cursorblink ? LCD_BIT_B : 0) );
  LCDCTRL_OUT |= LCD_E;    // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E); // Clock bit low
}


/******************************************************************************
 *  FUNCTION: void display_instr_displayclear(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function sends the "Display Clear" instruction to the LCD
 *  controller.
 *****************************************************************************/
void display_instr_displayclear(void) {
  LCDCTRL_OUT &= ~(LCD_RS | LCD_RNW); // Clear RS and RNW bits
  LCDDATA_OUT = 0x01;                 // Display Clear command bit
  LCDCTRL_OUT |= LCD_E;    // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E); // Clock bit low
}


/******************************************************************************
 *  FUNCTION: void display_instr_entrymode(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function sends the "Entry Mode Set" instruction to the LCD
 *  controller.
 *****************************************************************************/
void display_instr_entrymode(void) {
  LCDCTRL_OUT &= ~(LCD_RS | LCD_RNW); // Clear RS and RNW bits
  LCDDATA_OUT = 0x04;                 // Entry Mode Set command bit
  LCDDATA_OUT |= ( (LCD_CURSORINCREMENT ? LCD_BIT_ID : 0) | // Cursor increment
                   (LCD_DISPLAYSHIFT ? LCD_BIT_S : 0) );    // Display shift 
  LCDCTRL_OUT |= LCD_E;    // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E); // Clock bit low
}


/******************************************************************************
 *  FUNCTION: void display_instr_cgramaddress(unsigned char address)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function sets the address pointer of the LCD controller to the 
 *  CGRAM character located at the "address" parameter location.
 *****************************************************************************/
void display_instr_cgramaddress(unsigned char address) {
  LCDCTRL_OUT &= ~(LCD_RS | LCD_RNW); // Clear RS and RNW bits
  LCDDATA_OUT = 0x40;                 // CGRAM Address command bit
  LCDDATA_OUT |= (address << 3);      // CGRAM Character address
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low
}


/******************************************************************************
 *  FUNCTION: void display_util_chartop_emptybox(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function programs the top of the empty box character into CGRAM.
 *****************************************************************************/
void display_util_chartop_emptybox(void) {
  // Declare local variable
  int i;

  // Write the first line
  LCDCTRL_OUT &= ~(LCD_RNW);          // Clear RNW bit
  LCDCTRL_OUT |= LCD_RS;              // Set RS bit
  LCDDATA_OUT = 0x1F;                 // First line
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low

 // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Write the second line
  LCDCTRL_OUT &= ~(LCD_RNW);          // Clear RNW bit
  LCDCTRL_OUT |= LCD_RS;              // Set RS bit
  LCDDATA_OUT = 0x11;                 // Second line
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low

 // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Write the third line
  LCDCTRL_OUT &= ~(LCD_RNW);          // Clear RNW bit
  LCDCTRL_OUT |= LCD_RS;              // Set RS bit
  LCDDATA_OUT = 0x11;                 // Third line
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low

 // Wait for 40 microseconds
  for(i = 48; i > 0; i--);

  // Write the fourth line
  LCDCTRL_OUT &= ~(LCD_RNW);          // Clear RNW bit
  LCDCTRL_OUT |= LCD_RS;              // Set RS bit
  LCDDATA_OUT = 0x11;                 // Fourth line
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low
}


/******************************************************************************
 *  FUNCTION: void display_util_charbottom_emptybox(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function programs the bottom of the empty box character into CGRAM.
 *****************************************************************************/
void display_util_charbottom_emptybox(void) {
  // Declare local variable
  int i;

  // Write the fifth line
  LCDCTRL_OUT &= ~(LCD_RNW);          // Clear RNW bit
  LCDCTRL_OUT |= LCD_RS;              // Set RS bit
  LCDDATA_OUT = 0x11;                 // Fifth line
  LCDCTRL_OUT |= LCD_E;               // Clock bit high
  _NOP();
  LCDCTRL_OUT &= ~(LCD_E);            // Clock bit low

 // Wait for 40 microseconds

⌨️ 快捷键说明

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