GLCD not working in this beta 3 version

Beta Testing discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Innovator
Posts: 21
Joined: 01 Jan 2009 20:21

GLCD not working in this beta 3 version

#1 Post by Innovator » 29 Apr 2010 04:55

i am using LV-33A dev board and the glcd works when using mikroC for dspic but i am now trying out mikroC Pro for dspic v3beta and i can not get it to work. i have got the new touch panel example from you website but that also doesnt work and yes i have changed the glcd connection bits to suit the dev board (think i have got them right). i have only uploaded a partial bit of the program as the program runs until "TP_Calibrate_Bottom_Left(); // Calibration of bottom left corner" and then stops but nothing is or has been displayed on screen.

can you see what i am doing wrong.......

Code: Select all

// Glcd module connections
sbit GLCD_D7 at RD7_bit;
sbit GLCD_D6 at RD6_bit;
sbit GLCD_D5 at RD4_bit;
sbit GLCD_D4 at RD4_bit;
sbit GLCD_D3 at RD3_bit;
sbit GLCD_D2 at RD2_bit;
sbit GLCD_D1 at RD1_bit;
sbit GLCD_D0 at RD0_bit;
sbit GLCD_D7_Direction at TRISD7_bit;
sbit GLCD_D6_Direction at TRISD6_bit;
sbit GLCD_D5_Direction at TRISD5_bit;
sbit GLCD_D4_Direction at TRISD4_bit;
sbit GLCD_D3_Direction at TRISD3_bit;
sbit GLCD_D2_Direction at TRISD2_bit;
sbit GLCD_D1_Direction at TRISD1_bit;
sbit GLCD_D0_Direction at TRISD0_bit;
sbit GLCD_CS1 at LATB2_bit;
sbit GLCD_CS2 at LATB3_bit;
sbit GLCD_RS  at LATB4_bit;
sbit GLCD_RW  at LATB5_bit;
sbit GLCD_EN  at LATB6_bit;
sbit GLCD_RST at LATB7_bit;
sbit GLCD_CS1_Direction at TRISB2_bit;
sbit GLCD_CS2_Direction at TRISB3_bit;
sbit GLCD_RS_Direction  at TRISB4_bit;
sbit GLCD_RW_Direction  at TRISB5_bit;
sbit GLCD_EN_Direction  at TRISB6_bit;
sbit GLCD_RST_Direction at TRISB7_bit;
// End Glcd module connections

// Touch Panel module connections
sbit DriveA at LATD10_bit;
sbit DriveB at LATD11_bit;
sbit DriveA_Direction at TRISD10_bit;
sbit DriveB_Direction at TRISD11_bit;
// End Touch Panel module connection

bit         write_erase;
char         pen_size;
char write_msg[] = "WRITE";

// GLCD menu messages
char clear_msg[] = "CLEAR";
char erase_msg[] = "ERASE";
unsigned int x_coord, y_coord;

void Initialize() {
ADPCFG = 0xF3FF;                    // set AN8 and AN9 channel pins as analog
DriveA_Direction = 0;               // Set DriveA pin as output
DriveB_Direction = 0;               // Set DriveB pin as output
Glcd_Init();                        // Initialize GLCD
Delay_ms(500);
Glcd_Fill(0);                       // Clear GLCD
ADC1_Init();                        // Initalize ADC module
TP_Init(128, 64, 6, 7);             // Initialize touch panel
TP_Set_ADC_Threshold(3900);         // Set touch panel ADC threshold
                    }

void Calibrate() {
Glcd_Dot(0,63,1);                               // Draw bottom left dot
Glcd_Write_Text("TOUCH BOTTOM LEFT",12,3,1);
TP_Calibrate_Bottom_Left();                     // Calibration of bottom left corner
//RE7_bit=1;               for testing only
Delay_ms(1000);
Glcd_Dot(0,63,0);                               // Clear bottom left dot
Glcd_Dot(127,0,1);                              // Draw upper right dot
Glcd_Write_Text("                 ",12,3,1);
Glcd_Write_Text("TOUCH UPPER RIGHT",12,4,1);
TP_Calibrate_Upper_Right();                     // Calibration of upper right corner
Delay_ms(1000);
                  }
