void displayFloat(int x, int y, float oldValue, float theValue) {
char toPrintOld[4];
char toPrint[4];
sprintf(toPrintOld, "%f", oldValue);
sprintf(toPrint, "%f", theValue);
toPrintOld[3] = '\0';
toPrint[3] = '\0'; // Limit shown digits to 3
Glcd_Write_Text(toPrintOld, x, y, 1);
Glcd_Write_Text(toPrint, x, y, 1);
}
void displayInt8(int x, int y, int oldValue, int theValue) {
char toPrintOld[4];
char toPrint[4];
sprintf(toPrintOld, "%u", oldValue);
sprintf(toPrint, "%u", theValue);
toPrintOld[3] = '\0';
toPrint[3] = '\0'; // Limit shown digits to 3
Glcd_Write_Text(toPrintOld, x, y, 1);
Glcd_Write_Text(toPrint, x, y, 1);
}
void displayInt16(int x, int y, int oldValue, int theValue) {
char toPrintOld[6];
char toPrint[6];
sprintf(toPrintOld, "%lu", oldValue);
sprintf(toPrint, "%lu", theValue);
toPrintOld[5] = '\0';
toPrint[5] = '\0'; // Limit shown digits to 5
Glcd_Write_Text(toPrintOld, x, y, 1);
Glcd_Write_Text(toPrint, x, y, 1);
}
int useThreshold = 0; // 0 = Off, 1 = Rising, 2 = Falling
int theThreshold = 127;
int timeType = 1; // 1 = us, 2 = ms
int timePeriod = 4; // us or ms per measurement (* 25 for each div)
int voltageRange = 1; // 1 = 0 - 5V, 2 = 0 - 2.5V, 3 = 0 - 1.25V
float voltageConst = 0.079365; // For displaying the scaled voltage
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";
void changeThreshold(int theUsage, int theValue) {
float tempFloat = 0.0;
tempFloat = (theThreshold>>2) * voltageConst;
if (theUsage == 0)
Glcd_Write_Text(strOff, 12, 24, 1);
else if (theUsage == 1) {
Glcd_Write_Text(strRising, 12, 24, 1);
displayFloat(12, 30, tempFloat, (theValue>>2) * voltageConst);
}
else if (theUsage == 2) {
Glcd_Write_Text(strFalling, 12, 24, 1);
displayFloat(12, 30, tempFloat, (theValue>>2) * voltageConst);
}
useThreshold = theUsage;
theThreshold = theValue;
Glcd_Write_Text(strThreshold, 0, 24, 1);
if (useThreshold == 0) Glcd_Write_Text(strOff, 12, 24, 1);
else if (useThreshold == 1) Glcd_Write_Text(strRising, 12, 24, 1);
else if (useThreshold == 2) Glcd_Write_Text(strFalling, 12, 24, 1);
}
void changeTimeDivision(int theType, int theValue) {
float tempFloat = 0.0, tempFloat2 = 0.0;
Glcd_Write_Text(strTime, 0, 36, 1);
if (theType == 1) {
tempFloat = timePeriod * 25;
tempFloat2 = theValue * 25;
displayFloat(12, 36, tempFloat/1000, tempFloat2/1000);
}
else if (theType == 2)
displayFloat(12, 36, timePeriod * 25, theValue * 25);
timeType = theType;
timePeriod = theValue;
if ((theType == 1) && (timePeriod < 16)) timePeriod = 16;
Glcd_Write_Text(strMs, 4, 42, 1);
}
void changeVoltageRange(int theType) {
Glcd_Write_Text(strRange, 0, 54, 1);
if (voltageRange == 1) Glcd_Write_Text(strR0to5, 8, 54, 1);
else if (voltageRange == 2) Glcd_Write_Text(strR0to25, 8, 54, 1);
else if (voltageRange == 3) Glcd_Write_Text(strR0to12, 8, 54, 1);
voltageRange = theType;
if (voltageRange == 1) voltageConst = 0.079365;
else if (voltageRange == 2) voltageConst = 0.039683;
else if (voltageRange == 3) voltageConst = 0.019841;
if (voltageRange == 1) Glcd_Write_Text(strR0to5, 8, 54, 1);
else if (voltageRange == 2) Glcd_Write_Text(strR0to25, 8, 54, 1);
else if (voltageRange == 3) Glcd_Write_Text(strR0to12, 8, 54, 1);
}
void main() {
int const numOfSamples = 100;
int HQadcReadings[numOfSamples];
int adcReadings[numOfSamples], adcReadingsOld[numOfSamples];
int i = 0;
int thres2 = 1;
int tempThres = 0, k = 0;
float avgV = 0.0, avgVOld = 0.0;
float maxV = 0.0, maxVOld = 0.0;
float minV = 0.0, minVOld = 0.0;
float ptopV = 0.0, ptopVOld = 0.0;
int theFreq = 0.0, theFreqOld = 0.0;
INTCON = 0; // disable all interrupts
ADCON1 = 0x82; // configure VDD as Vref, and analog channels
TRISA = 0xFF; // designate porta as input
Glcd_Init(&PORTC, 4,5,0,1,6,2, &PORTB);
Glcd_Fill(0x00); // Must initialize the LCD
Glcd_Line((128-numOfSamples),0,(128-numOfSamples),63,1);
// Draw static text
Glcd_Write_Text(strAverageV, 0, 0, 1);
Glcd_Write_Text(strVMaximum, 0, 6, 1);
Glcd_Write_Text(strVMinimum, 0, 12, 1);
Glcd_Write_Text(strVPtoP, 0, 18, 1);
Glcd_Write_Text(strHz, 20, 48, 1);
// Setup variable ranges
changeVoltageRange(1); // Set voltage range
changeTimeDivision(1, 200); // Set time divisions
changeThreshold(1, 127); // Set threshold level
delay_ms(10);
delay_ms(100);
while (1) {
// If using threshold, wait until it has been reached
if (voltageRange == 1) tempThres = (int) theThreshold << 2;
else if (voltageRange == 2) tempThres = (int) theThreshold << 1;
else if (voltageRange == 3) tempThres = (int) theThreshold;
if (useThreshold == 1) {
k = 0;
while ((ADC_read(2)>tempThres) && (k<65535)) (k++);
k = 0;
while ((ADC_read(2)<tempThres) && (k<65535)) (k++);
}
else if (useThreshold == 2) {
k = 0;
while ((ADC_read(2)<tempThres) && (k<65535)) (k++);
k = 0;
while ((ADC_read(2)>tempThres) && (k<65535)) (k++);
}
// Collect ADC readings
if (timeType == 1)
for (i=0; i<numOfSamples; i++) {
HQadcReadings = ADC_read(2);
//Delay_us(timePeriod - 16);
Delay_us(100);
}
else if (timeType == 2)
for (i=0; i<numOfSamples; i++) {
HQadcReadings = ADC_read(2);
//Delay_ms(timePeriod);
Delay_ms(100);
}
for (i=0; i<numOfSamples; i++) {
if (voltageRange == 1) adcReadings = 63-(HQadcReadings>>4);
else if (voltageRange == 2) adcReadings = 63-(HQadcReadings>>3);
else if (voltageRange == 3) adcReadings = 63-(HQadcReadings>>2);
}
// Draw ADC readings
for (i=1; i<numOfSamples; i++)
Glcd_Dot(i+(128-numOfSamples),adcReadingsOld,1);
for (i=1; i<numOfSamples; i++)
Glcd_Dot(i+(128-numOfSamples),adcReadings,1);
for (i=0; i<numOfSamples; i++)
adcReadingsOld[i] = adcReadings[i];
// Calculate and display frequency of signal using zero crossing
// displayint8(0, 54, thres2, 0);
if (useThreshold != 0) {
for (i=0; i<63; i+=3)
Glcd_Dot(thres2+(128-numOfSamples),i,0);
if (useThreshold == 1) {
thres2 = 1;
while ((adcReadings[thres2]<(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
thres2++;
while ((adcReadings[thres2]>(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
}
else if (useThreshold == 2) {
thres2 = 1;
while ((adcReadings[thres2]>(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
thres2++;
while ((adcReadings[thres2]<(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
}
// displayint8(0, 54, 0, thres2);
for (i=0; i<63; i+=3)
Glcd_Dot(thres2+(128-numOfSamples),i,1);
k = (int) thres2 * timePeriod;
if (timeType == 1) theFreq = (float) 1000/k * 1000;
if (timeType == 2) theFreq = (float) 1000/k;
displayInt16(0, 48, theFreqOld, theFreq);
theFreqOld = theFreq;
}
// Calculate and display Average V
avgV = 0;
for (i=0; i<numOfSamples; i++)
avgV = (float) avgV + adcReadings[i];
avgV = (float) (63-(avgV / numOfSamples)) * voltageConst;
displayFloat(12, 0, avgVOld, avgV);
avgVOld = avgV;
// Calculate and display Maximum V
maxV = 63;
for (i=0; i<numOfSamples; i++)
if (adcReadings[i]<maxV) maxV = adcReadings[i];
maxV = (float) (63-maxV) * voltageConst;
displayFloat(12, 6, maxVOld, maxV);
maxVOld = maxV;
// Calculate and display Minimum V
minV = 0;
for (i=0; i<numOfSamples; i++)
if (adcReadings[i]>minV) minV = adcReadings[i];
minV = (float) (63-minV) * voltageConst;
displayFloat(12, 12, minVOld, minV);
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_Dot(i,63-(theThreshold>>2),1);
for (i=0; i<63; i+=5) {
Glcd_Dot(53,i,1);
Glcd_Dot(78,i,1);
Glcd_Dot(103,i,1);
Glcd_Dot(127,i,1);
}
Delay_ms(100); // Reduces flicker by allowing pixels to be on
// much longer than off
}
}
I am trying to built a GLCD oscilloscope using PIC 18F2550 and above is the mikroC program for my pic18F2550. It was successfully compiled and HEX file was generated....When input signal from the frequency generator was fed into portA of pic 18f2550 nothing was display on the GLCD. All i got on my GLCD was a full black rectangle..I have double-checked the circuit connection and so the last resort was the problem to my program...SO, can any experts please troubleshoot and check for me is there anything missout or syntax error...Thank you first......
GLCD Scope does not have display....HELP!!!!!!!!!!!!!!!!!!!!
Post your requests and ideas on the future development of mikroC.
Author
Message
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects