Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Can we design a DC voltmeter with pic16f877a?

Status
Not open for further replies.

RamEtrics

Newbie level 4
Newbie level 4
Joined
Feb 22, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
31
Hi i am trying to designing a DC voltmeter using pic16f877a.If it is possible, tell me the design procedure to do this.And tell the programming in CCS C compiler basics for this topic?
 

Thank you tanveerriaz and Your post was very useful to me.
The program in the link is compiles successfully without error but also i am having problem in the hardware.
LCD doesn't show anything. I am using a 16*2 LCD. Please help me.
 

Hi milan.rajik,advance thank you for coming to help me.
Now my code is working and displays voltage in LCD, but "if else condition" in the code is not working.I heard "float value can't be work in if else condition". Please help me to rectify the mistake...

My code is
Code:
#if defined(__PCM__)
#include <16F877a.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=16000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define LCD_EN      PIN_E0
#define LCD_RS      PIN_E1
#define LCD_RW      PIN_E2

//LCD->R/S R/W EN D0 D1 D2 D3 D4 D5 D6 D7
//PIN->RE0 RE1 RE2 RD0 RD1 RD2 RD3 RD4 RD5 RD6 RD7

void lcd_write(char data);
void lcd_init();
void lcd_newline();
void clr_lcd();


void main()
{
int16 adc_value;
float volts;

delay_ms(10);
output_bit(LCD_RW,0);

delay_ms(100);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
lcd_init();
delay_us(20);

while(1)
{
clr_lcd();
adc_value=read_adc();
volts = (int)(adc_value * 5)/1023.0;
printf(lcd_write,"\fVoltage=%3.2fV",volts);
delay_ms(1000);
if(volts<=5.00)
{
output_bit(pin_b1,1);//Green LED to indicate safety voltage
}
else
{
output_bit(pin_b2,1);//Red LED to indicate vulnerable voltage
}
}
delay_ms(1000);
output_bit(LCD_RW,0);

}

void lcd_init()
{
output_bit(LCD_RS,0);
delay_ms(10);
lcd_write(0x01);
lcd_write(0x38);
lcd_write(0x06);
lcd_write(0x0f);
lcd_write(0x80);
delay_ms(100);
output_bit(LCD_RS,1);
}

void clr_lcd()
{output_bit(LCD_RS,0);
delay_ms(10);
lcd_write(0x01);
output_bit(LCD_RS,1);
delay_ms(1);
}

void lcd_newline()
{
output_bit(LCD_RS,0);
delay_ms(10);
lcd_write(0xc0);
output_bit(LCD_RS,1);
delay_ms(1);
}

void lcd_write(char data)
{
output_d(data);
delay_ms(1);
output_bit(LCD_EN,1);
delay_ms(1);
output_bit(LCD_EN,0);
delay_ms(1);
}
 
Last edited:

hi
you want a DC voltmeter ha? but this program is a simple type of it. what will happen if you have a mixed input signal for example like this:

3a74325328.gif

and also noise can affect your measurement. dont you have problem with these?
 

CCS C has a LCD library. Include lcd.c and define LCD connections and use it. Who said that if() cannot be used to test float values?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#if defined(__PCM__)
 
#include <16F877a.H>
 
#device adc=10
 
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
 
#use delay(clock=16000000)
 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
 
#define LCD_EN      PIN_E0
#define LCD_RS      PIN_E1
#define LCD_RW      PIN_E2
 
//LCD->R/S R/W EN D0 D1 D2 D3 D4 D5 D6 D7
//PIN->RE0 RE1 RE2 RD0 RD1 RD2 RD3 RD4 RD5 RD6 RD7
 
void lcd_write(char data);
void lcd_init();
void lcd_newline();
void clr_lcd();
 
 
void main()
{
    float voltsCurrentValCurrentVal = 0.0, voltaPreviousVal = 0.0;
 
    delay_ms(10);
    output_bit(LCD_RW,0);
 
    delay_ms(100);
    setup_adc_ports(AN0);
    setup_adc(ADC_CLOCK_DIV_8);
    set_adc_channel(0);
 
    lcd_init();
    delay_us(20);
 
    while(1)
    {
        
        
        voltsCurrentVal = read_adc();
    
        if(voltsPreviousVal != voltsCurrentVal) {
            voltsCurrentVal = (voltsCurrentVal * 5.0) / 1023.0;
 
            clr_lcd();
            printf(lcd_write,"\fVoltage = %4.2f", voltsCurrentVal);
 
            if(voltsCurrentVal < 2.5)
            {
                output_bit(pin_b1,1);   //Green LED to indicate safety voltage
                output_bit(pin_b2,0);   //Green LED to indicate safety voltage
            }
            else
            {
                output_bit(pin_b2,1);   //Red LED to indicate vulnerable voltage
                output_bit(pin_b1,0);   //Green LED to indicate safety voltage
            }
        }
 
        delay_ms(1000);
 
        output_bit(LCD_RW,0);
 
    }   
}
 
 
 
void lcd_init()
{
    output_bit(LCD_RS,0);
    delay_ms(10);
    lcd_write(0x01);
    lcd_write(0x38);
    lcd_write(0x06);
    lcd_write(0x0f);
    cd_write(0x80);
    delay_ms(100);
    output_bit(LCD_RS,1);
}
 
void clr_lcd()
{
    output_bit(LCD_RS,0);
    delay_ms(10);
    lcd_write(0x01);
    output_bit(LCD_RS,1);
    delay_ms(1);
}
 
void lcd_newline()
{
    output_bit(LCD_RS,0);
    delay_ms(10);
    lcd_write(0xc0);
    output_bit(LCD_RS,1);
    delay_ms(1);
}
 
void lcd_write(char data)
{
    output_d(data);
    delay_ms(1);
    output_bit(LCD_EN,1);
    delay_ms(1);
    output_bit(LCD_EN,0);
    delay_ms(1);
}

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top