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

📄 lcd-t6963.c

📁 T6963的lpc21xx接口程序,且包括一些画直线,局部清屏等函数
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*  240*128LCD,T6963控制器
*  在lpc2114中调试通过,ads1.2
*  
****************************************************************************/

#define   LCDRD         0x00004000             //O P0.14口 LCD的读请求信号  
#define   LCDWR         0x00008000             //O P0.15口 LCD的写请求信号:低有效  
#define   LCDCE         0x00010000             //O P0.16口 LCD的片选信号:低有效  
#define   LCDCD         0x00020000             //O P0.17口 LCD的数据/命令:1=命令,0=数据   
//P0.18~P0.25为LCD的8位数据接口                //O

#define  LCD_GRAPHICS_ADDR  0x0000      // LCD图形显示区的地址
#define  LCD_XMAX 30;  //LCD的一行最多显示的字符数(8*16字符)
#define  LCD_YMAX 8;   //LCD最多显示的字符行数(8*16字符)
// 显示变量
uint8 flag_no=0;   //显示主菜单时决定是在哪个项目并在哪一行反显,有效值为0-5 0=打开文件1=新件文件其余对照菜单栏
uint8 cursor=0;      //开关光标: 0=关光标;1=下划线光标;0x5a=字串闪烁光标


/****************************************************************************
* 名称:Delay_n()
* 功能:延时 = 20ns * 3 * N * 16
* 入口参数:delayn - 延时长度
* 出口参数:
* delay_n(1) = 约为0.108083us
****************************************************************************/
void Delay_n(uint32 delayn)
{ 
  for(; delayn > 0; delayn--);

}

/****************************************************************************
* 名称:Read_Statuse_T6963(void)
* 功能:读T6963的状态值
* 入口参数:
*           
* 出口参数:状态值   
* LCD的操作时序:CD置位到CS变高之间的时间>100ns,且在CS变高后要保持10ns
*               WR为上升沿有效,并保持40ns;
*               RD在变低150ns后,数据有效;
*        注:1个指令周期为18ns,1个I/O周期为36ns.
****************************************************************************/
uint8 Read_Statuse_T6963(void)
{ 
   uint32 xa,xi;
  
  
  IO0SET = LCDWR | LCDCD;   //LCDWR和LCDCD置1
    Delay_n(10);
  IO0CLR = LCDCE | LCDRD;   //LCDWR和LCDCD置0
  
    Delay_n(30);
    
    xa = IO0PIN;      //数据线为P0.18~P0.25
    xa = xa >> 18;
    xa = xa & 0xff;   
    
  IO0SET = LCDWR | LCDCE | LCDRD;  

    
  return(xa);
}
/****************************************************************************
* 名称:check_status_t6963(void)
* 功能:检测T6963状态位的指令读写状态位(BIT0)和数据读写状态位(BIT1),如果忙,则继续检测状态位.
*                            自动写状态位(bit3)
* 入口参数:
*           
****************************************************************************/
void check_status_t6963(void)
{ uint8 xa;
  uint32 xi;
  for(xi = 0; xi < 200; xi++)   
   {
     xa = Read_Statuse_T6963();
     if((xa & 0x03) == 0x03) break;
   
   }
}
/****************************************************************************
* 名称:Write_Byte_T6963(uint8 xd, uint8 cd)
* 功能:写1个字节的数据或命令到LCD
* 入口参数:xd -- 8位数据或命令
*           cd -- 1=命令,0=数据
* 出口参数:
* LCD的操作时序:CD置位到CS变高之间的时间>100ns,且在CS变高后要保持10ns
*               WR为上升沿有效,并保持40ns;
*               RD在变低150ns后,数据有效;
*        注:1个指令周期为18ns,1个I/O周期为36ns.
****************************************************************************/
void Write_Byte_T6963(uint8 xd, uint8 cd)
{ 
   uint32 xa;
  check_status_t6963();
  if(cd == 0x00)  IO0CLR = LCDCD;
     else         IO0SET = LCDCD;
    Delay_n(30);
  IO0CLR = LCDWR | LCDCE;
    Delay_n(30);
    
    xa = 0x03fc0000;   //数据线为P0.18~P0.25,先全部清0,再根据数据的值把其它位置1.
    IO0CLR = xa;
    Delay_n(30);
    xa = xd;
    xa = xa << 18;
    IO0SET = xa ;
    Delay_n(30);
    
  IO0SET = LCDWR | LCDCE | LCDRD;  
    Delay_n(30);
}
/****************************************************************************
* 名称:write_command_lcd(uint8 xd,uint8 xlen,uint8 *xp)
* 功能:向LCD发送一组命令
* 入口参数:xd -- 命令字节
*           xlen -- 与命令相关的参数的长度: 0=无参数,1=1参数,2=2参数
*           *xp  -- 参数存放的数组,最小为2字节
* 出口参数:无 
* 操作: 
*        LCD的命令及参数组成的格式为:参数0 + 参数1 + 命令.
*
****************************************************************************/
void write_command_lcd(uint8 xd,uint8 xlen,uint8 *xp)
{ uint8 xi;
  if(xlen > 2) xlen = 2;
  for(xi = 0; xi < xlen; xi++)
   {  Write_Byte_T6963(xp[xi],0);
   }
   Write_Byte_T6963(xd,1);
}

/****************************************************************************
* 名称:lcd_initi(void)
* 功能:初始化lcd
* 入口参数:
*           
* 出口参数:
*
* 其它: 在T6963 for 240*128的LCD中,此处硬件把一个字符的点阵数设置为8,则
*       一屏图形区点用的字节数为: (240/8) * 128 = 0x0F00.
****************************************************************************/
void lcd_initi(void) //  ;初始化lcd
{ uint16 xt;

  lcd_parameter[0] = 0x00; //文本区首址0000H
  lcd_parameter[1] = 0x00; 
  write_command_lcd(0x40,2,lcd_parameter);

  lcd_parameter[0] = 40; //;文本字节数/行
  lcd_parameter[1] = 0x00; 
  write_command_lcd(0x41,2,lcd_parameter);

  lcd_parameter[0] = 0x00; //图形区首址
  lcd_parameter[1] = 0x00;  
  write_command_lcd(0x42,2,lcd_parameter);

  lcd_parameter[0] = 40; //图形字节数/行
  lcd_parameter[1] = 0x00; 
  write_command_lcd(0x43,2,lcd_parameter);

  lcd_parameter[0] = 0x00; //光标位置x
  lcd_parameter[1] = 0x00; //y
  write_command_lcd(0x21,2,lcd_parameter);

  write_command_lcd(0xa1,0,lcd_parameter); //光标为8列*7行

  write_command_lcd(0x88,0,lcd_parameter); //显示方式:CGROM ,"或"合成

  write_command_lcd(0x98,0,lcd_parameter); //显示开关: 光标闪,光标,文本,图形-全开
                  
  lcd_parameter[0] = 0x00;  //地址低位
  lcd_parameter[1] = LCD_GRAPHICS_ADDR >> 8; //0x00;  //地址高位
  write_command_lcd(0x24,2,lcd_parameter);  //指定显示的地址

  for(xt = 0; xt < 0x8000; xt++)   //清空32K显示RAM
    { lcd_parameter[0] = 0x00;
      write_command_lcd(0xc0,1,lcd_parameter); 
    }  
}

/****************************************************************************
* 名称:disp_one(uint8 x,uint8 y,uint16 asc_addr,uint8 flag)
* 功能:显示一个8x16的点阵字符.
* 入口参数:x -- LCD屏的X方向显示位置,以字节为单位(0~29)
*           y -- LCD屏的Y方向显示位置,以字符行为单位(0~7行),
*          adc_addr  -- 显示字符的编码.汉字则是汉字变码的左半部或右半边的编码
           所以显示汉字时需要两次调用此函数。
*          flag=1反显,flag=0不反显
* 出口参数:无 
* 其它:
*      
*       函数中使用到的charBuffer[]数组,为ASCII码字符集的8*16显示点阵.
*          
****************************************************************************/
void disp_one(uint8 x,uint8 y,uint16 asc_addr,uint8 flag)
{ uint16 xasc,xadd;//xadd1;
  uint8 xi;
  
   
  xadd = (y * 16);
  xadd = xadd * LCD_XMAX ; 
  xadd = xadd + x + LCD_GRAPHICS_ADDR;
    
  xasc = asc_addr;
  xasc = xasc * 16;
  for(xi = 0; xi < 16; xi++)
    {  //lcd_addr
      lcd_parameter[0] =  xadd;       //地址低位
      lcd_parameter[1] =  xadd >> 8;  //地址高位
      write_command_lcd(0x24,2,lcd_parameter);
       //char_addr
     lcd_parameter[0] = charBuffer[xasc +xi]; //dispbuff[xasc + xi]; 
     if(flag) lcd_parameter[0]=~lcd_parameter[0];
     write_command_lcd(0xc0,1,lcd_parameter);
	  xadd += LCD_XMAX ; 
    }  

}
  /****************************************************************************
* 名称:part_lcd_clear(uint8 x0, uint8 y0, uint8 x1, uint8 y1)
* 功能:清除显示屏的一部分区域
* 入口参数:x0,y0 - 起点坐标, x0以字节为单位,y0以点为单位
*           x1,y1 - 终点坐标, x1以字节为单位,y1以点为单位
* 出口参数:
*
* 其它: 
****************************************************************************/
void part_lcd_clear(uint8 x0, uint8 y0, uint8 x1, uint8 y1)
{
  uint32 addr; 
  uint8 i,j; 
  
  addr = x0 + y0 * LCD_XMAX ; 
  for(i=0;i < y1 - y0; i++){            

⌨️ 快捷键说明

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