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.

Digital voltmeter with PIC16F876A

Status
Not open for further replies.

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
Hello there,can some body help me to know where the error is I am design a 0-30V digital voltmeter but I am always getting 0V on the seven segment display.

Here are the code and the proteus circuit.

PHP:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA

byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;


void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  

   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;

       delay_ms(1);

      volt2=volt1;                
      output_low(PIN_b2);
      display[0]=volt1/10;      
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);

       output_low(PIN_b4);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);

 	  output_low(PIN_b5);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
	  output_high(PIN_b4);
      delay_ms(10);

}
}
Thanks.
 

Attachments

  • circuit.zip
    17.9 KB · Views: 27

Venkadesh_M

Advanced Member level 4
Joined
Jun 26, 2013
Messages
1,375
Helped
258
Reputation
516
Reaction score
254
Trophy points
83
Location
Coimbatore, India
Activity points
6,738
you put

Code C - [expand]
1
volt2 = volt1


instead of

Code C - [expand]
1
volt1 = volt2


and also

Code C - [expand]
1
output_c(digit[display[volt1]]);

 

mathespbe

Full Member level 3
Joined
Jul 10, 2013
Messages
186
Helped
45
Reputation
90
Reaction score
44
Trophy points
28
Location
India, Tamilnadu, Coimbatore
Activity points
866
Hello there,can some body help me to know where the error is I am design a 0-30V digital voltmeter but I am always getting 0V on the seven segment display.

Here are the code and the proteus circuit.

PHP:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA

byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;


void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  

   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;

       delay_ms(1);

      volt2=volt1;                
      output_low(PIN_b2);
      display[0]=(volt1/10) ;      
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);

       output_low(PIN_b4);
      display[1]=(volt1%10) ;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);

 	  output_low(PIN_b5);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
	  output_high(PIN_b4);
      delay_ms(10);

}
}
Thanks.

try this code...

Code:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA

byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;


void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  

   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;

       delay_ms(1);

      volt1=volt2;                
      output_low(PIN_b2);
      display[0]=(volt1/10) + 30;      
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);

       output_low(PIN_b4);
      display[1]=(volt1%10) + 30;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);

 	  output_low(PIN_b5);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
	  output_high(PIN_b4);
      delay_ms(10);

}
}
 

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
try this code...

Code:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA

byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;


void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  

   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;

       delay_ms(1);

      volt1=volt2;                
      output_low(PIN_b2);
      display[0]=(volt1/10) + 30;      
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);

       output_low(PIN_b4);
      display[1]=(volt1%10) + 30;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);

 	  output_low(PIN_b5);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
	  output_high(PIN_b4);
      delay_ms(10);

}
}


Hello,why may I use that +30 in this expression:display[1]=(volt1%10) + 30; ?
 

Venkadesh_M

Advanced Member level 4
Joined
Jun 26, 2013
Messages
1,375
Helped
258
Reputation
516
Reaction score
254
Trophy points
83
Location
Coimbatore, India
Activity points
6,738
look at the changes

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
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA
 
byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;
 
 
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  
 
   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;
 
       delay_ms(1);
 
      volt1=volt2               
      output_low(PIN_b2);
      display[0]=(volt1%10) ;   
      volt1 = volt1 / 10;   
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);
 
       output_low(PIN_b4);
      display[1]=(volt1%10) ;      
      volt1 = volt1 / 10;   
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);
 
       output_low(PIN_b5);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
      output_high(PIN_b4);
      delay_ms(10);
 
}
}

 

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
He said that for LCD, here is no lcd just 7 segment display.. try my program too.....

The codes are not running.
All of them are not running with 7segment display.
 

mathespbe

Full Member level 3
Joined
Jul 10, 2013
Messages
186
Helped
45
Reputation
90
Reaction score
44
Trophy points
28
Location
India, Tamilnadu, Coimbatore
Activity points
866
Frst check the ADC values.. whether it ADC is configured properly or not... Just debug it on proteus and chech the variable values properly...
 

sahu

Advanced Member level 2
Joined
Oct 9, 2009
Messages
516
Helped
67
Reputation
128
Reaction score
62
Trophy points
1,308
Location
Uttar pradesh (INDIA)
Activity points
3,875
Hello there,can some body help me to know where the error is I am design a 0-30V digital voltmeter but I am always getting 0V on the seven segment display.

Here are the code and the proteus circuit.

PHP:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA

byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;


void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  

   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;

       delay_ms(1);

      volt2=volt1;                
      output_low(PIN_b2);
      display[0]=volt1/10;      
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);

       output_low(PIN_b4);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);

 	  output_low(PIN_b5);
      display[1]=volt1%10;      
      output_c(digit[display[1]]);
      output_high(PIN_b2);
	  output_high(PIN_b4);
      delay_ms(10);

}
}
Thanks.
Can u post the screenshot image of your schematic asproteus circuit ?
 

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
Can u post the screenshot image of your schematic asproteus circuit ?

see the schematic here attached and the codes in ccs c
PHP:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA
 
byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;
 
 
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  
Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
 
   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;
 
       delay_ms(1);
 
      volt1=volt2;              
      output_low(PIN_b2);
      display[0]=(volt1%10) ;   
      volt1 = volt1 / 10;   
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);
 
       output_low(PIN_b4);
      display[1]=(volt1%10) ;      
      volt1 = volt1 / 10;   
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);
 
       output_low(PIN_b5);
      display[2]=volt1%100;      
      output_c(digit[display[2]]);
      output_high(PIN_b2);
      output_high(PIN_b4);
      delay_ms(10);
 
}
}
 

Attachments

  • Digital voltmeter.zip
    11.4 KB · Views: 30

sahu

Advanced Member level 2
Joined
Oct 9, 2009
Messages
516
Helped
67
Reputation
128
Reaction score
62
Trophy points
1,308
Location
Uttar pradesh (INDIA)
Activity points
3,875
see the schematic here attached and the codes in ccs c
PHP:
#include "16f876a.h"
#DEVICE ADC=10
#fuses XT,NOWDT,NOLVP,NODEBUG,NOCPD
#use delay(clock=4M)
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#define PORTB
#DEFINE PORTC
#define PORTA
 
byte const digit[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 char display[3];
 unsigned int volt1,volt2;
int value;
 
 
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);  
Setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(AN0);
   set_adc_channel(0);
   setup_vref(FALSE);
 
   while(TRUE){
   //setup_comparator(NC_NC_NC_NC);
   
      delay_us(10);    
        read_adc(ADC_START_ONLY);
      delay_us(100);
      value=read_adc();
      volt2=(value*500)/1023;
 
       delay_ms(1);
 
      volt1=volt2;              
      output_low(PIN_b2);
      display[0]=(volt1%10) ;   
      volt1 = volt1 / 10;   
      output_c(digit[display[0]]);
      output_high(PIN_b4);
    output_high(PIN_b5);
      delay_ms(10);
 
       output_low(PIN_b4);
      display[1]=(volt1%10) ;      
      volt1 = volt1 / 10;   
      output_c(digit[display[1]]);
      output_high(PIN_b2);
     output_high(PIN_b5);
      delay_ms(10);
 
       output_low(PIN_b5);
      display[2]=volt1%100;      
      output_c(digit[display[2]]);
      output_high(PIN_b2);
      output_high(PIN_b4);
      delay_ms(10);
 
}
}

dear i say screenshot image of your schematic.
becoz i have not proteus.so i can't open it
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top