/*--------------------------------------- Name :LCD1602液晶显示Created By : Paul HeDate : 2012.9.18----------------------------------------*/ # include <reg52.h># include "macroandconst.h"# define LcdData P0sbit EN=P3^5;sbit RW=P3^6;sbit RS=P3^7;//sfr LcdData=0x80;/*********************延时函数*********************/voidDelay(uint16 t){while(t--);}/*********************LCD1602驱动程序*********************/void //完成一个字节命令的写入LcdWriteCmd(uint8 cmd){Delay(1000);EN=0;RW=0;RS=0;LcdData=cmd;EN=1;Delay(20);EN=0;}void //完成一个字节数据的写入LcdWriteDat(uint8 dat){Delay(1000);EN=0;RW=0;RS=1;EN=1;LcdData=dat;EN=0;}void //清屏LcdClear(){LcdWriteCmd(0x01);}void //初始化液晶屏LcdInit(){LcdWriteCmd(0x38);Delay(200);LcdWriteCmd(0x0e);Delay(200);LcdWriteCmd(0x06);Delay(200);}void //完成字符串的写入,如果第一行写满,自动切换到第二行LcdWriteStr(uint8 addr,uint8*p){LcdWriteCmd(addr);while(*p!=0x00){LcdWriteDat(*p);p++;if(addr++==0x8f){LcdWriteCmd(0xc0);}}}//主函数voidmain(){LcdClear();LcdInit();LcdWriteStr(0x80,"HeHuiBo");LcdWriteStr(0xc0,"10101072054");while(1);}/*--------------------------------------- Name :LCD12864液晶显示Created By : Paul HeDate : 2012.9.19----------------------------------------*/ # include <reg52.h># include "macroandconst.h"# define LcdData P0sbit EN=P3^5;sbit RW=P3^6;sbit RS=P3^7;//sfr LcdData=0x80;/*********************延时函数*********************/voidDelay(uint16 t){while(t--);}/*********************LCD12864驱动程序*********************/voidLcdWriteCmd(uint8 cmd){Delay(5000);EN=0;RW=0;RS=0;EN=1;LcdData=cmd;Delay(50);EN=0;}voidLcdWriteDat(uint8 dat){Delay(5000);EN=0;RW=0;RS=1;EN=1;LcdData=dat;Delay(50);EN=0;}voidLcdClear(){LcdWriteCmd(0x01);}voidLcdInit(){Delay(0xffff);Delay(0xffff);LcdWriteCmd(0x30);Delay(1000);LcdWriteCmd(0x30);Delay(1000);LcdWriteCmd(0x0c);Delay(1000);LcdWriteCmd(0x01);Delay(1000);LcdWriteCmd(0x06);Delay(1000);}voidLcdShowGroup(uint8 x,uint8y,uint8 *p){switch(y){case 1:LcdWriteCmd(0x80+x-1);break;case 2:LcdWriteCmd(0x90+x-1);break;case 3:LcdWriteCmd(0x88+x-1);break;case 4:LcdWriteCmd(0x98+x-1);break;default :break;}while(*p){LcdWriteDat(*p++);}}//主函数voidmain(){LcdClear();LcdInit();LcdShowGroup(1,1,"12864液晶实验");LcdShowGroup(3,2,"何辉波");LcdShowGroup(2,3,"10101072054");while(1);}# include <reg52.h># include "macroandconst.h" # define LcdData P0sbit EN=P3^5;sbit RW=P3^6;sbit RS=P3^7;uint8 lcdcount=0;/*********************延时函数*********************/ voidDelay(uint16 t){while(t--);}/*********************LCD1602驱动程序*********************/ voidLcdWriteCmd(uint8 cmd) {Delay(1000);EN=0;RW=0;RS=0;LcdData=cmd;EN=1;Delay(20);EN=0;}voidLcdWriteDat(uint8 dat){Delay(1000);EN=0;RW=0;RS=1;EN=1;LcdData=dat;EN=0;}voidLcdClear(){LcdWriteCmd(0x01);}voidLcdInit(){LcdWriteCmd(0x38);Delay(200);LcdWriteCmd(0x0e);Delay(200);LcdWriteCmd(0x06);Delay(200);}/*voidLcdWriteStr(uint8 addr,uint8*p){LcdWriteCmd(addr);while(*p!=0x00){LcdWriteDat(*p);p++;if(addr++==0x8f){LcdWriteCmd(0xc0);}}} */void UART0_Init(){SCON=0x50;TMOD|=0x20;PCON|=0x80;TH1=0xFD;TL1=0xFD;IE|=0x90;TR1=1;}void UART0_SendByte(uint8 dat){EA=0;SBUF=dat;while(TI==0);TI=0;EA=1;}void UART0_SendStr(uint8 *Str){uint8 i;i=0;while(*(Str+i)!='\0'){UART0_SendByte(*(Str+i));i=i+1;}}void UART0_SendUint16(uint16dat){uint8 flag;uint8 temp;flag=0;temp=dat/10000;if (temp!=0||flag!=0){flag=1;UART0_SendByte(temp+'0');}dat=dat%10000;temp=dat/1000;if (temp!=0||flag!=0){flag=1;UART0_SendByte(temp+'0');}dat=dat%1000;temp=dat/100;if (temp!=0||flag!=0){flag=1;UART0_SendByte(temp+'0');}dat=dat%100;temp=dat/10;if (temp!=0||flag!=0){flag=1;UART0_SendByte(temp+'0');}dat=dat%10;UART0_SendByte(temp+'0'); }void UART_Rcv()interrupt 4{uint8 temp;EA=0;if(RI){RI=0;temp=SBUF;UART0_SendByte(temp);UART0_SendByte(0x0d);UART0_SendByte(0x0a);lcdcount++;if(lcdcount==16){LcdWriteCmd(0xc0);}if(lcdcount==32){lcdcount=0;LcdClear();}LcdWriteDat(temp);}EA=1;}void main(){LcdClear();UART0_Init();LcdInit();UART0_SendStr("串口程序欢迎您!");UART0_SendByte(0x0d);UART0_SendByte(0x0a);UART0_SendUint16(0x020 89);UART0_SendByte(0x0d);UART0_SendByte(0x0a);while(1);}# include <reg52.h># include "macroandconst.h"sbit EN=P3^5;sbit RW=P3^6;sbit RS=P3^7;//sfr LcdData=0x80;# define LcdData P0# define keyport P2//键盘驱动程序bitReadKey(void){bit dat;keyport =0xf0;//键盘口高四位列线为1,低四位行线为0if(keyport==0xf0){dat=0;//无按键按下}else{dat=1;}return dat;}uint8IdentifyKey(void){uint8 i=1,j=0xfe,m;while(j!=0x7f){keyport=j;m=keyport&0xf0;switch(m){case 0xe0 :{i=i+0;j=0x7f;break;}case 0xd0 :{i=i+4;j=0x7f;break;}case 0xb0 :{i=i+8;j=0x7f;break;}case 0x70 :{i=i+12;j=0x7f;break;}default :{i=i+1;j=(j<<1)+1;break;}}}return i;}/*********************延时函数*********************/voidDelay(uint16 t){while(t--);}/*********************LCD1602驱动程序*********************/void //完成一个字节命令的写入操作LcdWriteCmd(uint8 cmd){Delay(1000);EN=0;RW=0;RS=0;LcdData=cmd;EN=1;Delay(20);EN=0;}void //完成一个字节数据的写入操作LcdWriteDat(uint8 dat){Delay(1000);EN=0;RW=0;RS=1;EN=1;LcdData=dat;EN=0;}void //完成液晶的清屏操作LcdClear(){LcdWriteCmd(0x01);}void //完成液晶初始化操作LcdInit(){LcdWriteCmd(0x38);Delay(200);LcdWriteCmd(0x0e);Delay(200);LcdWriteCmd(0x06);Delay(200);}void //完成字符串雪乳操作,如果第一行写满,自动切换到第二行。