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

Code forTouchscreen for Dev board easypic5 tested works fine

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
kabukiman85



Joined: 30 Oct 2008
Posts: 2
Location: Barcelona Spain

View user's profile Send private message

Code forTouchscreen for Dev board easypic5 tested works fine
PostPosted: Thu Oct 30, 2008 10:07 am     Reply with quote

I made this code to work with easypic5. I don't know if it is very efficient.
If anyone want to modify it to make it more efficent, please I want to know how.

thanks
Code:

/***************************************
      MIKROELECTRONICA ADAPTED CODE FOR CCS C

****************************************/


#include <16F887.h>
#device ADC = 10
#FUSES XT,NOWDT,NOPROTECT,NOPUT
#use delay(clock=8000000)
#include <GLCD_ESP5.c> // Custom library for KS108 EasyPic5
#include <graphics.c>

int16 const ADC_THRESHOLD=900;
int16 xmin;
int16 ymin;
int16 ymax;
int16 xmax;

int16 get_X()
{
  //Get X axis value DRIVEA = 1 DRIVEB =1
  output_c(0b00000001);
 
  set_adc_channel(0);
  delay_ms(2);
  return read_adc();

}

int16 get_Y()
{
   //Get X axis value DRIVEA = 0 DRIVEB =1
 
   output_c(0b00000010);
   set_adc_channel(1);
   delay_ms(2);
   return read_adc();
   
}
char PressDetect() {
  INT16 adc_rd;
  char result;
 
  // PRESS detecting DRIVEA = 0 DRIVEB = 0 read channel 1
  output_c(0x00);
  delay_us(3500);

  set_adc_channel(1);
  delay_ms(2);
  adc_rd = read_adc();


  result = (adc_rd > ADC_THRESHOLD);                     
 
  //debouncing, repeat detecting after 2ms
  delay_ms(2);
  adc_rd = read_adc();
  result = result & (adc_rd > ADC_THRESHOLD);
  return result;
}

void calibrate_screen()
{
  char msg []="TOCA ABAJO IZQUIERDA";
  char msg2 []="TOCA SUPERIOR DERECHA";
 
  glcd_text57(0,30,msg,1,ON);
 
 
  glcd_pixel(0,63,ON);
   while(!PressDetect());

   xmin = get_X() - 10;
   ymin = get_Y() - 10;
   
   delay_ms(1000);
   
   glcd_fillscreen(OFF);
   
 
  glcd_text57(0,30,msg2,1,ON);
 
  glcd_pixel(127,0,ON);
 
  while(!PressDetect());
 
   xmax = get_X() + 5 ;
   ymax = get_Y() + 5 ;

  delay_ms(1000);
 
 
 
}


void main()
{
   char msg[] = "CLEAR";
   int16 x_coord,y_coord;
   int8 x,y;
 
    glcd_init(ON);
   
   SET_TRIS_C(0b00000100);
   set_tris_b(0xff);
   setup_adc_ports(sAN0 | sAN1);
   setup_adc(ADC_CLOCK_INTERNAL);
 
  calibrate_screen();
 
  glcd_fillscreen(OFF);
 
  glcd_rect(0,0,30,7,1,1);   //Write Clear button
  glcd_text57(0,0,msg,1,0);
 
   while(1)
   {
      if(PressDetect())
      {
      y_coord = Get_Y() - ymin;
      x_coord = Get_X() - xmin;
     
      x = (int8) ((double) x_coord * 128 / (double)(xmax - xmin)); 
     
      y = (64 -(y_coord << 6) / (ymax - ymin));
     
      if(x >=0 && x <=30)
      {
         if(y>=0 && y <= 7)
         { //If clear button is pressed clear screen
            glcd_fillscreen(OFF);
             glcd_rect(0,0,30,7,1,1);
               glcd_text57(0,0,msg,1,0);
               delay_ms(100); // Delay for posible stack overflow
         }else  glcd_pixel(x,y,1);
         
      }else  glcd_pixel(x,y,1);
     
      }
       
   }

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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