manoj soorya
Member
this is the PCB I already designed to my needs..
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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;
I don't know where you got that code from
If the volt meter does AC then a switch on RA3 could swap between the two!!
Sagor has already replied with the answer!! Change the TRIS registers to suit!!
/* 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
Here is the code... It runs on those connections ripped from your PCB picture..
/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...
I made that code work for your PCB.... I don't know why I bothered....