setting up TFT LCD touch screen with ssd1289 chip

Discussion in 'The Projects Forum' started by cheshmayebaruni, May 20, 2015.

  1. cheshmayebaruni

    Thread Starter New Member

    Dec 28, 2012
    22
    0
    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 (Text):
    1.  
    2. #include <mega32a.h>
    3. #include <delay.h>
    4. #include<stdlib.h>
    5.  
    6. #include "SSD1289.h"
    7.  
    8.  
    9. #define ADC_VREF_TYPE 0x00
    10.  
    11. // Read the AD conversion result
    12. unsigned int read_adc(unsigned char adc_input)
    13. {
    14. ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
    15. // Delay needed for the stabilization of the ADC input voltage
    16. delay_us(10);
    17. // Start the AD conversion
    18. ADCSRA|=0x40;
    19. // Wait for the AD conversion to complete
    20. while ((ADCSRA & 0x10)==0);
    21. ADCSRA|=0x10;
    22. return ADCW;
    23. }
    24.  
    25.  int xx,yy;
    26.  char strx[5];
    27.  char stry[5];
    28. void main(void)
    29. {
    30.   char strx[16];
    31.   char stry[16];
    32.  int x,y;
    33.  
    34. int Temp_adcY,Temp_adcX;
    35. // ADC initialization
    36. // ADC Clock frequency: 1000.000 kHz
    37. // ADC Voltage Reference: AREF pin
    38. ADMUX=ADC_VREF_TYPE & 0xff;
    39. ADCSRA=0x83;
    40. lcd_init();
    41.    
    42.   DDRB=0xff;
    43.   DDRC=0xff;
    44.   DDRD=0xff;
    45.    
    46.    
    47.    
    48.   while(1)
    49.   {  
    50.    
    51.    
    52.   lcd_clear();
    53.   lcd_background_color(YELLOW);
    54.    
    55.    
    56.   DDRA= 0xF3;
    57.   PORTA.0= 0;
    58.   PORTA.1=1;
    59.   xx = read_adc(2);
    60.   DDRA= 0xFC;
    61.   PORTA.2= 0;
    62.   PORTA.3=1;
    63.   yy = read_adc(0);
    64.   itoa(yy,stry);
    65.   itoa(xx,strx);
    66.   lcd_gotoxy(0,0);
    67.   lcd_puts(strx,RED,BLACK);
    68.   lcd_gotoxy(10,10);
    69.   lcd_puts(stry,RED,BLACK);
    70.   delay_ms(125);
    71.   lcd_clear();
    72.    
    73.   }
    74.  
    75.    
    76.    
    77. }
    78.  
    79.  
    80.  
     
    Last edited: May 20, 2015
  2. cheshmayebaruni

    Thread Starter New Member

    Dec 28, 2012
    22
    0
    values on the lcd is stable. not variable
    i think my adc cofigurations is incorrect. please checking it. thnaks

    [​IMG]
     
  3. cheshmayebaruni

    Thread Starter New Member

    Dec 28, 2012
    22
    0
    please give me correct code of adc configurations
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    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.
     
    cheshmayebaruni likes this.
  5. cheshmayebaruni

    Thread Starter New Member

    Dec 28, 2012
    22
    0
    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 ..
    [​IMG]
    Code (Text):
    1.  
    2. #include <mega32a.h>
    3. #include <delay.h>
    4. #include <stdlib.h>
    5. #include "SSD1289.h"
    6.  
    7. #define ADC_VREF_TYPE 0x20
    8. unsigned char read_adc(unsigned char adc_input)
    9. {
    10. ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
    11. delay_us(10);
    12. ADCSRA|=0x40;
    13. while ((ADCSRA & 0x10)==0);
    14. ADCSRA|=0x10;
    15. return ADCH;
    16. }
    17.  
    18.  
    19.  
    20. int xx,yy;
    21. char strx[15];
    22. char stry[15];
    23.  
    24. void init();
    25.  
    26. void main(void)
    27. {  
    28.       int x,y;
    29.    char out[20];
    30.  
    31.  
    32.  
    33.    int i,j=5;
    34.  
    35.  
    36.  
    37. ADMUX=ADC_VREF_TYPE & 0xff;
    38. ADCSRA=0x83;
    39.  
    40.  
    41.   lcd_init();
    42.    
    43.  
    44.      /*
    45.         lcd_gotoxy(5,10);
    46.         lcd_puts("wellcom to my project",GREEN,BLACK);
    47.         delay_ms(50);
    48.         */    
    49.          
    50.        
    51.      
    52.           lcd_clear();
    53.          
    54.            //YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
    55.              lcd_draw_line(22,238,22,320,BLACK);    
    56.              lcd_draw_line(44,238,44,320,BLACK);
    57.              lcd_draw_line(66,238,66,320,BLACK);
    58.              lcd_draw_line(88,238,88,320,BLACK);
    59.              lcd_draw_line(110,238,110,320,BLACK);
    60.              lcd_draw_line(132,238,132,320,BLACK);
    61.              lcd_draw_line(154,238,154,320,BLACK);
    62.              lcd_draw_line(176,238,176,320,BLACK);
    63.              lcd_draw_line(198,238,198,320,BLACK);
    64.              lcd_draw_line(220,238,220,320,BLACK);
    65.              //-------------------------------------
    66.              //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    67.              lcd_draw_line(0,238,240,238,BLACK);    
    68.              lcd_draw_line(0,266,240,266,BLACK);
    69.              lcd_draw_line(0,293,240,293,BLACK);
    70.            
    71.              lcd_gotoxy(1,239);
    72.              lcd_putchar('Q',BLACK,WHITE);
    73.               lcd_gotoxy(4,239);
    74.              lcd_putchar('W',BLACK,WHITE);
    75.               lcd_gotoxy(7,239);
    76.              lcd_putchar('E',BLACK,WHITE);
    77.               lcd_gotoxy(9,239);
    78.              lcd_putchar('R',BLACK,WHITE);
    79.               lcd_gotoxy(12,239);
    80.              lcd_putchar('T',BLACK,WHITE);
    81.               lcd_gotoxy(15,239);
    82.              lcd_putchar('Y',BLACK,WHITE);
    83.               lcd_gotoxy(18,239);
    84.              lcd_putchar('U',BLACK,WHITE);
    85.               lcd_gotoxy(20,239);
    86.              lcd_putchar('I',BLACK,WHITE);
    87.               lcd_gotoxy(23,239);
    88.              lcd_putchar('O',BLACK,WHITE);
    89.               lcd_gotoxy(25,239);
    90.              lcd_putchar('P',BLACK,WHITE);
    91.              lcd_gotoxy(28,239);
    92.              lcd_putchar('(',BLACK,WHITE);  
    93.            
    94.              lcd_gotoxy(1,241);
    95.              lcd_putchar('A',BLACK,WHITE);
    96.               lcd_gotoxy(4,241);
    97.              lcd_putchar('S',BLACK,WHITE);
    98.               lcd_gotoxy(7,241);
    99.              lcd_putchar('D',BLACK,WHITE);
    100.               lcd_gotoxy(9,241);
    101.              lcd_putchar('F',BLACK,WHITE);
    102.               lcd_gotoxy(12,241);
    103.              lcd_putchar('G',BLACK,WHITE);
    104.               lcd_gotoxy(15,241);
    105.              lcd_putchar('H',BLACK,WHITE);
    106.               lcd_gotoxy(18,241);
    107.              lcd_putchar('J',BLACK,WHITE);
    108.               lcd_gotoxy(20,241);
    109.              lcd_putchar('K',BLACK,WHITE);
    110.               lcd_gotoxy(23,241);
    111.              lcd_putchar('L',BLACK,WHITE);
    112.               lcd_gotoxy(25,241);
    113.              lcd_putchar(';',BLACK,WHITE);
    114.              lcd_gotoxy(28,241);
    115.              lcd_putchar(')',BLACK,WHITE);
    116.            
    117.                lcd_gotoxy(1,243);
    118.              lcd_putchar('Z',BLACK,WHITE);
    119.               lcd_gotoxy(4,243);
    120.              lcd_putchar('X',BLACK,WHITE);
    121.               lcd_gotoxy(7,243);
    122.              lcd_putchar('C',BLACK,WHITE);
    123.               lcd_gotoxy(9,243);
    124.              lcd_putchar('V',BLACK,WHITE);
    125.               lcd_gotoxy(12,243);
    126.              lcd_putchar('B',BLACK,WHITE);
    127.               lcd_gotoxy(15,243);
    128.              lcd_putchar('N',BLACK,WHITE);
    129.               lcd_gotoxy(18,243);
    130.              lcd_putchar('M',BLACK,WHITE);
    131.               lcd_gotoxy(20,243);
    132.              lcd_putchar(',',BLACK,WHITE);
    133.               lcd_gotoxy(23,243);
    134.              lcd_putchar('.',BLACK,WHITE);
    135.               lcd_gotoxy(25,243);
    136.              lcd_putchar('?',BLACK,WHITE);
    137.              lcd_gotoxy(28,243);
    138.              lcd_putchar('!',BLACK,WHITE);
    139.            
    140.              lcd_gotoxy(7,1);
    141.               lcd_puts("typed text : ",BLACK,WHITE);
    142.              lcd_draw_rectangle(50,40,185,100,BLACK);
    143.            
    144.              lcd_gotoxy(20,10);
    145.               lcd_puts("Save text ",BLACK,WHITE);
    146.              lcd_draw_rectangle(158,155,236,185,BLACK);
    147.            
    148.    while (1)
    149.       {        
    150.            
    151.            
    152.              
    153.      
    154.       DDRA.0=1;        //-x
    155.       DDRA.1=0;        //y
    156.       DDRA.2=1;        //x
    157.       DDRA.3=0;        //-y
    158.       PORTA.0=0;
    159.       PORTA.1=0;
    160.       PORTA.2=1;
    161.       PORTA.3=0;
    162.      
    163.       y=read_adc(1);
    164.       y=y/4.26;  
    165.       itoa(y,stry);
    166.      
    167.        lcd_gotoxy(0,1);
    168.       lcd_puts("X= ",RED,WHITE);
    169.       lcd_puts(stry,RED,WHITE);
    170.      
    171.       DDRA.0=0;
    172.       DDRA.1=1;
    173.       DDRA.2=0;
    174.       DDRA.3=1;
    175.       PORTA.0=0;
    176.       PORTA.1=1;
    177.       PORTA.2=0;
    178.       PORTA.3=0;
    179.       x=read_adc(2);
    180.       x=x/3.19;  
    181.       itoa(x,strx);  
    182.    
    183.       lcd_gotoxy(0,0);    
    184.       lcd_puts("Y= ",RED,WHITE);
    185.       lcd_puts(strx,RED,WHITE);
    186.      
    187.         //-----------------------------------------------
    188.          lcd_gotoxy(j,3);    
    189.        
    190.           if(y<25 && y>19 && x==10 ){              
    191.           lcd_putchar('Q',BLACK,WHITE);
    192.            j++;
    193.          }  
    194.        
    195.          if(y<25 && y>19 && x>11 && x<15){              
    196.           lcd_putchar('W',BLACK,WHITE);
    197.           j++;
    198.          }
    199.        
    200.          if(y<25 && y>19 && x<19 && x>15){              
    201.          lcd_putchar('E',BLACK,WHITE);
    202.          j++;
    203.          }  
    204.        
    205.           if(y<25 && y>19 && x<23  && x>19 ){              
    206.           lcd_putchar('R',BLACK,WHITE);
    207.            j++;  
    208.          }
    209.        
    210.           if(y<25 && y>19 && x>23 && x<27){                
    211.           lcd_putchar('T',BLACK,WHITE);
    212.            j++;
    213.          }
    214.        
    215.          if(y<25 && y>19 && x>28 && x<32){              
    216.          lcd_putchar('Y',BLACK,WHITE);
    217.           j++;
    218.          }
    219.        
    220.           if(y<25 && y>19 && x>32  && x<37){              
    221.           lcd_putchar('U',BLACK,WHITE);
    222.           j++;
    223.          }
    224.        
    225.          if(y<25 && y>19 && x<41 && x>37){              
    226.           lcd_putchar('I',BLACK,WHITE);
    227.           j++;
    228.          }
    229.        
    230.          if(y<25 && y>19 && x<45 && x>41){              
    231.          lcd_putchar('O',BLACK,WHITE);
    232.          j++;
    233.          }
    234.        
    235.           if(y<25 && y>19 && x<49  && x>45 ){              
    236.           lcd_putchar('P',BLACK,WHITE);
    237.           j++;
    238.          }  
    239.        
    240.          if(y<25 && y>19 && x<41 && x>49){              
    241.           lcd_putchar('(',BLACK,WHITE);
    242.           j++;
    243.           }
    244.         //----------------------------------------------
    245.       }      
    246.   }    
    247.      
    248. void init()
    249. {
    250.  
    251. PORTA=0x00;
    252. DDRA=0x00;
    253. PORTB=0x00;
    254. DDRB=0x00;
    255. PORTC=0x20;
    256. DDRC=0xFF;
    257. PORTD=0x00;
    258. DDRD=0xFF;
    259.  
    260.  
    261. // Analog Comparator initialization
    262. // Analog Comparator: Off
    263. // Analog Comparator Input Capture by Timer/Counter 1: Off
    264. ACSR=0x80;
    265. SFIOR=0x00;
    266. // ADC initialization
    267. // ADC Clock frequency: 125.000 kHz
    268. // ADC Voltage Reference: AREF pin
    269. // ADC Auto Trigger Source: None
    270. ADMUX=ADC_VREF_TYPE & 0xff;
    271. ADCSRA=0x83;
    272. }
    273. [code]
     
    Last edited: May 22, 2015
Loading...