Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F676 voltmeter Pinout

Status
Not open for further replies.
this is the PCB I already designed to my needs..:nailbiting:



DJYYYiT.png
 
I don't know where you got that code from, but its rubbish...
C:
  for (i=0;i<200;i++)
   {
   __delay_us(1);
   result=Adc_Read(0);
   if (result > resmax) resmax=result;
   if (result < resmin) resmin=result; }
  result=resmax-resmin;
This will yield 0 if the voltage is stable...
Assume 8 bit reading... 200 x (mid voltage, say 2,5v) we get 25400.. So max and min will be the same (ish)..

result = resmax - resmin; or result = 25400-25400... Oh a big fat 0.. so unless you ground your probes before every 200 samples you get zilch..

I compiled it with XC8 and the code works fine...

Change the faulty line to:-

result = resmin + (resmax - resmin) / 2;
 
I don't know where you got that code from

I got this circuit from a Russian site... and eassy designing of PCB, I interchange some connection of the IC to the display.

I already made 3 PCB for my own purpose... But it not work. Its my fault.. I need to check the edited schematic first, I know.

I know, You can help me..

Sorry for my poor english...

I hop the help from you and sorry for the rubbish code...

Regarding Manoj Soorya
 
I am also trying again and again to change the setting.. but no change in the display... what I do? or I leave from this work?

Its my humble request...
 
I converted this to XC8... Using the PCB you supplied
Here's the connections:- No resistors on the drawing as they are not needed for simulation, and the display is a 4 way but ho-hum..
upload_2017-8-22_17-31-52.png


Here is the code... It runs on those connections ripped from your PCB picture..
C:
/*  PIC16F676, , 4 MHz
   mikroC PRO for PIC  */
#include<xc.h>
#define _XTAL_FREQ 4000000
#define a 1   //
#define b 2   //
#define c 4   //
#define d 8   //
#define e 16  //
#define f 32  //
#define g 64  //
#define DP 128//
unsigned int i = 1; //
unsigned char Dig[11];
static char Segment[3] = {0x7f,0x7f,0x7f};
static unsigned char ColCount = 0;
unsigned result, resmax, resmin;
unsigned char R_A, R_C;
void io_init()
 {
 TRISA = 0b00001001;
 PORTA = 0b00000100;
 TRISC = 0b00000000;
 PORTC = 0b00001010;
 ADCON0 = 0b00000001;
 ADCON1 = 0b10000101;
 CMCON = 7;}
void Dig_init()
 {
 Dig[0]=0xff-0x3F;
 Dig[1]=0xff-0x06;
 Dig[2]=0xff-0x5B;
 Dig[3]=0xff-0x4F;
 Dig[4]=0xff-0x66;
 Dig[5]=0xff-0x6D;
 Dig[6]=0xff-0x7D;
 Dig[7]=0xff-0x07;
 Dig[8]=0xff-0x7F;
 Dig[9]=0xff-0x6F;
 Dig[10]=0xff-0x00;
 }
void Display()
 {
 R_A = 0;
 R_C = 0;
 __delay_us(2);
 if (ColCount >= 3) ColCount = 0;
 switch (ColCount)
  {
  case 0 : R_A += 4; break;
  case 1 : R_A += 2; break;
  case 2 : R_A += 32;
  }
 if( Segment[ColCount] & 0x01) R_C+= 4; //a
 if( Segment[ColCount] & 0x02) R_C+= 8; //b
 if( Segment[ColCount] & 0x04) R_C+= 16; //c
 if( Segment[ColCount] & 0x08) R_C+= 32; //d
 if( Segment[ColCount] & 0x10) R_A+= 16; //e
 if( Segment[ColCount] & 0x20) R_C+= 2; //f
 if( Segment[ColCount] & 0x40) R_C+= 1; //g               manoj
 PORTA = R_A; PORTC = R_C;
 ColCount++;
 }
void HTO7S(unsigned long int Num)
 {
 Segment[0] = Dig[Num / 100];
 if (Segment[0] == Dig[0]) Segment[0] = Dig[10];
  Segment[1] = Dig[Num % 100 / 10];
 if ((Segment[1] == Dig[0]) && (Segment[0] == Dig[10])) Segment[1] = Dig[10];
  Segment[2] = Dig[Num % 10];
 }
void Init_Timer1 () {
 GIE = 1;
 PEIE = 1;
 T1CON = 0x01;
 TMR1H = 0x00;
 TMR1L = 0x00;
 // T1CON.T1CKPS0 = 1;
 // T1CON.T1CKPS1 = 1;
 TMR1IE = 1;
 }
void interrupt ISR()
 {
 if(TMR1IF)
  {
  TMR1H = 0xF7;
  TMR1IF = 0;
  Display();
  }
 }
int Adc_Read(char channel)
 {
 GO = 1;
 __delay_us(200);
 while(GO);
 return ADRESH ;
 }
void main()
 {
 io_init();
 Dig_init();
 Init_Timer1();
 do
  {
  result=0;
  resmax=0;
  resmin=65535;
  for (i=0;i<200;i++)
   {
   __delay_us(1);
   result=Adc_Read(0);
   if (result > resmax) resmax=result;
   if (result < resmin) resmin=result; }
  result=resmin + (resmax-resmin) /2;
  HTO7S(result / 4);
  __delay_ms(500);
  }while (1);
}

**** REMEMBER *** I changed this for DC measurement... Your original is for AC
 
Hello Ian Rogers



Here is the code... It runs on those connections ripped from your PCB picture..

Can you please make the code working I already Given? Its most suitable for the PCB, I made..

I will upload the code and schematic for the same again...

