5-channels voltmeter using PIC16f877a

General discussion on mikroC.
Post Reply
Author
Message
bill_clinton
Posts: 1
Joined: 08 Apr 2010 17:37

5-channels voltmeter using PIC16f877a

#1 Post by bill_clinton » 08 Apr 2010 19:38

I've tried to edit the ADC_on_LCD example to develop a 5 channel multimeter and connect to 4x20 LCD display.

Can anyone help me check is it correct?

Code: Select all

/*
 * Project name:
     ADC_on_LCD (Displaying ADC result on LCD)
 * Copyright:
     (c) Mikroelektronika, 2005-2008.
 * Description:
     This code demonstrates how to use library function ADC_read, and library
     procedures and functions for LCD display (4 bit interface).
 * Test configuration:
     MCU:             PIC16F877A
     Dev.Board:       EasyPIC4
     Oscillator:      HS, 08.0000 MHz
     Ext. Modules:    LCD
     SW:              mikroC v8.0.0.0
 * NOTES:
     On EasyPIC4 jumpers should be on RA0, RA1, RA2, RA3 and RA5 at A-D Converter Input.
*/

#include"built_in.h"

unsigned char ch;
unsigned int adc_rd;
char *text;
long tlong;

void main() {
  INTCON = 0;                              // disable all interrupts
  Lcd_Init(&PORTB);
  LCD_Cmd(LCD_CURSOR_OFF);                 // send command to LCD (cursor off)
  LCD_Cmd(LCD_CLEAR);                      // send command  to LCD (clear LCD)

  text = "mikroElektronika";               // assign text to string
  LCD_Out(1,1,text);                       // print string a on LCD, 1st row, 1st column
  text = "LCD example";                    // assign text to string
  LCD_Out(2,1,text);                       // print string a on LCD, 2nd row, 1st column

  ADCON1     = 0x82;                       // configure VDD as Vref, and analog channels
  TRISA      = 0xFF;                       // designate PORTA as input
  Delay_ms(5000);
  text  = "V:";                            // assign text to string
  while (1) {
    adc_rd  = ADC_read(0);                 // get ADC value from 0th channel
    LCD_Out(1,1,text);                     // print string a on LCD, 1st row, 1st column

    tlong = (long)adc_rd * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

    ch     = tlong / 1000;                 // extract volts digit
    LCD_Chr(1,3,48+ch);                    // write ASCII digit at 1st row, 3rd column
    LCD_Chr_CP('.');

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = tlong % 10;                    // extract 0.001 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point
    LCD_Chr_CP('V');

    adc_rd  = ADC_read(1);                 // get ADC value from 1st channel
    LCD_Out(2,1,text);                     // print string a on LCD, 2nd row, 1st column

    tlong = (long)adc_rd * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

    ch     = tlong / 1000;                 // extract volts digit
    LCD_Chr(2,3,48+ch);                    // write ASCII digit at 2nd row, 3rd column
    LCD_Chr_CP('.');

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = tlong % 10;                    // extract 0.001 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point
    LCD_Chr_CP('V');

    adc_rd  = ADC_read(2);                 // get ADC value from 2nd channel
    LCD_Out(3,1,text);                     // print string a on LCD, 3rd row, 1st column

    tlong = (long)adc_rd * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

    ch     = tlong / 1000;                 // extract volts digit
    LCD_Chr(3,3,48+ch);                    // write ASCII digit at 3rd row, 3rd column
    LCD_Chr_CP('.');

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = tlong % 10;                    // extract 0.001 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point
    LCD_Chr_CP('V');

    adc_rd  = ADC_read(3);                 // get ADC value from 3rd channel
    LCD_Out(4,1,text);                     // print string a on LCD, 4th row, 1st column

    tlong = (long)adc_rd * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

    ch     = tlong / 1000;                 // extract volts digit
    LCD_Chr(4,3,48+ch);                    // write ASCII digit at 4th row, 3rd column
    LCD_Chr_CP('.');

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = tlong % 10;                    // extract 0.001 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point
    LCD_Chr_CP('V');

    adc_rd  = ADC_read(4);                 // get ADC value from 4th channel
    LCD_Out(1,11,text);                     // print string a on LCD, 1st row, 11th column

    tlong = (long)adc_rd * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

    ch     = tlong / 1000;                 // extract volts digit
    LCD_Chr(1,13,48+ch);                    // write ASCII digit at 2nd row, 13th column
    LCD_Chr_CP('.');

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = tlong % 10;                    // extract 0.001 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point
    LCD_Chr_CP('V');

    Delay_ms(1);
  }
}//~!
I'm still new into microcontroller.

pusu
Posts: 1
Joined: 10 Feb 2012 18:58
Location: Zalau_Romania

Re: 5-channels voltmeter using PIC16f877a

#2 Post by pusu » 10 Feb 2012 19:06

bill_clinton wrote:I've tried to edit the ADC_on_LCD example to develop a 5 channel multimeter and connect to 4x20 LCD display.

Can anyone help me check is it correct?
Hi bill_clinton,
Did you resolved something in this matter? I want to know the solution. Thk.

Post Reply

Return to “mikroC General”