Documente Academic
Documente Profesional
Documente Cultură
h>
#device ADC=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#build(reset=0x1, interrupt=0x8)
#ORG 0x0F00,0x0FFF {}
int8 timeType = 1;
int8 timePeriod = 4;
each div)
int8 voltageRange = 1;
1.25V
float voltageConst = 0.079365;
char strAverageV[] = "Av";
char strVMaximum[] = "Mx";
char strVMinimum[] = "Mn";
char strVPtoP[] =
"PP";
char strThreshold[] ="Th";
char strOff[] =
"Off";
char strRising[] =
"Rise";
char strFalling[] = "Fall";
char strTime[] =
"Tm";
char strMs[] =
"ms/div";
char strHz[] =
"Hz";
char strRange[] =
"R";
char strR0to5[] =
"0-5";
char strR0to25[] =
"0-2.5";
char strR0to12[] =
"0-1.2";
// 1 = us, 2 = ms
// us or ms per measurement (* 25 for
// 1 = 0 - 5V, 2 = 0 - 2.5V, 3 = 0 // For displaying the scaled voltage
Disable
Disable
Disable
Disable
Disable
Timer 1
Timer 2
Timer 3
CCP1
CCP2
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
glcd_init(ON);
// Must initialize the LCD
glcd_line((128-numOfSamples),0,(128-numOfSamples),63,ON);
// Draw static text
set_adc_channel(0);
delay_ms(10);
delay_ms(100);
while (TRUE) {
// If using threshold, wait until it has been reached
if (voltageRange == 1) tempThres = (int16) theThreshold << 2;
else if (voltageRange == 2) tempThres = (int16) theThreshold << 1;
else if (voltageRange == 3) tempThres = (int16) theThreshold;
if (useThreshold == 1) {
k = 0;
while ((READ_ADC()>tempThres) && (k<65535)) (k++);
k = 0;
while ((READ_ADC()<tempThres) && (k<65535)) (k++);
}
else if (useThreshold == 2) {
k = 0;
while ((READ_ADC()<tempThres) && (k<65535)) (k++);
k = 0;
while ((READ_ADC()>tempThres) && (k<65535)) (k++);
}
// Collect ADC readings
if (timeType == 1)
for (i=0; i<numOfSamples; i++) {
HQadcReadings[i] = read_adc();
delay_us(timePeriod-16);
}
else if (timeType == 2)
for (i=0; i<numOfSamples; i++) {
HQadcReadings[i] = read_adc();
delay_ms(timePeriod);
}
for (i=0; i<numOfSamples; i++) {
if (voltageRange == 1) adcReadings[i] = 63(HQadcReadings[i]>>4);
else if (voltageRange == 2) adcReadings[i] = 63(HQadcReadings[i]>>3);
else if (voltageRange == 3) adcReadings[i] = 63(HQadcReadings[i]>>2);
}
// Draw ADC readings
for (i=1; i<numOfSamples; i++)
glcd_pixel(i+(128-numOfSamples),adcReadingsOld[i],OFF);
for (i=1; i<numOfSamples; i++)
glcd_pixel(i+(128-numOfSamples),adcReadings[i],ON);
minVOld = minV;
// Calculate and display Peak-to-peak V
ptopV = maxV - minV;
displayFloat(12, 18, ptopVOld, ptopV);
ptopVOld = ptopV;
// Display graph lines
if (useThreshold != 0)
for (i=29; i<127; i+=3)
glcd_pixel(i,63-(theThreshold>>2),ON);
for (i=0; i<63; i+=5) {
glcd_pixel(53,i,ON);
glcd_pixel(78,i,ON);
glcd_pixel(103,i,ON);
glcd_pixel(127,i,ON);
}
delay_ms(100);
}
}