• 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.
Hi all...

I have a Voltmeter with PIC16F676...with source code too... its working good. I need to change the PINOUT of the IC to the display. This is a part of the original code.

Code:
void io_init()
   {TRISA = 0b00001001;          // Ïîðò RA0  - âõîä
    PORTA = 0b00000100;
    TRISC = 0b00000000;
    PORTC = 0b00001010;
    ADCON0 = 0b00000001;  // Êîíôèãóðèðóåì AN0 êàê àíàëîãîâûé
    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);     // 255. Åñëè ñ îáùèì êàòîäîì, òî
    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; // åñëè ñ÷åò÷èê ñòîëáöîâ >= 3 îáíóëÿåì åãî

    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++; }
and I changed this like...

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

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

compilation is okey.. but the second code doesnot work ....... any help would be appriciated...

Thank you
 
Last edited by a moderator:

sagor1

Active Member
You are setting RA.f4 twice, once in the case select, and then possibly in the part where you set "segment"
 
You are setting RA.f4 twice, once in the case select, and then possibly in the part where you set "segment"
Thanks for remind me about RA.f4...

This is the complete code...



Code:
/* Îïèñàíèå: Âîëüòìåòð äëÿ èçìåðåíèÿ íàïðÿæåíèÿ
   ñåòè ïåðåìåííîãî òîêà íà 3õ7ñåã èíäèêàòîðå
 * Êîíôèãóðàöèÿ: 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  // ÷èñëî 255 ìèíóñ ñóììó ñîîòâåòñòâóþùèõ ñåãìåíòàì ìàêðîñîâ.
#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; // Ïðåäâàðèòåëüíûå çíà÷åíèÿ PORTA è PORTC

void io_init()
   {TRISA = 0b00001001;          // Ïîðò RA0  - âõîä
    PORTA = 0b00000100;
    TRISC = 0b00000000;
    PORTC = 0b00001010;
    ADCON0 = 0b00000001;  // Êîíôèãóðèðóåì AN0 êàê àíàëîãîâûé
    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);     // 255. Åñëè ñ îáùèì êàòîäîì, òî
    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; // åñëè ñ÷åò÷èê ñòîëáöîâ >= 3 îáíóëÿåì åãî

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

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

    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 END]


Regarding
 

sagor1

Active Member
Re-check the initial settings (values) for PortA and PortC. The program initially set PortA = 00000100 and PortC to 00001010. Since you are changing pin definitions, do you not have to change the initial values as well? Just a thought....
I'm not good with C at all, so that is about as far as I can go...
 

Superdat

Member
You might get a better response if this was posted in a "C" forum, this is Oshonsoft Basic.
I know some Oshonsoft contributers understand C, but as I said a "C" forum might get a better level of help.
I'm just strating to learn C so I'm afraid I'm of no help
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Many Thanks Admin....

I think I already post in the C forum..... :nailbiting:
No! You posted in the depository... This is for code that has been written to help others... I deleted it..
 
I try much time with datasheet and pinout of 16F676... I do not dunderstand what is " TRSIA, ADCON and CMCON in my code.. and how to set corresponding to my needs.... really tired... But whenever I change in source, the display will change.. :)

Thank you so much Ian Roger
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top