Min egentliga fråga är om någon har någon erfarenhet av överhörning mellan kanaler när man adomvandlar? Brukar det ske ofta och är det något man måste ha i åtanke när man designar sina lösningar?
film: http://www.youtube.com/watch?v=Mgf9_i0EKSU
Kod: Markera allt
#include <pic.h>
void sjuseg(int siffra);
unsigned long tid = 0;
void main()
{
//variables that are needed for in the loops
int j,k,i;
char ental=0, tiotal=0, hundratal=0;
int temptid;
//set the apropiat I/O for the different ports.
TRISA = 0b00010000;
TRISB = 0b00000000;
TRISC = 0b11011000;
ANSELH =0b00000011;
ANSEL = 0b10000000;
WPUA4 = 0;
//init
//RA4 = 0;
//config TMR0 and intterupt.
OPTION = 0b01010001;
INTCON = 0b10100000;
//config ADC
ADCON1 = 0b00100000;
ADCON0 = 0b00001001;
//wait a short wile for ADC capacitor to charge.
for(j=0; j< 30000;j++);
j = 0;
while(1){
//turn off the timer.
T0CS = 1;
RC5 = 1;
j=0;
while(tid == 0)
{
//start a conversion for the first number.
CHS0 = 1;
CHS1 = 0;
CHS2 = 0;
CHS3 = 1;
GODONE = 1;
while(GODONE);
ental = ADRESH/26;
for(i=0;i<100;i++);
//do the next one.
CHS0 = 0;
CHS1 = 0;
CHS2 = 0;
CHS3 = 1;
GODONE = 1;
while(GODONE);
tiotal = ADRESH/26;
for(i=0;i<100;i++);
//do the next one.
CHS0 = 1;
CHS1 = 1;
CHS2 = 1;
CHS3 = 0;
GODONE = 1;
while(GODONE);
hundratal = ADRESH/26;
for(i=0;i<100;i++);
switch(j%3){
case 0:
sjuseg(ental);
RB5 = 0;
RB6 = 1;
RA5 = 1;
break;
case 1:
sjuseg(tiotal);
RB5 = 1;
RB6 = 0;
RA5 = 1;
break;
case 2:
sjuseg(hundratal);
RB5 = 1;
RB6 = 1;
RA5 = 0;
break;
};
j++;
if(RC4 == 1 && j>100)
tid = (ental + tiotal*10 + hundratal*100)*100;
if(RA4 == 1){
RC5 = 0;
while(RA4);
RC5 = 1;
}
}
//turn on the timer.
T0CS = 0;
//Turn on the relay
RC5 = 0;
j=0;
while(tid != 0){
//calulate current time.
temptid = tid/100;
ental = temptid%10;
tiotal = (temptid%100)/10;
hundratal = temptid/100;
switch(j%3){
case 0:
sjuseg(ental);
RB5 = 0;
RB6 = 1;
RA5 = 1;
break;
case 1:
sjuseg(tiotal);
RB5 = 1;
RB6 = 0;
RA5 = 1;
break;
case 2:
sjuseg(hundratal);
RB5 = 1;
RB6 = 1;
RA5 = 0;
break;
};
j++;
if(RC4 == 1 && j>200)
tid=0;
}
}
}
void interrupt tmr()
{
//intterput handling function.
if(tid != 0)
tid--;
TMR0 = 24;
T0IF = 0;
}
void sjuseg(int siffra)
{
switch(siffra)
{
case 0:
RA0 = 1;
RA1 = 1;
RA2 = 1;
RC0 = 1;
RC1 = 1;
RC2 = 1;
RB4 = 0;
break;
case 1:
RA0 = 0;
RA1 = 1;
RA2 = 1;
RC0 = 0;
RC1 = 0;
RC2 = 0;
RB4 = 0;
break;
case 2:
RA0 = 1;
RA1 = 1;
RA2 = 0;
RC0 = 1;
RC1 = 1;
RC2 = 0;
RB4 = 1;
break;
case 3:
RA0 = 1;
RA1 = 1;
RA2 = 1;
RC0 = 1;
RC1 = 0;
RC2 = 0;
RB4 = 1;
break;
case 4:
RA0 = 0;
RA1 = 1;
RA2 = 1;
RC0 = 0;
RC1 = 0;
RC2 = 1;
RB4 = 1;
break;
case 5:
RA0 = 1;
RA1 = 0;
RA2 = 1;
RC0 = 1;
RC1 = 0;
RC2 = 1;
RB4 = 1;
break;
case 6:
RA0 = 1;
RA1 = 0;
RA2 = 1;
RC0 = 1;
RC1 = 1;
RC2 = 1;
RB4 = 1;
break;
case 7:
RA0 = 1;
RA1 = 1;
RA2 = 1;
RC0 = 0;
RC1 = 0;
RC2 = 0;
RB4 = 0;
break;
case 8:
RA0 = 1;
RA1 = 1;
RA2 = 1;
RC0 = 1;
RC1 = 1;
RC2 = 1;
RB4 = 1;
break;
case 9:
RA0 = 1;
RA1 = 1;
RA2 = 1;
RC0 = 0;
RC1 = 0;
RC2 = 1;
RB4 = 1;
break;
};
}