📄 1602.c
字号:
#include <reg51.h>
#include <intrins.h>
#include <ds1302.h>
#define LCD_BUS P0
sbit LCD_RS=P2^2;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^0;
sbit P1_4=P1^4;
//延时
void delay_ms(unsigned int x)
{unsigned char n;
while (x--)
{ for(n=0;n<125;n++);
}
}
//读命令(状态)
unsigned char LCD_RC(void)
{LCD_BUS=0xff;
LCD_RS=0;
LCD_RW=1;
_nop_();
LCD_E=1;
_nop_();
_nop_();
while(LCD_BUS&0x80);
LCD_E=0;
return(LCD_BUS);
}
//写命令
void LCD_WC(unsigned char commond, bit BUSY)
{if(BUSY) LCD_RC();
LCD_RS=0;
LCD_RW=0;
_nop_();
LCD_BUS=commond;
_nop_();
LCD_E=1;
_nop_();
LCD_E=0;
}
//写数据
void LCD_WD(unsigned char Ddata)
{
LCD_RC();
LCD_RS=1;
LCD_RW=0;
_nop_();
LCD_BUS=Ddata;
_nop_();
LCD_E=1;
_nop_();
LCD_E=0;
}
//LCD初始化
void LCD_INT()
{LCD_WC(0x38,0);//设置显示模式,三次,不测试忙信号
delay_ms(4);
LCD_WC(0x38,0);
delay_ms(4);
LCD_WC(0x38,0);
delay_ms(4);
////////////////
LCD_WC(0x38,1);//设置显示模式,测试忙信号
LCD_WC(0x08,1);//关闭显示
LCD_WC(0x01,1);//显示清屏
LCD_WC(0x06,1);
LCD_WC(0x0c,1);
}
//按指定位置显示一个字符
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
{
if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
X |= 0x80; // 算出指令码,要+0x80
LCD_WC(X, 0); //这里不检测忙信号,发送地址码
LCD_WD(DData);
}
//显示一串字符
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char *P)
{
unsigned char *buff;
buff=P;
while(*buff!='\0')//若到达字串尾则退出
{ if(X>15){X=0,Y=1;}
DisplayOneChar(X,Y,*buff); //显示单个字符
X++; buff++;
}
}
void show_time()
{v_Get1302(0x8d);//年.月.日....秒
DisplayListChar(14,0,time);
v_Get1302(0x89);
DisplayListChar(0,1,time);
v_Get1302(0x87);
DisplayListChar(3,1,time);
v_Get1302(0x85);
DisplayListChar(6,1,time);
v_Get1302(0x83);
DisplayListChar(9,1,time);
v_Get1302(0x81);
DisplayListChar(12,1,time);
}
void main(void)
{
LCD_INT();
initialize_DS1302();
DisplayListChar(0,0,"now time is:2006");
DisplayListChar(0,1," - - : : ");
while(1)
{show_time();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -