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

📄 yjxs.c

📁 该程序详细介绍了实时时钟芯片DS1302的使用编程代码
💻 C
字号:
/*******************************************************
液晶屏显示模块
********************************************************/

#include<config.h>
#define RS1602    P1_0       //数据/命令选择
#define RW1602    P1_1       //读/写选择
#define EL1602    P1_2       //使能信号

#define DataPort P0          // 数据端口
#define Busy    0x80


/*=======================================================
正常读写操作之前必须检测LCD控制器状态:    CS=1 RS1602=0 RW1602=1
DB7:    0  LCD控制器空闲; 1  LCD控制器忙
========================================================*/
void WaitForEnable( void ) {

    DataPort = 0xff;

    RS1602=0; RW1602=1; _nop_();    EL1602=1; _nop_(); _nop_();

    while( DataPort & Busy );
    EL1602=0;
}


/*=======================================================
写控制字符子程序: E=1 RS1602=0 RW1602=0
=======================================================*/
void LcdWriteCommand( Uchar CMD,Uchar AttribC )  {    //送控制字符子程序

    if (AttribC) WaitForEnable();                     // 检测忙信号?
    RS1602=0; RW1602=0; _nop_();
    DataPort=CMD; _nop_();                       
    EL1602=1;_nop_();_nop_();EL1602=0;                // 操作允许脉冲信号
}


/*=======================================================
当前位置写字符子程序: E =1 RS1602=1 RW1602=0
=======================================================*/
void LcdWriteData( char dataW )  {

    WaitForEnable();                             // 检测忙信号

    RS1602=1; RW1602=0; _nop_();

    DataPort=dataW; _nop_();

    EL1602=1; _nop_(); _nop_(); EL1602=0;        // 操作允许脉冲信号

}


/*=======================================================
初始化程序, 必须按照产品资料介绍的初始化过程进行
=======================================================*/
void Lcdreset( void )  {

       LcdWriteCommand( 0x38, 0);            // 显示模式设置(不检测忙信号)
        Delayms(10);
    LcdWriteCommand( 0x38, 0);            // 共三次
        Delayms(10);
    LcdWriteCommand( 0x38, 0);
        Delayms(10);

    LcdWriteCommand( 0x38, 1);            // 显示模式设置(以后均检测忙信号)
    LcdWriteCommand( 0x08, 1);            // 显示关闭
    LcdWriteCommand( 0x01, 1);            // 显示清屏
    LcdWriteCommand( 0x06, 1);            // 显示光标移动设置
    LcdWriteCommand( 0x0c, 1);            // 显示开及光标设置
}


/*=======================================================
显示光标定位(X表示行 ,Y表示列)
=======================================================*/
void Disp_XY( char posx,char posy) {

Uchar temp;

    temp = posy & 0x0f;
    posx &= 0x1;   
    if ( posy>15 )   temp |= 0x40;
	if (posx==1)   temp |=0x40;
    temp |= 0x80;
    LcdWriteCommand(temp,0);
}

/*=======================================================
按指定位置显示数出一个字符
=======================================================*/
void Disponechar(Uchar x,Uchar y,Uchar Wdata)  {

    Disp_XY( x, y );                // 定位显示地址
    LcdWriteData( Wdata );            // 写字符
}

/*=======================================================
液晶屏上显示字符串
=======================================================*/
void Eputstr(Uchar x,Uchar y, Uchar code *ptr) {
Uchar i,l=0;
    while (*ptr++ >0){l++;};        //统计字符的个数(字符串数组的最后一位是‘\0')
	ptr=ptr-(l+1);                   //使指针重新指向首个字符
    for (i=0;i<l;i++)     { Disponechar(x,y++,*ptr++);
                            if ( y == 31 )  { y = 0; x ^= 0; }
                           }
                                                }










⌨️ 快捷键说明

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