void main() 
{
PORTE = 0;
TRISE = 0x00;
//RE7_bit =1;           for testing only
Initialize();
Glcd_Write_Text("CALIBRATION",12,3,1);
Delay_ms(5000);
Glcd_Fill(0);           // Clear GLCD
Calibrate();
Glcd_Fill(0);
Glcd_Write_Text("WRITE ON SCREEN", 20, 5, 1) ;
Delay_ms(1000);
Glcd_Fill(0);           // Clear GLCD
Glcd_V_Line(0,7,0,1);
Glcd_Write_Text(clear_msg,1,0,0);
Glcd_V_Line(0,7,97,1);
Glcd_Write_Text(erase_msg,98,0,0);  

// Pen Menu:
Glcd_Rectangle(41,0,52,9,1);
Glcd_Box(45,3,48,6,1);
Glcd_Rectangle(63,0,70,7,1);
Glcd_Box(66,3,67,4,1);
Glcd_Rectangle(80,0,86,6,1);
Glcd_Dot(83,3,1);
write_erase = 1;
pen_size = 1;
while (1) 

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: GLCD not working in this beta 3 version

#2 Post by tihomir.losic » 29 Apr 2010 08:18

Hello,

please, try this code:

Code: Select all

// Glcd module connections
sbit GLCD_D7 at RD7_bit;
sbit GLCD_D6 at RD6_bit;
sbit GLCD_D5 at RD5_bit;
sbit GLCD_D4 at RD4_bit;
sbit GLCD_D3 at RD3_bit;
sbit GLCD_D2 at RD2_bit;
sbit GLCD_D1 at RD1_bit;
sbit GLCD_D0 at RD0_bit;
sbit GLCD_D7_Direction at TRISD7_bit;
sbit GLCD_D6_Direction at TRISD6_bit;
sbit GLCD_D5_Direction at TRISD5_bit;
sbit GLCD_D4_Direction at TRISD4_bit;
sbit GLCD_D3_Direction at TRISD3_bit;
sbit GLCD_D2_Direction at TRISD2_bit;
sbit GLCD_D1_Direction at TRISD1_bit;
sbit GLCD_D0_Direction at TRISD0_bit;

sbit GLCD_CS1 at LATB2_bit;
sbit GLCD_CS2 at LATB3_bit;
sbit GLCD_RS  at LATB4_bit;
sbit GLCD_RW  at LATB5_bit;
sbit GLCD_EN  at LATB6_bit;
sbit GLCD_RST at LATB7_bit;
sbit GLCD_CS1_Direction at TRISB2_bit;
sbit GLCD_CS2_Direction at TRISB3_bit;
sbit GLCD_RS_Direction  at TRISB4_bit;
sbit GLCD_RW_Direction  at TRISB5_bit;
sbit GLCD_EN_Direction  at TRISB6_bit;
sbit GLCD_RST_Direction at TRISB7_bit;
// end Glcd module connections


sbit DRIVE_A at LATD10_bit;  // for writing to output pin always use latch
sbit DRIVE_B at LATD11_bit;  // for writing to output pin always use latch
sbit DRIVE_A_Direction at TRISD10_bit;
sbit DRIVE_B_Direction at TRISD11_bit;

const char READ_X_CHANNEL = 8;     // READ X line is connected to analog channel 0
const char READ_Y_CHANNEL = 9;     // READ Y line is connected to analog channel 1

char write_erase, pen_size;
unsigned int x_coord, y_coord;
long         x_coord128, y_coord64;                       // scaled x-y position
int          cal_x_min, cal_y_min, cal_x_max, cal_y_max;  // calibration constants
char write_msg[] = "WRITE";                               // GLCD menu messages
char clear_msg[] = "CLEAR";
char erase_msg[] = "ERASE";
const unsigned int ADC_THRESHOLD = 900;                   // threshold value for press detecting
char temp;

  // returns 1 if TouchPanel is pressed, 0 otherwise
char PressDetect() {
  unsigned adc_rd;
  char result;

  // PRESS detecting
  DRIVE_A = 0;         // DRIVEA = 0 (LEFT drive off, RIGHT drive off, TOP drive on)
  DRIVE_B = 0;         // DRIVEB = 0 (BOTTOM drive off)
  Delay_ms(5);

  adc_rd = ADC1_Read(READ_Y_CHANNEL);      // READ-Y
  result = (adc_rd > ADC_THRESHOLD);       // if logical one is detectet

  //debouncing, repeat detecting after 2ms
  Delay_ms(2);
  adc_rd = ADC1_Read(READ_Y_CHANNEL);      // READ-Y
  result = result & (adc_rd > ADC_THRESHOLD);
  return result;
}

unsigned int GetX() {
  unsigned int result;
  //reading X
  DRIVE_A = 1;          // DRIVEA = 1 (LEFT drive on, RIGHT drive on, TOP drive off)
  DRIVE_B = 0;          // DRIVEB = 0 (BOTTOM drive off)

  Delay_us(500);
  result = ADC1_Read(READ_X_CHANNEL);      // READ-X (BOTTOM)
  return result;
}

unsigned int GetY() {
  unsigned int result;
  //reading Y
  DRIVE_A = 0;          // DRIVEA = 0 (LEFT drive off, RIGHT drive off, TOP drive on)
  DRIVE_B = 1;          // DRIVEB = 1 (BOTTOM drive on)

  Delay_us(500);
  result = ADC1_Read(READ_Y_CHANNEL);      // READ-X (LEFT)
  return result;
}

void Calibrate() {

  Glcd_Dot(0,63,1);
  Glcd_Write_Text("TOUCH BOTTOM LEFT",10,3,1);

  while (!PressDetect());

  // get calibration constants (reading and compensating TouchPanel nonlinearity)
  cal_x_min = GetX() - 10;
  cal_y_min = GetY() - 10;
  Delay_ms(1000);

  Glcd_Fill(0);
  Glcd_Dot(127,0,1);
  Glcd_Write_Text("TOUCH UPPER RIGHT",10,4,1);
  while (!PressDetect());

  // get calibration constants (reading and compensating TouchPanel nonlinearity)
  cal_x_max = GetX() + 5;
  cal_y_max = GetY() + 5;
  Delay_ms(1000);
}

void Initialize() {

  ADPCFG = 0xFCFF;                          // set AN6 and AN7 channel pins as analog
  AD1CON1 = 0x8000;
  CMCON = 0;

  TRISB8_bit = 1;                           // inputs
  TRISB9_bit = 1;

  DRIVE_A_Direction = 0;                    // set DRIVE_A pin as output
  DRIVE_B_Direction = 0;                    // set DRIVE_B pin as output

  Glcd_Init();                              // initialize GLCD

}

void main() {

  Initialize();

  Glcd_Init();   // GLCD initialization LV 24-33A

  Glcd_Fill(0);
  Glcd_Set_Font(FontSystem5x7_v2, 5, 8, 32);
  Glcd_Write_Text("CALIBRATION", 24, 3, 1);
  Delay_ms(1500);

  Glcd_Fill(0);
  Calibrate();
  Glcd_Fill(0);

  Glcd_Write_Text("WRITE ON SCREEN", 24, 4, 1);
  Delay_ms(1000);
  Glcd_Fill(0);

  Glcd_Fill(0);
  Glcd_V_Line(0,7,0,1);
  Glcd_Write_Text(clear_msg,1,0,0);
  Glcd_V_Line(0,7,97,1);
  Glcd_Write_Text(erase_msg,98,0,0);

  // pen menu:
  Glcd_Rectangle(41,0,52,9,1);
  Glcd_Box(45,3,48,6,1);
  Glcd_Rectangle(63,0,70,7,1);
  Glcd_Box(66,3,67,4,1);
  Glcd_Rectangle(80,0,86,6,1);
  Glcd_Dot(83,3,1);

  write_erase = 1;
  pen_size = 1;

  while (1) {
    if (PressDetect()) {
      // after a PRESS is detected read X-Y and convert it to 128x64 space

      x_coord = GetX() - cal_x_min;
      y_coord = GetY() - cal_y_min;

      x_coord128 = (x_coord * 128L) / (cal_x_max - cal_x_min);
      y_coord64 = (64 -(y_coord *64L) / (cal_y_max - cal_y_min));


      if ((x_coord128 < 0) || (x_coord128 > 127))
         continue;
      if ((y_coord64 < 0) || (y_coord64 > 63))
         continue;

      // if clear is pressed
      if ((x_coord128 < 31) && (y_coord64 < 8)) {

         Glcd_Fill(0);

         // pen menu:
         Glcd_Rectangle(41,0,52,9,1);
         Glcd_Box(45,3,48,6,1);
         Glcd_Rectangle(63,0,70,7,1);
         Glcd_Box(66,3,67,4,1);
         Glcd_Rectangle(80,0,86,6,1);
         Glcd_Dot(83,3,1);

         Glcd_V_Line(0,7,0,1);
         Glcd_Write_Text(clear_msg,1,0,0);
         Glcd_V_Line(0,7,97,1);
         if (write_erase)
           Glcd_Write_Text(erase_msg,98,0,0);
         else
           Glcd_Write_Text(write_msg,98,0,0);
         }

      // if write/erase is pressed
      if ((x_coord128 > 96) && (y_coord64 < 8)) {
         if (write_erase) {
           write_erase = 0;
           Glcd_Write_Text(write_msg,98,0,0);
           Delay_ms(500);
           }
         else {
           write_erase = 1;
           Glcd_Write_Text(erase_msg,98,0,0);
           Delay_ms(500);
           }
         }

      // if pen size is selected
      if ((x_coord128 >= 41) && (x_coord128 <= 52) && (y_coord64 <= 9))
         pen_size = 3;

      if ((x_coord128 >= 63) && (x_coord128 <= 70) && (y_coord64 <= 7))
         pen_size = 2;

      if ((x_coord128 >= 80) && (x_coord128 <= 86) && (y_coord64 <= 6))
         pen_size = 1;

      if (y_coord64 < 11)
         continue;

      switch (pen_size) {
         case 1 : Glcd_Dot(x_coord128, y_coord64, write_erase); break;
         case 2 : Glcd_Box(x_coord128, y_coord64, x_coord128 + 1, y_coord64 + 1, write_erase); break;
         case 3 : Glcd_Box((unsigned) x_coord128-1, (unsigned) y_coord64-1, (unsigned) x_coord128 + 2, (unsigned) y_coord64 + 2, write_erase); break;
         }

      }
    }
}
Best regards,

Losic Tihomir
mikroElektronika [Support team]

Innovator
Posts: 21
Joined: 01 Jan 2009 20:21

Re: GLCD not working in this beta 3 version

#3 Post by Innovator » 29 Apr 2010 10:46

Hi Losic Tihomir

Thanks for your quick reply,i will try it out when i get back in hotel tonight, i can see that i had made a couple of mistakes myself (im not a good programmer yet but am workin on it :lol: ).

by the way, this "PRO" version is great, very user friendly to. i have used hitech,fed,ccs and mplab and i must say i get on better with mikroC.

Innovator
Posts: 21
Joined: 01 Jan 2009 20:21

Re: GLCD not working in this beta 3 version

#4 Post by Innovator » 01 May 2010 05:26

Hi Losic Tihomir,

i have now tried out the above code and must tell you it worked a treat - thank you once again.

im a bit of a nooby really because now i think of it i could of cut and pasted my working code in after the new setup of glcd connections/ initialisation part. i think the top most code through me a little because there was new functions for the touch panel (new to me that is). anyhow its working and i have now nearly got my workin project finished.

regards,

Innovator

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 Beta Testing”