完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
`#include #include #define uchar unsigned char #define uint unsigned int #define delay4us() {_nop_();_nop_();_nop_();_nop_();} //ADC0832Òý½Å¶¨Òå ***it CS=P1^0; ***it CLK=P1^1; ***it DIO=P1^2; //LCD1602 ¶Ë¿Ú¶¨Òå ***it RS=P2^0; ***it RW=P2^1; ***it E=P2^2; //ÒÔΪÕûÊý£¬Á½Î»Ð¡ÊýµÄÊý×ÖµçѹÏÔʾ»º³å uchar Display_Buffer[]="0.00V"; //LCDµÚÒ»ÐÐÏÔʾµÄÐÅÏ¢ uchar code Line1[]="Current Voltage:"; //ÑÓʱ×Ó³ÌÐò void DelayMS(uint ms) { uchar t; while(ms--) for(t=0;t<120;t++); } //LCDæ״̬¼ì²â bit LCD_Busy_Check() { bit result; RS=0;RW=1;E=1;delay4us();result=(bit)(P0&0x80);E=0; return result; } //ЩLCDÃüÁî void LCD_Write_Command(uchar cmd) { while(LCD_Busy_Check()); RS=0;RW=0;E=0;_nop_();_nop_();P0=cmd;delay4us(); E=1;delay4us();E=0; } //ÉèÖÃLCDÏÔʾλÖà void Set_Disp_Pos(uchar pos) { LCD_Write_Command(pos|0x80); } //дLCDÊý¾Ý void LCD_Write_Data(uchar dat) { while(LCD_Busy_Check()); RS=1;RW=0;E=0; P0=dat;delay4us(); E=1;delay4us();E=0; } //LCD³õʼ»¯ void LCD_Initialise() { LCD_Write_Command(0x38);DelayMS(1); LCD_Write_Command(0x0C);DelayMS(1); LCD_Write_Command(0x06);DelayMS(1); LCD_Write_Command(0x01);DelayMS(1); } //»ñÈ¡ADת»»½á¹û uchar Get_AD_Result() { uchar i,dat1=0,dat2=0; //Æðʼ¿ØÖÆλ CS=0; CLK=0; DIO=1; _nop_();_nop_(); CLK=1; _nop_();_nop_(); CLK=0;DIO=1;_nop_();_nop_(); CLK=1; _nop_();_nop_(); CLK=0;DIO=0;_nop_();_nop_(); CLK=1;DIO=1;_nop_();_nop_(); CLK=0;DIO=1;_nop_();_nop_(); for(i=0;i<8;i++) { CLK=1; _nop_();_nop_(); CLK=0; _nop_();_nop_(); dat1=dat1<<1|DIO; } for(i=0;i<8;i++) { dat2=dat2|((uchar)(DIO)< CLK=1; _nop_();_nop_(); CLK=0; _nop_();_nop_(); } CS=1; } void main() { uchar i; uint d; LCD_Initialise(); DelayMS(10); while(1) { d=Get_AD_Result()*500.0/255 ; Display_Buffer[0]=d/100+'0'; Display_Buffer[2]=d/10%10+'0'; Display_Buffer[3]=d%10+'0'; Set_Disp_Pos(0x01); i=0; while(Line1[i]!=' |