setting up TFT LCD touch screen with ssd1289 chip

Thread Starter

cheshmayebaruni

Joined Dec 28, 2012
22
hi Engineers;

i want set up touch screen lcd but i have some problem.

i can't working with ADC and geting x,y coordinate.

this below is my code of codevision :

thanks for your help.

LCD specifications:
3.2 inch
chip : ssd1289

microcontroller:
AT mega32


Code:
#include <mega32a.h>
#include <delay.h>
#include<stdlib.h>

#include "SSD1289.h"


#define ADC_VREF_TYPE 0x00

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

 int xx,yy;
 char strx[5];
 char stry[5];
void main(void)
{
  char strx[16];
  char stry[16];
 int x,y;
 
int Temp_adcY,Temp_adcX;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
lcd_init();
   
  DDRB=0xff;
  DDRC=0xff;
  DDRD=0xff;
   
   
   
  while(1)
  {   
   
   
  lcd_clear();
  lcd_background_color(YELLOW);
   
   
  DDRA= 0xF3;
  PORTA.0= 0;
  PORTA.1=1;
  xx = read_adc(2);
  DDRA= 0xFC;
  PORTA.2= 0;
  PORTA.3=1;
  yy = read_adc(0);
  itoa(yy,stry);
  itoa(xx,strx);
  lcd_gotoxy(0,0);
  lcd_puts(strx,RED,BLACK);
  lcd_gotoxy(10,10);
  lcd_puts(stry,RED,BLACK);
  delay_ms(125);
  lcd_clear();
   
  }
 
   
   
}
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
Your A2D just might be correct (I will not check as this is not a device I am familiar with). However, it seems you are just reading the pin output voltage on your A2D due to improperly driving the touch sensor.

I am assuming this is a resistive sensor from the scant information you give based on the outputs being in the form of X+, X-, Y+, Y-. These are sensed by establishing a voltage across one direction and reading the voltage on the other direction. Why?

Say you put 3.3V on Y+ and 0V on Y-. When you touch the screen you connect the Y side to the X side, so whatever voltage is on Y at that point will be conducted to both X terminals (so you could read either one). But to read the X terminals you need to make them analog inputs as the voltage can be anywhere from 0 to 3.3V (and digital inputs don't work well with in between voltages).

So to read Y:
A0=analog input
A1= high
A3=low
A4=analog input
Read either A0 or A4.

To read X:
A0=high
A1= analog input
A3=analog input
A4=low
Read either A1 or A3.

If you set and forget in either X or Y reading conditions you should be able to take a voltmeter and watch the voltage change as your finger skims across the screen.
 

Thread Starter

cheshmayebaruni

Joined Dec 28, 2012
22
hi. thanks for help

i have new problems. plz help me!!

this is my code

base on my code and ifs in codes .this should type my text but ..

Code:
#include <mega32a.h>
#include <delay.h>
#include <stdlib.h>
#include "SSD1289.h"

#define ADC_VREF_TYPE 0x20
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
delay_us(10);
ADCSRA|=0x40;
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}



int xx,yy;
char strx[15];
char stry[15];

void init();
 
