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.

Digital voltmeter with PIC16F876A

Status
Not open for further replies.

john120

Banned
Full Member level 5
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Visit site
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: 80

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]]);

 

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);

}
}
 

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; ?
 

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);
 
}
}

 

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 ?
 

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: 86

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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top