主程序:#includereg52.h#includeintrins.h#includestring.h#includeLCD1602.h#includeADC0808.h//---------------忙检查-------------------//ucharLCD_Busy_Check(){ucharLCD_Status;RS=0;RW=1;E=1;delay4us();LCD_Status=P0;E=0;returnLCD_Status;}//--------------向LCD写入命令--------------------//voidWrite_LCD_Command(ucharcmd){while((LCD_Busy_Check()&0x80)==0x80);//忙等待RS=0;RW=0;E=0;P0=cmd;delay4us();E=1;delay4us();E=0;}//-----------向LCD写入一个字节的数据函数-----------------*/voidWrite_LCD_Data(uchardat){while((LCD_Busy_Check()&0x80)==0x80);RS=1;RW=0;E=0;P0=dat;delay4us();E=1;delay4us();E=0;}//-----------LCD初始化-----------------*/voidInitialize_LCD1602()//液晶初始化函数{Write_LCD_Command(0x38);delay50us(10);//功能设置,数据长度为8位,双行显示,5×7点阵字体Write_LCD_Command(0x0C);delay50us(10);//显示开,关光标Write_LCD_Command(0x06);delay50us(10);//字符进入模式:屏幕不动,字符后移Write_LCD_Command(0x01);delay50us(10);//清屏}//-----------在LCD上显示字符串-----------------*/voidLCD_Display(uchar*str){uchari;for(i=0;istrlen(str);i++){Write_LCD_Data(str[i]);delay50us(100);}}unsignedlongdat_adc0808;uchardisplay_buffer[][16]={{Currentvoltage:},{(CH)=0.00V}};voiddelay50us(uintm){uintn,k;for(n=m;n0;n--)for(k=25;k0;k--);}uintadc0808_init()//AD初始化{START=0;OE=0;START=1;START=0;while(EOC==0);OE=1;dat_adc0808=P1;OE=0;returndat_adc0808;}voidRefresh_show()//刷新显示{uintt=dat_adc0808*500.0/255;//display_buffer[1][7]=t/100+'0';//整数位display_buffer[1][9]=t/10%10+'0';//两个小数位display_buffer[1][10]=t%10+'0';}sbitCLOCK=P2^6;externuchardisplay_buffer[][16];voidmain(){TMOD=0x02;TH0=0x14;TL0=0x00;IE=0x82;TR0=1;Initialize_LCD1602();delay50us(10);Write_LCD_Command(0x80);//设置显示的初始位置LCD_Display(display_buffer[0]);//显示Thevoltageis:while(1){adc0808_init();Refresh_show();Write_LCD_Command(0xC0);//设置显示的初始位置LCD_Display(display_buffer[1]);//显示测得的数据}}voidTimer0_INT()interrupt1{CLOCK=!CLOCK;}ADC0808头文件#ifndef__ADC0808_H__#define__ADC0808_H__#includereg52.h#definedata_portP1#defineucharunsignedchar#defineuintunsignedintsbitSTART=P2^3;sbitEOC=P2^4;sbitOE=P2^5;voiddelay50us(uintm);//延时uintadc0808_init();//AD初始化voidRefresh_show();#endifLCD1602头文件#ifndef__lCD1602_H__#define__LCD1602_H__#includereg52.h#definedat_portP0#defineucharunsignedchar#defineuintunsignedint#definedelay4us(){_nop_();_nop_();_nop_();_nop_();}sbitRS=P2^0;//RS=1数据RS=0命令sbitRW=P2^1;//RW=1读取RW=0写入sbitE=P2^2;//E使能信号ucharLCD_Busy_Check();//忙检查voidWrite_LCD_Command(ucharcmd);//向LCD写入命令voidWrite_LCD_Data(uchardat);//向LCD写入一个字节的数据函数voidInitialize_LCD1602();//液晶初始化函数voidLCD_Display(uchar*str);//在LCD上显示字符串#endif