资源描述:
《lcd初始化c语言程序.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、用1位数码管显示按键的键值#includeu#includeuunsignedcharcodesz1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};uunsignedcharcodejp[]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7
2、,0x77};uunsignedcharc=0;uvoiddelay(unsignedintt)u{uunsignedchari;uwhile(t--)u{ufor(i=0;i<125;i++);u}u}uvoidsm()u{unsignedchark,j,n,a,m=0xfe;uP2=0xf0;k=P2;k=k&0xf0;uif(k!=0xf0)u{delay(5);uif(k!=0xf0)u{for(j=0;j<4;j++)u{P2=m;n=P2;ufor(a=0;a<16;a++)u{if(j
3、p[a]==n)c=a;}um=_crol_(m,1);}u}u}}uvoidmain()u{uwhile(1)u{sm();uP1=sz1[c];}u}uLCD编程流程:1.初始化(设定LCD的各种工作显示方式)2.设定第一行显示起始地址3.送数据到数据端口,显示字符串4.设定第二行显示起始地址5.送数据到数据端口,显示数据1.初始化:u大概涉及到4个命令,发四次命令。所以把发命令编程子程序,调用子程序时只是命令代码不一样。uvoidbusy()u{rs=0;rw=1;en=1;udelay(1)
4、;uf=P0;uen=0;ubusy1=f&0x80;}uvoidwc(unsignedchara)u{while(busy1==0x80);urs=0;rw=0;en=0;uP0=a;uen=1;delay(1);en=0;}uvoidchsh()u{wc(0x38);delay(1);uwc(0x01);delay(1);uwc(0x0c);delay(1);uwc(0x06);delay(1);}uVoidmain()u{…uchsh();u…u}2.设定第一行显示起始地址uVoidmain(
5、)u{…uwc(0x80);u…u}3.送数据到数据端口,显示字符串送字符串到数据端口,实际上是逐个把数据送过去。所以把送数据编程子程序,调用子程序时只是数据不一样。unsignedcharhy[]={"Thenumberis"};uvoidwd(unsignedcharb)u{while(busy1==0x80);urs=1;rw=0;en=0;uP0=b;uen=1;delay(1);en=0;}uVoidmain()u{…ufor(j=0;j<13;j++)u{wd(hy[j]);}u…u}4
6、.设定第二行显示起始地址uVoidmain()u{…uwc(0xc8);u…u}5.送数据到数据端口,显示数据uvoiddispd(unsignedcharc)u{unsignedchard;ud=_crol_(c,4);ud=d&0x0f;uif(d<0x0a)d=d+0x30;uelsed=d+0x37;uwd(d);uc=c&0x0f;uif(c<0x0a)c=c+0x30;uelsec=c+0x07;uwd(c);}uVoidmain()u{…uUnsignedchare=0x43;udis
7、pd(e);u…u}实验:用LCD显示键盘的键值按键启动加1减1暂停倒计时程序voidds()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;if(++m>19){n--;if(n==0)while(1)disp(0);F=1;delay(20);F=0;delay(20);m=0;}}按键启动加1减1暂停倒计时#includesbitK1=P2^0;//加1sbitK2=P2^1;//减1sbitK3=P2^2;//暂
8、停sbitK4=P2^3;//启动sbitLED=P2^4;//发光二极管sbitF=P2^5;//蜂鸣器sbitS0=P3^6;sbitS1=P3^7;voiddisp(unsignedcharn);unsignedcharm=0;unsignedcharn=9;unsignedcharcodeD[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};voiddelay(unsignedinta){unsigne