CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help with GLCD.C modification

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alarassi



Joined: 28 Mar 2010
Posts: 8
Location: Malaysia

View user's profile Send private message

help with GLCD.C modification
PostPosted: Sun Mar 28, 2010 8:24 am     Reply with quote

hello guys
I'm new here and really need your help!

I'm developing a GLCD oscilloscope project that's been found online (http://www.semifluid.com/?p=15)

I have finished the hardware part and made all the connections and also tried it with a ready given hex file by the designer and the it worked nicely.

But when I tried to test the project by making some modifications to the code itself, I wasn't able to get the correct output! The code is compiled successfully but the displayed output is wrong! In other words it worked with the given hex file but not by generating the hex file from the code!!

The designer mentioned something about modifying the GLCD.C driver and he showed the steps to do it but although I followed the steps I got wrong output!

Here is the GLCD.C modification steps stated by the designer!
Code:

///////////////////////////////////////////////////////////////////////
//                     GLCD - modified.C
//
//  How to use: 1. Create a new file in your CCS C library folder
//              titled 'GLCD - modified.C'
//              2. Copy all of the code from your 'GLCD.C' file to the
//              new 'GLCD - modified.C' file.
//              3. Paste the following code into the appropriate places
//              4. Replace all "output_D" with "output_B"
//              5. Replace all "input_D" with "input_B"
//
//  Why all this work?  The GLCD.C file is copyrighted Custom Computer
//  Services, so I cannot distribute the library to other individuals
//  unless they are licensed users of the CCS C compiler.  Sorry!
//
//  Version 1.1 08/21/2006
//              Steven Cholewiak (www.semifluid.com) modified the
//              code for operation with a PIC18F2550 by changing
//              control lines and changing the data port to Port B.
//              He also added a 3x5 font, which was based upon the
//              font format from http://instruct1.cit.cornell.edu/
//              courses/ee476/video/Video32v2.c and modified to
//              include characters defined from http://mckoss.com/
//              jscript/tinyalice.htm
///////////////////////////////////////////////////////////////////////


//================================
// Paste in the top of your 'GLCD - modified.C' file!
//================================
#define GLCD_DI  PIN_C0   // Data or Instruction input
#define GLCD_RW  PIN_C1   // Read/Write
#define GLCD_E   PIN_C2   // Enable
#define GLCD_CS1 PIN_A3   // Chip Selection 1
#define GLCD_CS2 PIN_A4   // Chip Selection 2
#define GLCD_RST PIN_A5   // Reset

//================================
// Paste above "const int8 TEXT[51][5]"
//================================
//3x5 Font packed two per definition
//Original format from http://instruct1.cit.cornell.edu/courses/ee476/video/Video32v2.c
// - Modified by Steven Cholewiak (www.semifluid.com)
//    - 08/08/06 - Included punctuation characters
const int8 TEXT35[95][5]={
   0b00000000,   0b00000000,   0b00000000,   0b00000000,   0b00000000, //SPACE
   0b01000100,   0b01000100,   0b01000100,   0b00000000,   0b01000100, //!
   0b10101010,   0b10101010,   0b00000000,   0b00000000,   0b00000000, //"
   0b10101010,   0b11101110,   0b10101010,   0b11101110,   0b10101010, //#
   0b01100110,   0b11001100,   0b11001100,   0b01100110,   0b11101110, //$
   0b10101010,   0b00100010,   0b01000100,   0b10001000,   0b10101010, //%
   0b01000100,   0b10101010,   0b01000100,   0b10101010,   0b01100110, //&
   0b01000100,   0b01000100,   0b00000000,   0b00000000,   0b00000000, //'
   0b01000100,   0b10001000,   0b10001000,   0b10001000,   0b01000100, //(
   0b01000100,   0b00100010,   0b00100010,   0b00100010,   0b01000100, //)
   0b00000000,   0b10101010,   0b01000100,   0b10101010,   0b00000000, //*
   0b00000000,   0b01000100,   0b11101110,   0b01000100,   0b00000000, //+
   0b00000000,   0b00000000,   0b00000000,   0b01000100,   0b10001000, //,
   0b00000000,   0b00000000,   0b11101110,   0b00000000,   0b00000000, //-
   0b00000000,   0b00000000,   0b00000000,   0b00000000,   0b01000100, //.
   0b00100010,   0b00100010,   0b01000100,   0b10001000,   0b10001000, ///
   0b11101110,   0b10101010,   0b10101010,   0b10101010,   0b11101110, //0
   0b01000100,   0b11001100,   0b01000100,   0b01000100,   0b11101110, //1
   0b11101110,   0b00100010,   0b11101110,   0b10001000,   0b11101110, //2
   0b11101110,   0b00100010,   0b11101110,   0b00100010,   0b11101110, //3
   0b10101010,   0b10101010,   0b11101110,   0b00100010,   0b00100010, //4
   0b11101110,   0b10001000,   0b11101110,   0b00100010,   0b11101110, //5
   0b11001100,   0b10001000,   0b11101110,   0b10101010,   0b11101110, //6
   0b11101110,   0b00100010,   0b01000100,   0b10001000,   0b10001000, //7
   0b11101110,   0b10101010,   0b11101110,   0b10101010,   0b11101110, //8
   0b11101110,   0b10101010,   0b11101110,   0b00100010,   0b01100110, //9
   0b00000000,   0b01000100,   0b00000000,   0b01000100,   0b00000000, //:
   0b00000000,   0b01000100,   0b00000000,   0b01000100,   0b10001000, //;
   0b00100010,   0b01000100,   0b10001000,   0b01000100,   0b00100010, //<
   0b00000000,   0b11101110,   0b00000000,   0b11101110,   0b00000000, //=
   0b10001000,   0b01000100,   0b00100010,   0b01000100,   0b10001000, //>
   0b11001100,   0b00100010,   0b01100110,   0b00000000,   0b01000100, //?
   0b01000100,   0b10101010,   0b11101110,   0b10001000,   0b01100110, //@
   0b11101110,   0b10101010,   0b11101110,   0b10101010,   0b10101010, //A
   0b11001100,   0b10101010,   0b11101110,   0b10101010,   0b11001100, //B
   0b11101110,   0b10001000,   0b10001000,   0b10001000,   0b11101110, //C
   0b11001100,   0b10101010,   0b10101010,   0b10101010,   0b11001100, //D
   0b11101110,   0b10001000,   0b11101110,   0b10001000,   0b11101110, //E
   0b11101110,   0b10001000,   0b11101110,   0b10001000,   0b10001000, //F
   0b11101110,   0b10001000,   0b10001000,   0b10101010,   0b11101110, //G
   0b10101010,   0b10101010,   0b11101110,   0b10101010,   0b10101010, //H
   0b11101110,   0b01000100,   0b01000100,   0b01000100,   0b11101110, //I
   0b00100010,   0b00100010,   0b00100010,   0b10101010,   0b11101110, //J
   0b10001000,   0b10101010,   0b11001100,   0b11001100,   0b10101010, //K
   0b10001000,   0b10001000,   0b10001000,   0b10001000,   0b11101110, //L
   0b10101010,   0b11101110,   0b11101110,   0b10101010,   0b10101010, //M
   0b00000000,   0b11001100,   0b10101010,   0b10101010,   0b10101010, //N
   0b01000100,   0b10101010,   0b10101010,   0b10101010,   0b01000100, //O
   0b11101110,   0b10101010,   0b11101110,   0b10001000,   0b10001000, //P
   0b01000100,   0b10101010,   0b10101010,   0b11101110,   0b01100110, //Q
   0b11101110,   0b10101010,   0b11001100,   0b11101110,   0b10101010, //R
   0b11101110,   0b10001000,   0b11101110,   0b00100010,   0b11101110, //S
   0b11101110,   0b01000100,   0b01000100,   0b01000100,   0b01000100, //T
   0b10101010,   0b10101010,   0b10101010,   0b10101010,   0b11101110, //U
   0b10101010,   0b10101010,   0b10101010,   0b10101010,   0b01000100, //V
   0b10101010,   0b10101010,   0b11101110,   0b11101110,   0b10101010, //W
   0b00000000,   0b10101010,   0b01000100,   0b01000100,   0b10101010, //X
   0b10101010,   0b10101010,   0b01000100,   0b01000100,   0b01000100, //Y
   0b11101110,   0b00100010,   0b01000100,   0b10001000,   0b11101110, //Z
   0b11101110,   0b10001000,   0b10001000,   0b10001000,   0b11101110, //[
   0b10001000,   0b10001000,   0b01000100,   0b00100010,   0b00100010, //\
   0b11101110,   0b00100010,   0b00100010,   0b00100010,   0b11101110, //]
   0b01000100,   0b10101010,   0b00000000,   0b00000000,   0b00000000, //^
   0b00000000,   0b00000000,   0b00000000,   0b00000000,   0b11101110, //_
   0b10001000,   0b01000100,   0b00000000,   0b00000000,   0b00000000, //`
   0b00000000, 0b01000100, 0b10101010, 0b10101010, 0b01100110, //a
   0b10001000, 0b11001100, 0b10101010, 0b10101010, 0b11001100, //b
   0b00000000,   0b01100110, 0b10001000, 0b10001000, 0b01100110, //c
   0b00100010,   0b01100110, 0b10101010, 0b10101010, 0b01100110, //d
   0b00000000, 0b01000100, 0b10101010, 0b11001100, 0b01100110, //e
   0b01100110,   0b01000100, 0b11101110, 0b01000100, 0b01000100, //f
   0b00000000, 0b01000100, 0b10101010, 0b01100110, 0b11001100, //g
   0b10001000, 0b11001100, 0b10101010, 0b10101010, 0b10101010, //h
   0b01000100,   0b00000000, 0b01000100, 0b01000100, 0b01000100, //i
   0b01000100, 0b00000000, 0b01000100, 0b01000100, 0b10001000, //j
   0b10001000,   0b10001000, 0b10101010, 0b11001100, 0b10101010, //k
   0b01000100,   0b01000100, 0b01000100, 0b01000100, 0b01000100, //l
   0b00000000,   0b11101110, 0b11101110, 0b10101010, 0b10101010, //m
   0b00000000,   0b11001100, 0b10101010, 0b10101010, 0b10101010, //n
   0b00000000,   0b01000100, 0b10101010, 0b10101010, 0b01000100, //o
   0b00000000,   0b11001100, 0b10101010, 0b11001100, 0b10001000, //p
   0b00000000,   0b01100110, 0b10101010, 0b01100110, 0b00100010, //q
   0b00000000,   0b10001000, 0b11101110, 0b10001000, 0b10001000, //r
   0b00000000, 0b01100110, 0b11001100, 0b00100010, 0b11001100, //s
   0b01000100,   0b11101110, 0b01000100, 0b01000100, 0b01000100, //t
   0b00000000, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //u
   0b00000000, 0b10101010, 0b10101010, 0b01000100, 0b01000100, //v
   0b00000000,   0b10101010, 0b10101010, 0b11101110, 0b10101010, //w
   0b00000000,   0b10101010, 0b01000100, 0b01000100, 0b10101010, //x
   0b00000000,   0b10101010, 0b10101010, 0b01100110, 0b11001100, //y
   0b00000000, 0b11101110, 0b01100110, 0b11001100, 0b11101110, //z
   0b00100010,   0b01000100,   0b11001100,   0b01000100,   0b00100010, //{
   0b01000100,   0b01000100,   0b01000100,   0b01000100,   0b01000100, //|
   0b10001000,   0b01000100,   0b01100110,   0b01000100,   0b10001000, //}
   0b00000000,   0b11001100,   0b10101010,   0b00000000,   0b00000000  //~
   };

//================================
// Paste above "glcd_fillScreen(int1 color)"
//================================
// Purpose:       Write small text on a graphic LCD
// Inputs:        (x,y) - The upper left coordinate of the first letter
//                textptr - A pointer to an array of text to display
//                color - ON or OFF

//char characterSet[] = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
void glcd_text35(int8 x, int8 y, char* textptr, int1 color)
{
   int i, j, k;                           // Loop counters
   BYTE pixelData[5];                     // Stores character data

   for(i=0; textptr[i] != '\0'; ++i, ++x) // Loop through the passed string
   {
      if((textptr[i] >= ' ') && (textptr[i] <= '~'))
         memcpy(pixelData, TEXT35[textptr[i]-' '], 5);
      else
         memcpy(pixelData, TEXT35[0], 5); // Default to space

      if(x+3 >= GLCD_WIDTH)          // Performs character wrapping
      {
         x = 0;                           // Set x at far left position
         y += 5 + 1;                      // Set y at next position down
      }
      for(j=3; j>0; j--, x++)             // Loop through character byte data
      {
         for(k=0; k<5; k++)               // Loop through the vertical pixels
         {
            if(bit_test(pixelData[k], j)) // Check if the pixel should be set
            {
               glcd_pixel(x, y+k, color); // Draws the pixel
            }
         }
      }
   }
}



Can you pls show me how to do it ? I followed the same steps exactly. I couldn't get it right!!

Thank you


Last edited by alarassi on Mon Mar 29, 2010 1:39 pm; edited 1 time in total
alarassi



Joined: 28 Mar 2010
Posts: 8
Location: Malaysia

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 9:27 am     Reply with quote

hello guys,

i'm really wondering why there's no any answer for my enquiry so far!!!
is it unclear or difficult or what!? i though it would be easy for some of u to help me since i'm still new in this field!

i really need ur help and looking for it

thank ku
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 1:11 pm     Reply with quote

alarassi wrote:
hello guys,

i'm really wondering why there's no any answer for my enquiry so far!!!

i really need ur help and looking for it

thank ku


Maybe because some of us have a family life during the weekend !!! Surprised

Simply follow the instructions, you must create a new file called 'GLCD - modified.C' and btw you are not allowed to post a driver from CCS on the forum cause it is copyrighted !!
alarassi



Joined: 28 Mar 2010
Posts: 8
Location: Malaysia

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 1:48 pm     Reply with quote

mindstorm88 wrote:

Maybe because some of us have a family life during the weekend !!! Surprised

Simply follow the instructions, you must create a new file called 'GLCD - modified.C' and btw you are not allowed to post a driver from CCS on the forum cause it is copyrighted !!


OMG i didn't know about it! i deleted it already! sorry

i followed all the instructions exactly and compiled the code sucessfully but it doesn't give correct display! while when i use the given hex file by the designer it works great!
the only different i noticed was that the designer mentioned
Code:
//================================
// Paste above "const int8 TEXT[51][5]"
//================================

while if u check the GLCD.C , u find it as
const BYTE TEXT[51][5]!!

i don't know if it's different and how can i solv this problem!
i'm really looking for ur help

thank u
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 3:23 pm     Reply with quote

Byte, and int8, are the same.
I'd suspect it was just his typing.
It has been declared as 'byte', right back to a 2001 version (just checked...).
However the file did change in 2005. The earlier version dates to 2003. If you look at the copywrite dates, it was originally written in 1996, then modified in 2003. However the code seems fundamentally the same.
I'd start with a test meter, and actually bus out the pin connections, and verify that the lines do go to the pins you expect for the modified file. The most likely thing is a typo here.

Best Wishes
alarassi



Joined: 28 Mar 2010
Posts: 8
Location: Malaysia

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 11:16 pm     Reply with quote

Ttelmah wrote:
Byte, and int8, are the same.
I'd suspect it was just his typing.
It has been declared as 'byte', right back to a 2001 version (just checked...).
However the file did change in 2005. The earlier version dates to 2003. If you look at the copywrite dates, it was originally written in 1996, then modified in 2003. However the code seems fundamentally the same.
I'd start with a test meter, and actually bus out the pin connections, and verify that the lines do go to the pins you expect for the modified file. The most likely thing is a typo here.

Best Wishes

The connections are correct because I can use the given hex file. It shows the correct output signal! But I can't generate the correct hex file from the code itself!!
Can it be versions mismatch ?
Here's the original code for the program I'm using:
Code:

////////////////////////////////////////////////////////////////////////////////
//                      KS0108 128 x 64 Graphical LCD
//                          Oscilloscope Example
//
// Filename     : 18F2550 GLCD Oscilloscope DR1r1.c
// Programmer   : Steven Cholewiak, www.semifluid.com
// Version      : Version 1.0 - 08/21/2006
// Remarks      : This example draws a digital oscilloscope display to a KS0108
//                graphical LCD. Please note the limitations of the PIC's analog
//                port and make sure to buffer the input for the most accurate
//                reading.
//
//                More information on the circuit can be found at:
//                http://www.semifluid.com/PIC18F2550_GLCD_Oscilloscope.php
////////////////////////////////////////////////////////////////////////////////

#include <18F2550.h>
#device ADC=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

#use rs232(stream=PC, baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <GLCD - modified.c>

#INT_RDA
void serial_isr()                         // Serial Interrupt
{
   if (fgetc(PC) == 0x12 && fgetc(PC) == 0x34 && fgetc(PC) == 0x56 && fgetc(PC) == 0x78 && fgetc(PC) == 0x90) #asm reset #endasm
}

void displayFloat(BYTE x, BYTE y, float oldValue, float theValue) {
   char toPrintOld[9];
   char toPrint[9];
   sprintf(toPrintOld, "%f", oldValue);
   sprintf(toPrint, "%f", theValue);
   toPrintOld[4] = '\0';
   toPrint[4] = '\0';                              // Limit shown digits to 3
   glcd_text35(x, y, toPrintOld, OFF);
   glcd_text35(x, y, toPrint, ON);
}

void displayBYTE(BYTE x, BYTE y, BYTE oldValue, BYTE 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_text35(x, y, toPrintOld, OFF);
   glcd_text35(x, y, toPrint, ON);
}

void displayInt16(BYTE x, BYTE y, int16 oldValue, int16 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_text35(x, y, toPrintOld, OFF);
   glcd_text35(x, y, toPrint, ON);
}

BYTE useThreshold = 0;           // 0 = Off, 1 = Rising, 2 = Falling
BYTE theThreshold = 127;
BYTE timeType = 1;               // 1 = us, 2 = ms
BYTE timePeriod = 4;             // us or ms per measurement (* 25 for each div)
BYTE 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(BYTE theUsage, BYTE theValue) {
   float tempFloat = 0.0;

   tempFloat = (theThreshold>>2) * voltageConst;

   if (theUsage == 0)
      glcd_text35(12, 24, strOff, OFF);
   else if (theUsage == 1) {
      glcd_text35(12, 24, strRising, OFF);
      displayFloat(12, 30, tempFloat, (theValue>>2) * voltageConst);
   }
   else if (theUsage == 2) {
      glcd_text35(12, 24, strFalling, OFF);
      displayFloat(12, 30, tempFloat, (theValue>>2) * voltageConst);
   }

   useThreshold = theUsage;
   theThreshold = theValue;

   glcd_text35(0, 24, strThreshold, ON);
   if (useThreshold == 0) glcd_text35(12, 24, strOff, ON);
   else if (useThreshold == 1) glcd_text35(12, 24, strRising, ON);
   else if (useThreshold == 2) glcd_text35(12, 24, strFalling, ON);
}

void changeTimeDivision(BYTE theType, int16 theValue) {
   float tempFloat = 0.0, tempFloat2 = 0.0;

   glcd_text35(0, 36, strTime, ON);
   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_text35(4, 42, strMs, ON);
}

void changeVoltageRange(BYTE theType) {
   glcd_text35(0, 54, strRange, ON);
   if (voltageRange == 1) glcd_text35(8, 54, strR0to5, OFF);
   else if (voltageRange == 2) glcd_text35(8, 54, strR0to25, OFF);
   else if (voltageRange == 3) glcd_text35(8, 54, strR0to12, OFF);

   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_text35(8, 54, strR0to5, ON);
   else if (voltageRange == 2) glcd_text35(8, 54, strR0to25, ON);
   else if (voltageRange == 3) glcd_text35(8, 54, strR0to12, ON);
}

void main() {
   BYTE const numOfSamples = 100;
   int16 HQadcReadings[numOfSamples];
   BYTE adcReadings[numOfSamples], adcReadingsOld[numOfSamples];
   BYTE i = 0;
   BYTE thres2 = 1;
   int16 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;
   int16 theFreq = 0.0, theFreqOld = 0.0;

   SETUP_ADC_PORTS(AN0 | VSS_VDD);           // Setup ADC Pins
   SETUP_ADC(ADC_CLOCK_DIV_64);              // Setup ADC
   SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_1);  // Use the int. osc. for Timer 0
   SETUP_TIMER_1(T1_DISABLED);               // Disable Timer 1
   SETUP_TIMER_2(T2_DISABLED, 127, 1);       // Disable Timer 2
   SETUP_TIMER_3(T3_DISABLED);               // Disable Timer 3
   SETUP_CCP1(CCP_OFF);                      // Disable CCP1
   SETUP_CCP2(CCP_OFF);                      // Disable 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
   glcd_text35(0, 0, strAverageV, ON);
   glcd_text35(0, 6, strVMaximum, ON);
   glcd_text35(0, 12, strVMinimum, ON);
   glcd_text35(0, 18, strVPtoP, ON);
   glcd_text35(20, 48, strHz, ON);
   // Setup variable ranges
   changeVoltageRange(1);                    // Set voltage range
   changeTimeDivision(1, 200);                // Set time divisions
   changeThreshold(1, 127);                  // Set threshold level

   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);
      for (i=0; i<numOfSamples; i++)
         adcReadingsOld[i] = adcReadings[i];

      // Calculate and display frequency of signal using zero crossing
      // displayBYTE(0, 54, thres2, 0);
      if (useThreshold != 0) {
         for (i=0; i<63; i+=3)
               glcd_pixel(thres2+(128-numOfSamples),i,OFF);
         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++);
         }
         // displayBYTE(0, 54, 0, thres2);
         for (i=0; i<63; i+=3)
            glcd_pixel(thres2+(128-numOfSamples),i,ON);

         k = (int16) 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_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);    // Reduces flicker by allowing pixels to be on
                       // much longer than off
   }
}

I hope you can help me out with it because I'm really tired!
Silly Question. Is there a difference between driver & library or both are same with different names because I didn't find library folder ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 2:18 am     Reply with quote

No, being able to use the 'given hex file', does _not_ prove that the connections match the modifications.
The most likely scenario, is that he modified the file, then found something wrong (a line swapped etc.), and modified the file again, _but did not document this_. So the supplied file, actually uses a fractionally different connection to the documentation.
Realistically, the modifications to the file, are all just to use different connection pins, so the thing to do, is find out the _real_ connections, and modify the file yourself, to match what is really there.

Best Wishes
alarassi



Joined: 28 Mar 2010
Posts: 8
Location: Malaysia

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 3:30 am     Reply with quote

Thank you for your reply

After long search, I realized that it might be nothing wrong with the modification or the given files! I think what I have to do is to play with the delays in the GLCD.C since I'm using different type of GLCD but with the same controller! So my glcd type might be slow!

Can you please tell me in which part I should add delays to and test the glcd?

Thank you
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group