void main(void)
{  
      int x,y;
   char out[20];
 
  
  
   int i,j=5;



ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;


  lcd_init();
   

     /* 
        lcd_gotoxy(5,10);
        lcd_puts("wellcom to my project",GREEN,BLACK);
        delay_ms(50);
        */     
         
       
     
          lcd_clear();
         
           //YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
             lcd_draw_line(22,238,22,320,BLACK);    
             lcd_draw_line(44,238,44,320,BLACK);
             lcd_draw_line(66,238,66,320,BLACK);
             lcd_draw_line(88,238,88,320,BLACK);
             lcd_draw_line(110,238,110,320,BLACK);
             lcd_draw_line(132,238,132,320,BLACK);
             lcd_draw_line(154,238,154,320,BLACK);
             lcd_draw_line(176,238,176,320,BLACK);
             lcd_draw_line(198,238,198,320,BLACK);
             lcd_draw_line(220,238,220,320,BLACK);
             //-------------------------------------
             //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
             lcd_draw_line(0,238,240,238,BLACK);    
             lcd_draw_line(0,266,240,266,BLACK);
             lcd_draw_line(0,293,240,293,BLACK);
           
             lcd_gotoxy(1,239);
             lcd_putchar('Q',BLACK,WHITE);
              lcd_gotoxy(4,239);
             lcd_putchar('W',BLACK,WHITE);
              lcd_gotoxy(7,239);
             lcd_putchar('E',BLACK,WHITE);
              lcd_gotoxy(9,239);
             lcd_putchar('R',BLACK,WHITE);
              lcd_gotoxy(12,239);
             lcd_putchar('T',BLACK,WHITE);
              lcd_gotoxy(15,239);
             lcd_putchar('Y',BLACK,WHITE);
              lcd_gotoxy(18,239); 
             lcd_putchar('U',BLACK,WHITE);
              lcd_gotoxy(20,239);
             lcd_putchar('I',BLACK,WHITE);
              lcd_gotoxy(23,239);
             lcd_putchar('O',BLACK,WHITE);
              lcd_gotoxy(25,239);
             lcd_putchar('P',BLACK,WHITE);
             lcd_gotoxy(28,239);
             lcd_putchar('(',BLACK,WHITE);  
           
             lcd_gotoxy(1,241);
             lcd_putchar('A',BLACK,WHITE);
              lcd_gotoxy(4,241);
             lcd_putchar('S',BLACK,WHITE);
              lcd_gotoxy(7,241);
             lcd_putchar('D',BLACK,WHITE);
              lcd_gotoxy(9,241);
             lcd_putchar('F',BLACK,WHITE);
              lcd_gotoxy(12,241);
             lcd_putchar('G',BLACK,WHITE);
              lcd_gotoxy(15,241);
             lcd_putchar('H',BLACK,WHITE);
              lcd_gotoxy(18,241); 
             lcd_putchar('J',BLACK,WHITE);
              lcd_gotoxy(20,241);
             lcd_putchar('K',BLACK,WHITE);
              lcd_gotoxy(23,241);
             lcd_putchar('L',BLACK,WHITE);
              lcd_gotoxy(25,241);
             lcd_putchar(';',BLACK,WHITE);
             lcd_gotoxy(28,241);
             lcd_putchar(')',BLACK,WHITE);
           
               lcd_gotoxy(1,243);
             lcd_putchar('Z',BLACK,WHITE);
              lcd_gotoxy(4,243);
             lcd_putchar('X',BLACK,WHITE);
              lcd_gotoxy(7,243);
             lcd_putchar('C',BLACK,WHITE);
              lcd_gotoxy(9,243);
             lcd_putchar('V',BLACK,WHITE);
              lcd_gotoxy(12,243);
             lcd_putchar('B',BLACK,WHITE);
              lcd_gotoxy(15,243);
             lcd_putchar('N',BLACK,WHITE);
              lcd_gotoxy(18,243); 
             lcd_putchar('M',BLACK,WHITE);
              lcd_gotoxy(20,243);
             lcd_putchar(',',BLACK,WHITE);
              lcd_gotoxy(23,243);
             lcd_putchar('.',BLACK,WHITE);
              lcd_gotoxy(25,243);
             lcd_putchar('?',BLACK,WHITE);
             lcd_gotoxy(28,243);
             lcd_putchar('!',BLACK,WHITE);
            
             lcd_gotoxy(7,1); 
              lcd_puts("typed text : ",BLACK,WHITE);
             lcd_draw_rectangle(50,40,185,100,BLACK);
            
             lcd_gotoxy(20,10); 
              lcd_puts("Save text ",BLACK,WHITE);
             lcd_draw_rectangle(158,155,236,185,BLACK);
            
   while (1)
      {        
            
           
             
      
      DDRA.0=1;        //-x
      DDRA.1=0;        //y
      DDRA.2=1;        //x
      DDRA.3=0;        //-y
      PORTA.0=0;
      PORTA.1=0;
      PORTA.2=1;
      PORTA.3=0;
      
      y=read_adc(1); 
      y=y/4.26;  
      itoa(y,stry);
     
       lcd_gotoxy(0,1);
      lcd_puts("X= ",RED,WHITE);
      lcd_puts(stry,RED,WHITE);
     
      DDRA.0=0;
      DDRA.1=1;
      DDRA.2=0;
      DDRA.3=1;
      PORTA.0=0;
      PORTA.1=1;
      PORTA.2=0;
      PORTA.3=0;
      x=read_adc(2);
      x=x/3.19;  
      itoa(x,strx);   
   
      lcd_gotoxy(0,0);    
      lcd_puts("Y= ",RED,WHITE);
      lcd_puts(strx,RED,WHITE); 
     
        //-----------------------------------------------
         lcd_gotoxy(j,3);    
        
          if(y<25 && y>19 && x==10 ){               
          lcd_putchar('Q',BLACK,WHITE);
           j++; 
         }  
        
         if(y<25 && y>19 && x>11 && x<15){               
          lcd_putchar('W',BLACK,WHITE);
          j++;
         }
       
         if(y<25 && y>19 && x<19 && x>15){               
         lcd_putchar('E',BLACK,WHITE);
         j++; 
         }   
       
          if(y<25 && y>19 && x<23  && x>19 ){               
          lcd_putchar('R',BLACK,WHITE);
           j++;  
         }
        
          if(y<25 && y>19 && x>23 && x<27){                
          lcd_putchar('T',BLACK,WHITE);
           j++;
         }
       
         if(y<25 && y>19 && x>28 && x<32){               
         lcd_putchar('Y',BLACK,WHITE);
          j++;
         }
        
          if(y<25 && y>19 && x>32  && x<37){               
          lcd_putchar('U',BLACK,WHITE);
          j++;
         } 
        
         if(y<25 && y>19 && x<41 && x>37){               
          lcd_putchar('I',BLACK,WHITE);
          j++;
         }
       
         if(y<25 && y>19 && x<45 && x>41){              
         lcd_putchar('O',BLACK,WHITE);
         j++;
         }
        
          if(y<25 && y>19 && x<49  && x>45 ){              
          lcd_putchar('P',BLACK,WHITE);
          j++; 
         }  
        
         if(y<25 && y>19 && x<41 && x>49){               
          lcd_putchar('(',BLACK,WHITE);
          j++;
          }
        //----------------------------------------------
      }      
  }     
      
void init()
{

PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x20;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;


// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
}
[code]
 
Last edited:
Top