كود:
/* Project: Digital Voltmeter based on PIC16F877 Oscillator @ 4MHz, MCLR Enabled, PWRT Enabled, WDT OFF */ // LCD module connections sbit LCD_RS at RB0_bit; sbit LCD_EN at RB1_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB0_bit; sbit LCD_EN_Direction at TRISB1_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Message1[] = "DVM Project"; unsigned int ADC_Value, DisplayVolt; char *volt = "00.0"; void main() { ADCON0 = 0 ; // Analog channel select @ AN0 ADCON1 = 0b00001110 ; // RA0/AN0 is analog input TRISB = 0b00000000; // PORTB All Outputs TRISA = 0b00000001; // PORTA All Outputs, Except RA0 Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // CLEAR display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,Message1); Lcd_Chr(2,10,'V'); do { ADC_Value = ADC_Read(0); DisplayVolt = ADC_Value * 2; volt[0] = DisplayVolt/1000 + 48; volt[1] = (DisplayVolt/100)%10 + 48; volt[3] = (DisplayVolt/10)%10 + 48; Lcd_Out(2,5,volt); delay_ms(500); // Hold for 500 ms } while(1);} // End main()