Hope your help again...


Code:
/PIC16F676,  4 MHz
   mikroC PRO for PIC  */


#define a 1   // 
#define b 2   //
#define c 4   //
#define d 8   //
#define e 16  //
#define f 32  //
#define g 64  //
#define DP 128//

unsigned int i = 1; //
unsigned char Dig[11]; //
//
//

static char Segment[3] = {0x7f,0x7f,0x7f};
static unsigned char ColCount = 0; //

unsigned result, resmax, resmin;           //
unsigned char RA, RC; //

void io_init()
   {TRISA = 0b00001001;          //
    PORTA = 0b00000100;
    TRISC = 0b00000000;
    PORTC = 0b00001010;
    ADCON0 = 0b00000001;  //
    ADCON1 = 0b10000101;  // 1110 D D D D D D D A VDD VSS 1/0
    CMCON = 7;}           //

void Dig_init()
   {Dig[0]  = 255-(a+b+c+d+e+f);   //
    Dig[1]  = 255-(b+c);           //
    Dig[2]  = 255-(a+b+g+e+d);     //
    Dig[3]  = 255-(a+b+g+c+d);     //
    Dig[4]  = 255-(f+g+b+c);       ///
    Dig[5]  = 255-(a+f+g+c+d);     //
    Dig[6]  = 255-(a+f+g+c+d+e);   //
    Dig[7]  = 255-(a+b+c);         // Dig[7]  = 255-(a+b+c);
    Dig[8]  = 255-(a+b+c+d+e+f+g);
    Dig[9]  = 255-(a+b+c+d+f+g);
    Dig[10] = 255-0;}

void Display() {
    RA = 0b00000000;    //  RA2, RC1, RC3 = 0
    RC = 0b00000000;    // Âñå ñòîëáöû K ðàâíû 1 Âñå ñåãìåíòû (a - h) ðàâíû 0
    delay_Cyc(2);
    if (ColCount >= 3) ColCount = 0; //

    switch (ColCount) {
        case 0 : RA.f2 = 1; break; // Âûáîð èíäèêàòîðà K1
        case 1 : RC.f1 = 1; break; // Âûáîð èíäèêàòîðà K2
        case 2 : RC.f3 = 1; }      // Âûáîð èíäèêàòîðà K3

    RC.f0 = Segment[ColCount].f0;  //a
    RC.f2 = Segment[ColCount].f1;  //b
    RA.f4 = Segment[ColCount].f2;  //c
    RA.f1 = Segment[ColCount].f3;  //d
    RA.f5 = Segment[ColCount].f4;  //e
    RC.f4 = Segment[ColCount].f5;  //f
    RC.f5 = Segment[ColCount].f6;  //g

    PORTA = RA; PORTC = RC;
    ColCount++; }

void HTO7S(unsigned long int Num)  {  // Ïðåîáðàçîâàíèå â 7-è ñåãìåíòíûé êîä
    Segment[0] = Dig[Num / 100];
    if (Segment[0] == Dig[0]) Segment[0] = Dig[10];

    Segment[1] = Dig[Num % 100 / 10];
    if ((Segment[1] == Dig[0]) && (Segment[0] == Dig[10])) Segment[1] = Dig[10];

    Segment[2] = Dig[Num % 10];}

void Init_Timer1 () { //Èñïîëüçóåòñÿ ìîäóëü Timer1
    INTCON.GIE = 1;
    INTCON.PEIE = 1;
    T1CON = 0x01;
    TMR1H = 0x00;
    TMR1L = 0x00;
    // T1CON.T1CKPS0 = 1;  // Äåëèòåëü íà 2    Äëÿ Proteus
    // T1CON.T1CKPS1 = 1;  // Äåëèòåëü íà 4    Äëÿ Proteus
    PIE1.TMR1IE = 1;}    // Ðàçðåøåíèå ïðåðûâàíèÿ ïî ïåðåïîëíåíèþ TMR1

void interrupt () {
    if (PIR1.TMR1IF)    // Îáðàáîò÷èê ïðåðûâàíèÿ ïðè ïåðåïîëíåíèè TMR1
        {TMR1H = 0xF7;   // Ïåðèîä 6,2 ìñåê
        PIR1.TMR1IF = 0;
        Display();}}

void main() {   // Ïðÿìîå èçìåðåíèå ïåðåìåííîãî íàïðÿæåíèÿ
    io_init();
    Dig_init();
    Init_Timer1();
    do {result=0;
        resmax=0;
        resmin=65535;
        for (i=0;i<200;i++) {
            delay_us(1);
            result=Adc_Read(0);
            if (result > resmax) resmax=result;
            if (result < resmin) resmin=result; }
        result=resmax-resmin;
        HTO7S(result / 4); // Äî 255 âîëüò
        delay_ms(500);}
    while (1);  // Áåñêîíå÷íûé öèêë
}

[CODE]

I delete some unreadable cahractor, thats in another language...
 

Attachments

  • Schematic.PDF
    124.7 KB · Views: 395
Oh Yeah!! Why don't I go all out and install MikroE for pic just to get you going!!! Do you not think I would have done that rather than spend over 2 hours converting to a better compiler just for someone else in another corner of the world!!!

Tell you what!! Why don't I reprint your PCB's for free!!!

I made that code work for your PCB.... I don't know why I bothered....
 
Its okey Ian Rogers...

Please be cool...


Its okey.....

I can made the PCB for your code...

Thank you so much.... I really appriciate your hardwork for me...


Thanks again...


I made that code work for your PCB.... I don't know why I bothered....

Thats only a true Admin can done for his friends..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top