📄 s1620字符型液晶模块驱动程序.txt
字号:
RS=1;
RW=0;
DPORT=c; //写入待写字符
E=1;
_nop_();
E=0;
}
/*带忙检测的写字符子程序
*/
void LcdWd(unsigned c)
{
WaitIdle();
LcdWdn(c);
}
/*检测忙信号的送控制字子程序*/
void LcdWcn(unsigned c)
{
RS=0;
RW=0;
DPORT=c;
E=1;
_nop_();
E=0;
}
/*检测忙信号的送控制字子程序*/
void LcdWc(unsigned c)
{
WaitIdle();
LcdWcn(c);
}
void LcdPos()
{
unsigned tmp;
Xpos&=0x0f; //16xx 型液晶的范围是0~15
Ypos&=0x01; //Y 的范围是0~1
tmp=Xpos;
if(Ypos==1)
{
tmp+=0x40;
}
tmp|=0x80;
LcdWc(tmp);
}
/*LCD 的复位程序*/
void RstLcd()
{
mDelay(15); //延时15ms
LcdWcn(0x38);
mDelay(5);
LcdWcn(0x38);
mDelay(5);
LcdWcn(0x38);
LcdWc(0x38);//显示模式设置
LcdWc(0x08);//显示关闭
LcdWc(0x01);//显示清屏
LcdWc(0x06);//显示光标移动设置
LcdWc(0x0c);//显示开关及光标设置
} //ts1620-1*/
/*void RstLcd() //JRM 162-a
{
mDelay(30); //延时15ms
/*LcdWcn(0x3C);
mDelay(1);
LcdWcn(0x0D);
mDelay(1);
LcdWcn(0x01);
mDelay(2);
LcdWcn(0x04);*/
/*LcdWc(0x38);//显示模式设置
//mDelay(1);
LcdWc(0x0e);//显示关闭
//mDelay(1);
LcdWc(0x01);//显示清屏
//mDelay(2);
LcdWc(0x04);//显示光标移动设置
//LcdWc(0x0c);//显示开关及光标设置
}*/
/*void WriteString(char s[]) //写字符串函数
{
unsigned pS=0;
for(;;)
{
WriteChar(s[pS]);
pS++;
if(s[pS]==0)
break;
if(++Xpos>=15) //每行最多显示16 个字符
break;
}
}*/
//测试用
sbit P10=P1^0;
sbit P11=P1^1;
sbit P12=P1^2;
sbit P13=P1^3;
sbit P14=P1^4;
sbit P15=P1^5;
sbit P16=P1^6;
sbit P17=P1^7;
/*计时部分*/
unsigned char TimerReg;
unsigned char Second;//秒
unsigned char Minute;//分
unsigned char Hour; //小时
unsigned int dischar[]={'0','1','2','3','4','5','6','7','8','9'};
void Disp (unsigned char tim,unsigned char Xpos1)
{
unsigned int ten=0;
unsigned int gw=0;
if (tim<10)
{
Xpos=Xpos1;
WriteChar('0');//在指定行列显示
//Xpos=Xpos1+1;
//WriteChar(dischar[tim]);
LcdWd(dischar[tim]);//带忙检测的写字符子程序
}
else
{
ten=tim/10; //取十位数
gw=tim-ten*10;//取个位数
Xpos=Xpos1;
WriteChar(dischar[ten]);//在指定行列显示
//Xpos=Xpos1+1;
//WriteChar(dischar[gw]);
LcdWd(dischar[gw]);//带忙检测的写字符子程序
}
}
/*void posclear(unsigned char Xpos1)
{
Xpos=Xpos1;
WriteChar(' ');//在指定行列显示
LcdWd(' ');//带忙检测的写字符子程序
}
*/
unsigned char sele;
/*void int1 (void) interrupt 2 //中断入口2(INT1)
{
P10=~P10;
mDelay(20);//延时处理,防止误按
P11=~P11;
if(int_Key == 0)//进入设置界面
{
sele++;
if (sele==3)sele=0;
P12=~P12;
do
{}
while(int_Key == 0);
}
}*/
void Timer() interrupt 1 //定时器0 中断子程序
{
//TH0=0x4c;TL0=0x09;//49.99ms 纠正误差! 误差:8小时慢 18秒!=0.625ms/s
TH0=0x4c;TL0=0x26;//0.625/20=0.03125 49.99-0.03125=49.95875
//误差:9小时 误差小于1S (慢)
//TH0=0x4c;TL0=0x00;//定时器初值:50ms定时
TimerReg++;
//-------测试用
//P17=~P17;
//-------
if (TimerReg==20)//1秒钟
{
TimerReg=0;//复位
Second++;
if (Second==60) //1分钟
{
Second=0;
Minute++;
if (Minute==60) //1小时
{
Minute=0;
Hour++;
if (Hour==24)//1天
{
Hour=0;
}
}
}}
/*秒显示刷新*/
Disp(Second,8);
/*分显示刷新*/
Disp(Minute,5);
/*小时显示刷新*/
Disp(Hour,2);
//--------测试用
//P10=~P10;
//P11=~P11;
//--------
//}
}
void Setkey (unsigned char len ,unsigned char t)// ,unsigned char addr
{
unsigned char tem;
do
{
switch (t)
{
case 1:{tem=Hour;}break;
case 2:{tem=Minute;}break;
case 3:{tem=Second;}break;
}
if(Add_Key == 0)//加1键
{
mDelay(20);//去抖
if(Add_Key == 0)
{
if (tem==len)tem=0;
else tem++;
do{}while(Add_Key==0);
}
}
if(Add2_Key == 0)//减一键
{
mDelay(20);//去抖
if(Add2_Key == 0)
{
if (tem==0)tem=len;
else tem--;
do{}while(Add2_Key==0);
}
}
switch (t)
{
case 1:{Hour=tem;}break;
case 2:{Minute=tem;}break;
case 3:{Second=tem;}break;
}
//posclear(addr);
//mDelay(250);
//Disp(t,addr);
if(int_Key == 0)break;
}while(1);
}
void wrflag(unsigned char ad)
{
Ypos=1;Xpos=ad;
WriteChar('^');
Ypos=0;
}
void clflag(unsigned char ad)
{
Ypos=1;Xpos=ad;
WriteChar(' ');
Ypos=0;
}
void main()
{
//unsigned char dis[]="00:00:00";
TimerReg=0;
Second=0;//秒 初始化
Minute=0;//分 初始化
Hour=0; //小时 初始化
sele=0;
//定时器初始化
TMOD=0x21;//TMOD定时器工作方式寄存器,0x21设定为T1为方式2 T0为方式1
TH0=0x4c; TL0=0x00; //定时器初值:50ms定时
//TH1=0xfd; TL1=0xfd; //产生9600bps波特率,SMOD为0;
//TR1=1;//起动定时器1
TR0=1;//起动定时器0
//中断
ET0=1;//允许定 时器0 中断,
//IT1=1;//允许 外部中断1
EA=1;//总中断允许控制位,开放所有中断
RstLcd(); //复位LCD
LcdWc(0x01);//清屏
Ypos=0;
Xpos=4;
WriteChar(':');
Xpos=7;
WriteChar(':');
//WriteString(dis);
//P11=0;//测试用
do{
if(int_Key == 0)
{
//P10=~P10;
mDelay(20);//延时处理,防止误按
//P11=~P11;
if(int_Key == 0)//进入设置界面
{
sele++;
//if (sele==5)sele=0;
P12=~P12;
do{}while(int_Key == 0);
}
}
switch(sele)
{
case 4:
{
clflag(8);sele=0;
}break;
case 1:
{
//P17=~P17;//测试用
wrflag(2);
Setkey(23,1);
}break;//小时 ,2,Hour
case 2:
{
//P16=~P16;//测试用
clflag(2);
wrflag(5);
Setkey(59,2);
}break;//分 ,5,Minute
case 3:
{
//P15=~P15; //测试用
clflag(5);
wrflag(8);
Setkey(59,3);
}break;//秒 ,8,Second
}
}while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -