This web site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more.

Last update: 31/07/2015

Here follows an example program to convert two channels of ADC values read on Porta in Volt using a four lines LCD. The program should be reaally clear and can be easily modified for any need.

Very often there is the need to show a voltage value using one or more analog converters on PORTA. Such a conversion can be done quite easily using an high level language as Mikroc.

// Define LCD - to be modified according to the schematics
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;

unsigned char car,x,y;
char *voltage = "00.00";
long temp;

{
LCD_Chr(x,y,48+car);
LCD_Chr_CP(48+car);
LCD_Chr_CP(48+car);
LCD_Chr_CP(48+car);
delay_ms(30);
}

void ShowVoltage (int x,int y, unsigned int value)     // Routine to show the ADC_read conversion in Volt
{
temp = (long)value* 5000;
temp = temp / 1023;
voltage[0] = temp/10000 + 48;
voltage[1] = (temp/1000)%10 + 48;
voltage[3] = (temp/100)%10 + 48;
voltage[4] = (temp/10)%10 + 48;
Lcd_Out (x,y,voltage);
delay_ms(30);
}

void main() {

ADCON1 = 0x80;                          // All analogs - right justify
TRISA = 0xFF;                               // PORTA Input
TRISB = 0;                                    // PORTB Output
TRISD = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
do {
Lcd_Out(3,1,"Ch1:");
ShowVoltage(3,11,value);
Lcd_Out(4,1,"Ch2:");
ShowVoltage(4,11,value);
} while(1);
}

Naturally if we have to measure different levels of voltage we have to use a resistor partitioner to reduce such voltages value to an acceptable value for the picmicro and modify the multiplier value (5000) with a right one.

Today25
Yesterday197
This week25
Total1888741

### Who Is Online

5
Online

Monday, 28 November 2022 02:34