《1602液晶频率计的设计(Proteus仿真图和程序).docx》由会员分享,可在线阅读,更多相关《1602液晶频率计的设计(Proteus仿真图和程序).docx(5页珍藏版)》请在课桌文档上搜索。
1、基于51单片机的1602液晶频率计设计一、Proteus仿真图:二、程序代码最大测量65536Hz的频率计/原理:TO定时IS,Tl计数include#include#defineucharunsignedchar#defineuintunsignedintuintcount=0;uintnm=0;ucharFw,Fq,Fb,Fs,Fg;#defineDataPortPOsbitLCM.RS=P20;sbitLCM.RW=P2a1;sbitLCM.EN=P22;ucharcodestrO=-Testfrequency-);ucharcodestrl=F=OOOOOHz);/ucharcodes
2、tr2=:voiddelay(unsignedintk)(unsignedintij;for(i=0;ik;i+)fr(j=0121+)(;)/=/*函数名:VoidWaiIFOrEnable(VOid)作用:检测忙碌信号*/=/voidWaitForEnable(Void)DataPort=Oxff;1.CM-RS=O;1.CM-RW=I;_nop_();1.CM_EN=1;.nopj);.nopj);While(DataPort&0x80);delay(5);1.CM-EN=O;)/=/*函数名:voidWriteCommandLCM(ucharCMD.ucharAtlribc)作用:写命
3、令到LCM*/=/voidWriteCommandLCM(ucharCMD,ucharAttribc)(if(Attribc)WaitForEnable();1.CM-RS=O;1.CM-RW=O;_nop_();DataPort=CMD;-110P-();1.CM-EN=I;_nop_();.nopj);1.CM-EN=O;/=/*函数名:VOidWriteDataLCM(uchardataW)作用:写数据*/=/voidWriteDataLCMCuchardataV)WaitForEnabIeO;1.CM-RS=I;1.CM-RW=O;.nopj);DataPort=dataW;-11op
4、-0;1.CM-EN=I;.nopj);-11op-();1.CM-EN=O;)/=/*函数名:voidInitLcdO作用:LCM初始化*/=/voidInitLcdOWriteCommandLCM(0x38,1);WriteComnandLCM(0x08,1);WriteCommandLCM(0x01,1);WriteComnandLCM(0x06,1);WriteCommandLCM(OxOc,1);/=/*函数名:voidDisplayOneChar(ucharX,ucharY,ucharDData)作用:显示指定坐标的一个字符*/=/voidDisplayOneCharCucharX
5、,ucharY,ucharDData)Y&=1;X=15;if(Y)X=0x40;X=0x80;WriteCommandLCM(X,0);WriteDataLCM(DData);/=/*函数名:voidDisplayListChar(ucharX,ucharY,ucharcode*DData作用:显示指定坐标的一串字符*/=/voidDisp1ayListChar(ucharX,ucharY,ucharcode*DData)ucharListLength=O;Y&=Oxl;X&=OxF;while(X=0;i)DiSPIayLiStChar(i,0,str);显示第一行字符DiSPlayLiSlChar(i,1,strl);显示第二行字符delay(100);1while(l)(if(nm=10)定时10*50MS=500ms(temp=TLl;tempI=THl;COUnI=2*(IemPI*256+iemp);定时2乘以500ms=100Omsdisplay();THl=计数器赋高8初值初值TLI=0;计数器赋低8初值nm=0;TRl=I;TRO=I;