/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...