tc1602a.c

来自「STC51系列的源码」· C语言 代码 · 共 134 行

C
134 行
字号
/********************************************************************************/
/* filename : TC1602A.c                                                         */
/* created  : xillinx                                                           */
/* descript : 处理字符型LCD显示                                                 */
/********************************************************************************/
#include "../CPU/CPU.h"
#include "../CFG/CFG.h"
#include "../UART/UART.h"
#include "../TC1602A/TC1602A.h"

/********************************************************************************/
/* funname : LCDT_delay_5ms()                                                   */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: 延时等待,1US需要3.7个NOP, 1000000US需要 3700000                    */
/********************************************************************************/
void LCDT_delay_5ms(void)
{   unsigned int time=0xE000;
    while(time--);
}

/********************************************************************************/
/* funname : LCDT_set_display()                                                 */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: 设置显示模式                                                       */
/********************************************************************************/
void LCDT_set_display(unsigned char mode)
{	LCDT_wr_cmd = 0x08|mode;	
}

/********************************************************************************/
/* funname : LCDT_wait_busy()                                                   */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: 等待释放BUSY信号                                                   */
/********************************************************************************/
void LCDT_wait_busy(void)
{	while((LCDT_rd_cmd&0x80)==0x80);  //* 等待BUSY释放
}

/********************************************************************************/
/* funname : LCDT_print_char()                                                  */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: 按指定位置显示一个字符,x表示列,y表示行                             */
/********************************************************************************/
void LCDT_print_char(unsigned char x, unsigned char y, unsigned char mdata)  
{   y &= 0x1;           //* y不能大于0x1
    x &= 0xF;           //* x不能大于0xF
    if(y==0x1)               
    {  x|=0x40;         //* 当要显示第二行时地址码+0x40;
    }                   
    x |= 0x80;          //* 算出指令码,写显示RAM/DDRAM的地址
    LCDT_wr_cmd =x;     //* 写入显示数据要写的地址单元
    LCDT_wait_busy();
    LCDT_wr_data=mdata; //* 写入显示数据
}

/********************************************************************************/
/* funname : LCDT_print_string()                                                */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: 按指定位置显示一串字符,x表示列,y表示行                             */
/********************************************************************************/
void LCDT_print_string(unsigned char x, unsigned char y, unsigned char * mdata)  
{   unsigned char list=0x0;
    y &= 0x1;   //* y不能大于0x1
    x &= 0xF;   //* x不能大于0xF
    while(x<0x10)
    {   if(mdata[list]==0x0)
        {  break;
        }
        LCDT_print_char(x, y, mdata[list]); //* 显示单个字符
        list++;
        x++;
    }
}

/********************************************************************************/
/* fun_name : LCDT_LED_open()                                                   */
/* version  : v1.00                                                             */
/* created  : xillinx                                                           */
/* descript : LCDP的背光打开                                                    */
/********************************************************************************/
void LCDT_LED_open(void)
{   c51_U07_latch|=0x40;               //* LCD背光打开
    c51_hc138_cs_keyw[0x0]=c51_U07_latch;
}

/********************************************************************************/
/* fun_name : LCDT_LED_clear()                                                  */
/* version  : v1.00                                                             */
/* created  : xillinx                                                           */
/* descript : LCDP的背光打开                                                    */
/********************************************************************************/
void LCDT_LED_clear(void)
{   LCDT_wr_cmd = 0x01; //* 清显示屏
	LCDT_wait_busy();   //* 等待BUSY释放
}
/********************************************************************************/
/* funname : LCDT_initialize()                                                  */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: 字符型显示LCD                                                      */
/********************************************************************************/
void LCDT_initialize()
{	LCDT_wr_cmd = 0x38; 
	LCDT_delay_5ms();
	LCDT_wr_cmd = 0x38;
	LCDT_delay_5ms();
	LCDT_wr_cmd = 0x38;
	
	LCDT_wr_cmd = 0x38; ///* 8位数据端口,2行显示,5x7点阵
	LCDT_wait_busy();   //* 等待BUSY释放
	
	LCDT_wr_cmd = 0x08; //* 关闭显示
	LCDT_wait_busy();   //* 等待BUSY释放
	
	LCDT_wr_cmd = 0x02; //* 归位
	LCDT_wait_busy();   //* 等待BUSY释放
	
	LCDT_wr_cmd = 0x01; //* 清显示屏
	LCDT_wait_busy();   //* 等待BUSY释放
	
	LCDT_wr_cmd = 0x06; //* 输入方式设置为指针加1计数,允许画面滚动
	LCDT_wait_busy();   //* 等待BUSY释放
	
	LCDT_wr_cmd = 0x08|LCDT_ENB_DISPLAY;    //* 打开显示,其他不设置
	LCDT_wait_busy();   //* 等待BUSY释放
	
	LCDT_LED_open();
}

⌨️ 快捷键说明

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