PIC16F688的數(shù)字電壓表設(shè)計(jì)制作
ADC的數(shù)學(xué)的準(zhǔn)確性取決于在輸入端的電阻的精度和穩(wěn)定的參考電壓,VDD = 5 V。我發(fā)現(xiàn),VDD是穩(wěn)定的,以5.02五,我測(cè)R1和R2,和它們的值是1267和3890歐姆 。因此,這給了5.02 V模擬的I / P ---> 0-1023數(shù)字計(jì)數(shù) =>分辨率=(5.02 - 0)/(1023-0)= 0.004907 V /計(jì)數(shù)
VA = 1267 * VIN /(1267 3890)= 0.2457 *輸入電壓
=>我/ P電壓= 4.07 * VA = 4.07 *數(shù)字計(jì)數(shù)* 0.004907
= 0.01997 *數(shù)字計(jì)數(shù)
= 0.02 *數(shù)字計(jì)數(shù)(約)
為了避免浮點(diǎn)運(yùn)算,使用的I / P電壓= 2 *計(jì)數(shù)。
例如,假設(shè)VIN = 7.6V。然后,
VA = 0.2457 *輸入電壓為1.87V
=>數(shù)碼計(jì)數(shù)= 1.87/0.004907 = 381
=>計(jì)算的I / P電壓= 2 * 381 = 0762 = 07.6V(4位產(chǎn)品的前3位數(shù)字 )
固件
固件寫入和mikroC編譯器編譯。LCD_D6的代碼是在這里。
SBIT LCD_D7 RC3_bit;
在TRISC4_bit SBIT LCD_RS_Direction;
TRISC5_bit SBIT LCD_EN_Direction;
TRISC0_bit SBIT LCD_D4_Direction;
TRISC1_bit SBIT LCD_D5_Direction;
TRISC2_bit SBIT LCD_D6_Direction;
SBIT TRISC3_bit LCD_D7_Direction;
/ /高端液晶模塊的連接
字符Message1 [] =“DVM項(xiàng)目“;
unsigned int類型ADC_Value,DisplayVolt;
CHAR *伏=“00.0”;
無(wú)效的主要(){
?。篈NSEL = 0b00000100; / / RA2/AN2是模擬輸入
ADCON0的= 0b00001000; / /模擬輸入通道選擇AN2的
ADCON1 = 0X00;
CMCON0 =為0x07; / / Disbale比較
TRISC = 0b00000000; / / PORTC的所有輸出
TRISA = 0b00001100; / / PORTA所有輸出,除RA3和RA2的
Lcd_Init(); / /初始化液晶
Lcd_Cmd(_LCD_CLEAR); / /清除顯示
Lcd_Cmd(_LCD_CURSOR_OFF) / /游標(biāo)關(guān)閉
Lcd_Out(1,1 Message1);
Lcd_Chr(2,10,“V”);
{
ADC_Value = ADC_Read(2)
DisplayVolt = ADC_Value * 2;
伏[0] = DisplayVolt/1000 + 48 ; ;
伏[1] =(DisplayVolt/100)%10 + 48;
伏[3] =(DisplayVolt/10)10%+ 48;
Lcd_Out(2.5伏);
delay_ms(100);
}(1) ;
}
輸出
評(píng)論