您好,欢迎访问三七文档
实验八LCM1602液晶显示实验姓名:专业:通信工程学号:2011412422成绩:一、实验目的1.掌握KeilC51软件与Protues软件联合仿真调试方法;2.掌握LCM1602液晶模块显示西文读原理及使用方法;3.掌握用8位数据模式驱动LCM1602液晶的C语言编程方法;4.掌握LCM1602液晶模块显示数字的C语言编程方法。二、实验内容1.用Proteus设计一LCM1602液晶显示接口电路。要求利用P0口接LCM1602液晶的数据端,P2.0~P2.2做LCM1602液晶的控制信号输入端。P3.0~P3.3口扩展4个功能键K1~K4。2.编写程序,实现字符的静态和动态显示。字符第一行为“1.姓名全拼”,第二行为“专业全拼+学号”。液晶的初始化、字符显示程序可参考网上的程序文件。3.编写程序,利用功能键实现字符的纵向滚动和横向滚动等效果显示。主程序动态显示“Myinformation!”,滚动效果显示四行字符:1:姓名全拼2.专业全拼+学号3.MCS-51EXP84.LCD三、实验仪器与设备1.微机一台2.keilc51集成开发环境3.proteus仿真软件五、实验程序一、静态显示#includereg51.h#defineucharunsignedchar#defineuintunsignedintucharcodetable[]=DaiHaiyang;ucharcodetable1[]=tongxin2011412422;sbitlcden=P2^2;sbitlcdrw=P2^1;sbitlcdrs=P2^0;ucharnum;voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidwrite_com(ucharcom){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_data(uchardate){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidinit(){lcden=0;lcdrw=0;write_com(0x38);write_com(0x0e);write_com(0x06);write_com(0x01);write_com(0x80+0x1);}voidmain(){init();delay(100);while(1){for(num=0;table[num]!='\0';num++){write_data(table[num]);delay(200);}write_com(2);write_com(0x80+0x40);for(num=0;table1[num]!='\0';num++){write_data(table1[num]);delay(200);}while(1);}}二、动态显示#includereg51.h#defineucharunsignedchar#defineuintunsignedintucharcodetable[]=DaiHaiyang;ucharcodetable1[]=tongxin2011412422;sbitlcden=P2^2;sbitlcdrw=P2^1;sbitlcdrs=P2^0;ucharnum;voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidwrite_com(ucharcom){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_data(uchardate){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidinit(){lcden=0;lcdrw=0;write_com(0x38);write_com(0x0e);write_com(0x06);write_com(0x01);write_com(0x80+0x1);}voidmain(){init();delay(100);while(1){for(num=0;table[num]!='\0';num++){write_data(table[num]);delay(200);}write_com(2);write_com(0x80+0x40);for(num=0;table1[num]!='\0';num++){write_data(table1[num]);delay(200);}write_com(1);}}三、滚动显示#includereg51.h#defineucharunsignedchar#defineuintunsignedintucharcodetable0[]=Myinformation!;ucharcodetable1[]=1.daihaiyang2.tongxin2011412422;ucharcodetable2[]=3.MCS-514.LCDDISPLAY;sbitlcden=P2^2;sbitlcdrw=P2^1;sbitlcdrs=P2^0;sbitk3=P3^2;ucharnum,flag=0;voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidwrite_com(ucharcom){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_data(uchardate){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidinit(){lcden=0;lcdrw=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80+0x1);}voidmain(){init();TMOD=0x01;TH0=(65536-10000)/256;TL0=(65536-10000)%256;EA=1;ET0=1;TR0=1;EX0=1;EX1=1;while(1){write_com(0x80);for(num=0;num16;num++){write_com(0x80+0x16+num);write_data(table0[num]);}write_com(0x1c);}}voidtime0()interrupt1{P3=0xff;if(P3!=0xff){delay(20);if(P3!=0xff&&flag==1){flag=0;switch(P3){case0xfd:{write_com(1);write_com(0x80);for(num=0;table1[num]!='\0';num++){write_data(table1[num]);}write_com(0x80+0x40);for(num=0;table1[num]!='\0';num++){write_data(table2[num])}for(num=0;num40;num++){write_com(0x1c);}}delay(200);break;}}}elseflag=1;}voidINT_0()interrupt0{EX0=0;delay(10);if(k3)while(k3);elseEX0=1;}voidINT_1()interrupt2{write_com(1);write_com(0x80);for(num=0;table0[num]!='\0';num++){write_data(table0[num]);}write_com(0x18);delay(100);}XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51X1CRYSTALC11nFC21nFC3220uR1300234567891RP1RESPACK-8D714D613D512D411D310D29D18D07E6RW5RS4VSS1VDD2VEE3LCD1LM016LRV1100
本文标题:实验八1602液晶
链接地址:https://www.777doc.com/doc-6196433 .html