http://zhidao.baidu.com/link?url=z41bGmQVCQYxeT7nATJVtuPhTJme04t_JwHtgyZtyakoyAUObR6edzdczTbIpemgO1SlrKK7z97Z29TY41reua
程序如下 #include <AT89X51.h> #include <absacc.h> #include<stdio.h> #include<math.h> #define WR_COM XBYTE[0x7ff0] #define RD_STA XBYTE[0x7ff2] #define WR_DAT XBYTE[0x7ff1] #define RD_DAT XBYTE[0x7ff3] sbit p32=P3^2; void init_LCD(); void init_cgram(); //void test_lcd(); void clr_lcd(); void PutChar(char t); void delay(); void lcdprintf(char x,char y,char *s); char code CGRAM_TABLE[]={0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x02,// ;年 0x0F,0x09,0x0F,0x09,0x0F,0x09,0x11,0x00, //;月 0x0F,0x09,0x09,0x0F,0x0,0x09,0x0F,0x00}; // ;日 void delay() { unsigned char i; for(i=0;i<250;i++); } void init_LCD() { unsigned char i; WR_COM=0x38; //设置为8位数据总线,16*2,5*7点阵 for(i=0;i<100;i++) delay(); WR_COM=0x01; //清屏幕 for(i=0;i<50;i++) delay(); WR_COM=0x06; //光标移动,显示区不移动,读写操作后AC加1 for(i=0;i<50;i++) delay(); WR_COM=0x0c; for(i=0;i<50;i++) delay(); } void init_cgram() { unsigned char i; //;设置自定义字符 WR_COM=0x40; for(i=0;i<24;i++) { WR_DAT=CGRAM_TABLE[i]; } for(i=0;i<40;i++) delay(); } void PutChar(char t) { WR_DAT=t; delay(); delay(); } void clr_lcd() { WR_COM=0x01; delay(); delay(); } void lcdprintf(char x,char y,char *s) { //clr_lcd(); if(y>1)y=1; WR_COM=(y*0x40+x)|0x80; delay(); delay(); while(*s!=0) { WR_DAT=*s; s++; delay(); delay(); } } main() { unsigned int period,k,i=0; float f,m; char buff[30]; init_LCD(); P2=0x00; while(1) { TMOD=0X09; TH0=0; TL0=0; while(p32==1); TR0=1; while(p32==0); while(p32==1); TR0=0; period=TH0*256+TL0; while(period<=500) /*判断是否分频及计算分频次数*/ { P2++; i++; period=period*10; if(i==6) {P2=0x00; break; } } k=pow(10,i); /* 10的i次方*/ f=((1000000.0/(2*period))*k)*10; if(f<1000) sprintf(buff,"f=%5.2fHZ",f); else {m=f/1000.0; sprintf(buff,"f=%5.2fKHZ",m); } lcdprintf(0,0,buff); } } 那位大哥有解决办法请不吝赐教,小弟急用如果可行一定追加悬赏