A Lcd interfaced voltmeter Project Using 89s51/52
A Digital Volt meter is meter which displays the voltage in an alpha numeric Display .
Here is the Circuits ,code in keil ,Hexcode etc
Theory behind calculation of Voltage divider circuit.
All we want is input voltage to ADC should not increase 5V and
Our maximum I/p Voltage to voltmeter is 15V only. So we design
the voltage divider circuit as follows.
All we want is input voltage to ADC should not increase 5V and
Our maximum I/p Voltage to voltmeter is 15V only. So we design
the voltage divider circuit as follows.
where Vmax is Maximum i/p voltage to voltmeter.
Vip is i/p voltage to ADC.
R1 and R2 are resistance of voltage divider circuit.
Vmax
---
|
\
/ R1
\
/
|___ I/p (Vip)
|
\
/ R2
\
/
|
|
V
GND
Vmax = 15V
V = R2*Vmax/(R1+R2)
5/15 = R2/R1+R2
3 = R1/R2+1
2 = R1/R2
R2 = R1/2
Lets take R1 as 200K
and R2 will be 100K
Maximum current: Imax = (Vmax-Vipmax)/R1 (approx)
Vmax = 15V
Vipmax = 5V
R1 = 200K
Imax = (15-5)/200 = 10/200 = 0.02mA
Keil Progarm
#include <REGX51.H>
#include "lcd.h"
#define adc_port P1 //ADC Port
#define rd P3_7 //Read signal P3.7
#define wr P3_6 //Write signal P3.6
#define cs P3_5 //Chip Select P3.5
#define intr P3_4 //INTR signal P3.4
void conv(); //Start of conversion function
void read(); //Read ADC function
unsigned int adc_avg, adc;
void main()
{
char i;
LCD_INI();
while (1) { //Forever loop
adc_avg = 0;
for (i = 0; i < 10; i++) {
conv(); //Start conversion
read(); //Read ADC
adc_avg += adc;
}
adc_avg = adc_avg / 10;
wrt_cmd(0x80);
wrt_string("V(DC): ");
adc = adc_avg * 59;
hex2lcd((unsigned char) (adc / 1000));
wrt_data('.');
adc = adc % 1000;
hex2lcd((unsigned char) (adc / 10));
wrt_data('V');
}
}
void conv()
{
cs = 0; //Make CS low
wr = 0; //Make WR low
wr = 1; //Make WR high
cs = 1; //Make CS high
while (intr); //Wait for INTR to go low
}
void read()
{
cs = 0; //Make CS low
rd = 0; //Make RD low
adc = adc_port; //Read ADC port
rd = 1; //Make RD high
cs = 1; //Make CS high
}
Hex Code
:10019400D2A7C2B0D2B130A706C2B2D2B280F7227F
:0E01B4001201948FA0C2B0C2B1D2B2C2B22268
:0E01C2001201948FA0D2B0C2B1D2B2C2B2224A
:10015B008B0D8A0E890FAB0DAA0EA90F12008A60A8
:10016B0013050FE50F7002050E14F912008AFF122A
:05017B0001C280E22238
:100180007F301201B47F0C1201B47F011201B47FE1
:04019000060201B4AE
:10010A00AE07E4FD749C2EFEC36480948040010D0A
:10011A00C3EE6480948050ECED648094804007EDD7
:10012A002430FF1201C2E4FD74642EFE74F62EFE22
:10013A00C36480948040010DC3EE6480948050ECC7
:10014A00ED2430FF1201C2EE240AFD2430FF020121
:01015A00C2E2
:0801E80056284443293A200087
:10000300120180E4F50AF50BF50C1201D01201A4DC
:10001300E509250BF50BE508350AF50A050CC3E5DB
:100023000C6480948A40E3AE0AAF0B7C007D0A1215
:1000330000B58E0A8F0B7F801201B47BFF7A0179A2
:10004300E812015BAE0AAF0B7C007D3B1200A38E6E
:10005300088F097C037DE81200B512010A7F2E1276
:1000630001C2AE08AF097C037DE81200B58C088D90
:1000730009AE08AF097C007D0A1200B512010A7FA0
:07008300561201C202000643
:0C01D000C2B5C2B6D2B6D2B520B4FD2232
:1001A400C2B5C2B7AF907508008F09D2B7D2B522D5
:030000000201DC1E
:0C01DC00787FE4F6D8FD75810F02000367
:10008A00BB010689828A83E0225002E722BBFE0274
:09009A00E32289828A83E49322A7
:1000A300EF8DF0A4A8F0CF8CF0A428CE8DF0A42E71
:0200B300FE222B
:1000B500BC000BBE0029EF8DF084FFADF022E4CC2F
:1000C500F875F008EF2FFFEE33FEEC33FCEE9DECF8
:1000D500984005FCEE9DFE0FD5F0E9E4CEFD22ED3E
:1000E500F8F5F0EE8420D21CFEADF075F008EF2F88
:1000F500FFED33FD4007985006D5F0F222C398FD79
:050105000FD5F0EA2215
:00000001FF
:0E01B4001201948FA0C2B0C2B1D2B2C2B22268
:0E01C2001201948FA0D2B0C2B1D2B2C2B2224A
:10015B008B0D8A0E890FAB0DAA0EA90F12008A60A8
:10016B0013050FE50F7002050E14F912008AFF122A
:05017B0001C280E22238
:100180007F301201B47F0C1201B47F011201B47FE1
:04019000060201B4AE
:10010A00AE07E4FD749C2EFEC36480948040010D0A
:10011A00C3EE6480948050ECED648094804007EDD7
:10012A002430FF1201C2E4FD74642EFE74F62EFE22
:10013A00C36480948040010DC3EE6480948050ECC7
:10014A00ED2430FF1201C2EE240AFD2430FF020121
:01015A00C2E2
:0801E80056284443293A200087
:10000300120180E4F50AF50BF50C1201D01201A4DC
:10001300E509250BF50BE508350AF50A050CC3E5DB
:100023000C6480948A40E3AE0AAF0B7C007D0A1215
:1000330000B58E0A8F0B7F801201B47BFF7A0179A2
:10004300E812015BAE0AAF0B7C007D3B1200A38E6E
:10005300088F097C037DE81200B512010A7F2E1276
:1000630001C2AE08AF097C037DE81200B58C088D90
:1000730009AE08AF097C007D0A1200B512010A7FA0
:07008300561201C202000643
:0C01D000C2B5C2B6D2B6D2B520B4FD2232
:1001A400C2B5C2B7AF907508008F09D2B7D2B522D5
:030000000201DC1E
:0C01DC00787FE4F6D8FD75810F02000367
:10008A00BB010689828A83E0225002E722BBFE0274
:09009A00E32289828A83E49322A7
:1000A300EF8DF0A4A8F0CF8CF0A428CE8DF0A42E71
:0200B300FE222B
:1000B500BC000BBE0029EF8DF084FFADF022E4CC2F
:1000C500F875F008EF2FFFEE33FEEC33FCEE9DECF8
:1000D500984005FCEE9DFE0FD5F0E9E4CEFD22ED3E
:1000E500F8F5F0EE8420D21CFEADF075F008EF2F88
:1000F500FFED33FD4007985006D5F0F222C398FD79
:050105000FD5F0EA2215
:00000001FF
LCD.c File
#include "lcd.h"/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**** Cheacking the busy flag of LCD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void busy()
{
flag = 1;
rs = 0;
rw = 1;
while (flag != 0) {
en = 0;
en = 1;
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**** Writing command to LCD ****
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void wrt_cmd(unsigned char val_lcd)
{
busy();
lcd_port = val_lcd;
rs = 0;
rw = 0;
en = 1;
en = 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~
**** Writing data on LCD ****
~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void wrt_data(unsigned char dat)
{
busy();
lcd_port = dat;
rs = 1;
rw = 0;
en = 1;
en = 0;
}
void wrt_string(unsigned char *string)
{
while (*string)
wrt_data(*string++);
}
void LCD_INI(void)
{
wrt_cmd(0X30);
wrt_cmd(0X0C);
wrt_cmd(0X01);
wrt_cmd(0X06);
}
void hex2lcd(unsigned char hex)
{
char temp1, temp2;
temp1 = hex;
temp2 = 0;
do {
temp1 = temp1 - 100;
if (temp1 >= 0)
temp2++;
} while (temp1 >= 0);
if (temp2 > 0)
wrt_data(temp2 + 0x30);
temp2 = 0;
temp1 = temp1 + 100;
do {
temp1 = temp1 - 10;
if (temp1 >= 0)
temp2++;
} while (temp1 >= 0);
wrt_data(temp2 + 0x30);
temp2 = temp1 + 10;
wrt_data(temp2 + 0x30);
} LCD Header File
#ifndef __LCD_H__
#define __LCD_H__
#include <REGX51.H>
#define lcd_port P2
#define rs P3_0
#define rw P3_1
#define en P3_2
#define flag P2_7
void wrt_cmd(unsigned char);
void wrt_data(unsigned char);
void wrt_string(unsigned char *);
void LCD_INI(void);
void busy(void);
void hex2lcd(unsigned char);
#endif