Thursday, April 21, 2011

Interfacing Touch Screen with microcontroller

Please Read : This article was posted by me a long time ago, I am not able to monitor the comments regularly. So, if you need my help regarding any article, please write to me at dmehta17@gmail.com . I will try to answer the queries as quickly as possible.  Also, please don't ask me for the code for any other controller except LPC2148, because I only have code for that controller. For any other controller, you will have to develop the code on your own based on the algorithm explained here. If you've created such code, I request you to share it with me via e-mail. I will publish it here with full credits to its original author.

--------------------------------------------------------------------------------------------------------------

I've always wanted to add something new to my projects. That's why in the 7th semester, when I saw a touch screen just lying in my college, I decided to go for it. Touch screens add an X-factor to otherwise ordinary projects. They are fun to use and more important, their applications are endless. In this article, I will explain how to interface a 4-wire resistive touch screen with microrocntrollers.

Resistive Touch Screens
Of all the kinds of touch screens available, Resistive touch screens are easy to interface, cheap and they have fair sensitivity.Resistive Touch screens are simply transducers. This touch screen has a resistive layers in both X and Y directions. According to the position of the touch, Their X channel and Y channel resistance changes. So, what we have to do is we have to determine the X and Y Channel resistance to get the position of the touch in terms of X and Y co-ordinates.
Here is an Image of simple resistive touch screen. 
 How To Interface Touch Screen with Microcontroller
To Interface Resistive touch screen with a microcontroller, you will need a microcontroller with inbuilt Analog-to-Digital converter having two or more channels. This is needed because, the touch screen will provide data in terms of an analog voltage on two different pins, using which, we have to determine position of the touch. Also, ADC input pins of the microcontroller should be configurable as General Purpose I/O (GPIO). As shown, in the figure, the touch screen has total of 4 wires coming out. Pin configuration is shown in the fig. To read the position of the touch, we have to first read touch position sequentially i.e. first read X position and then read the Y position. To do this, connect X1 and Y2 pins of touch screen to ADC multiplexed GPIO pins of the controller. And connect X2 and Y1 pins of touch screen to simple GPIO pins of the microcontroller.  


 
 
  
Now first, we have to read X position of the touch, for that, u have to program the pin X1 as Logic high (+5v or +3.3v in some cases) and configure pin X2 as logic low (GND). Now, as I told earlier, touch screen contains a resistive layer in both direction. So, when we apply +5v and GND to its pins, it will create a voltage gradient in X direction. Voltage on the X channel will vary according to the X position of the touch. We have to measure this voltage to determine the X position.For that, configure Y2 as ADC input and configure Y1 to high impedance state (in most controller, configuring Y1 as "Input" will work). Then read the value from the ADC. It will give the relative value of the touch. For example, if you have an 8-bit ADC in the controller, when you touch near the right most end, it will give you a value of 255 and when you touch near the left most end, it will give you a value near 0. After reading X position, you will have to read the Y position. For that, configure Y2 as Logic High, Y2 as Logic Low, and X1 as ADC input and X2 as High Impedance state. After that, whole procedure is the same. 


This way, you can interface touch screens with microcontrollers and add something new to your projects. I made a "Touch Screen Calculator" using the LPC2148 microcontroller. Below is the video of the Touch screen Calculator in action. If you need any help regarding this or have any suggestion/feedback, then write a comment here or mail me at dmehta17@gmail.com or you can connect with me on facebook at "http://www.facebook.com/damehta"


 


Here is the 'C' code I've created for reading X and Y positions from the touch screen. The code is for Phillips LPC2148 controller.I've crated two functions : "xcoordinate" and "ycoordinate".When called, functions wait for a touch and when touch screen is touched, returns X and Y co-ordinate respectively.

int xcoordinate(void)
{
 int x;
 PINSEL0 = (PINSEL0 & 0x3FFF3FF0) | 0x00000005; // Configure pins for touch screen
 PINSEL1 = (PINSEL1 & 0xC3FFFFFF) | 0x10000000;
 IO0DIR =  (IO0DIR &  0xDFFF7F7F) | 0x00008080;

 IO0SET = IO0SET | 0x00000080;     // Set pin to '1'
 IO0CLR = IO0CLR | 0x00008000;    // Set pin to '0'

 AD0CR = ( AD0CR & 0xFFD00000 ) | 0x00200208 ;  // Start the ADC

 while(1)
 {
   delayms(10);
   AD0CR = ( AD0CR & 0xF8FFFFFF ) | 0x01000000 ;

 xchkadc:

   x = AD0DR3 & 0x80000000 ;

   if(x == 0x80000000)  // Check if A-D conversion is complete
    {
     
      x = 0x00000000;
      x = AD0DR3 & 0x0000FFC0;
      x = x >> 6;
      x = x & 0x000003FF;
      if(x <= 10)
      {
        goto xexit;
      }
     
      AD0CR = AD0CR & 0xF8FFFFFF;
      return x;     // return the value of touch in x direction
     
    }

   goto xchkadc;

  xexit:  
  AD0CR = AD0CR & 0xF8FFFFFF;  
  }
  return 0;
}

int ycoordinate(void)
{
 int y;

 PINSEL0 = (PINSEL0 & 0x3FFF3FF0) | 0xC0000005;    // Configure pins for touch screen
 PINSEL1 = (PINSEL1 & 0xC3FFFFFF) | 0x00000000;

 IO0DIR = (IO0DIR & 0x9FFFFF7F) | 0x60000000;

 IO0SET = IO0SET | 0x40000000;    //// Set pin to '1'
 IO0CLR = IO0CLR | 0x20000000;    //// Set pin to '0'

 AD1CR = (AD1CR & 0xF0D00000) | 0x00200220 ;    //// Start the ADC

 while(1)
 {

  delayms(10);
  AD1CR = ( AD1CR & 0xF8FFFFFF ) | 0x01000000 ;

   ychkadc:

   y = AD1DR5 & 0x80000000 ;

   if(y == 0x80000000)    // Check if A-D conversion is complete
    {
     
      y = 0x00000000;
      y = AD1DR5 & 0x0000FFC0;
      y = y >> 6;
      y = y & 0x000003FF;
      if(y <= 10)
      {
        goto yexit1;
      }
     
      AD1CR = AD1CR & 0xF8FFFFFF;
      return y;            // return the value of touch in y direction
     
    }

   goto ychkadc;

   yexit1:
  
    AD1CR = AD1CR & 0xF8FFFFFF;
  }

 return 0;
}

100 comments:

  1. cool but how could i do it with an avr.......
    can u go in detail

    ReplyDelete
  2. @shyam....
    yeah, definitely u can do that. Tell me which controller are u using.

    ReplyDelete
    Replies
    1. Great job......really helpful......Thanx.......
      cud u show me hw 2 interface with atmega 32 and also provide the details for your touchscreen calculator...

      Delete
    2. can i use avr atmega8l

      Delete
  3. well ineed to know which software i should use to do programming paresh

    ReplyDelete
  4. @ above :
    Well, it depends on you. If you're using AVRs, you can use AVR Studio. If you're using ARM controllers like me, you can use SCARM or Keil also......

    ReplyDelete
  5. how to print a character in a touch screen?

    ReplyDelete
  6. @Benedict Maxwell
    You can't display anything on the touch screen....
    for that, I have fixed the touch on top of a Graphics LCD.....

    ReplyDelete
  7. how to feed information into the touch screen....

    ReplyDelete
  8. @Hearthacker

    You don't have to feed any data to touch screen. As I mentioned earlier, Touch screen is a passive resistive sensor. YOu have to get the value by measuring the resistance between two nodes.

    ReplyDelete
  9. is dis same fr atmega series of controllers??

    ReplyDelete
  10. @Prash : the procedure remains same for all the controllers, but the code I have written is for LPC2148 controller. For ATMega series, code will be somewhat different......

    ReplyDelete
  11. Will the programming for PIC microcontroller be easier than for LPC2148?...and how to display nos of the calculator on the lcd?

    ReplyDelete
  12. sir how do we interface a glcd with a microcontroller?

    thank u
    sahil

    ReplyDelete
  13. @Anonymous : That depends on which one you use most. I haven't tried PIC controllers yet. But if you are programming in 'C'. then everything is almost same.

    ReplyDelete
  14. @Anynomous and Sahil : For displaying the contents on the Graphics LCD, you have to interface LCDs with controller. Also, interfacing depends on which type of LCD controller the LCD has. KS0108 is the most famous GLCD controller and many interfacing libraries are available for different microcontrollers online.

    ReplyDelete
  15. Hello,

    This is similar to what i have to make... I have to program a touch screen with a php application using a microcontroller. What would be your opinion on doing this? What would be you approach?

    ReplyDelete
  16. @Raquel : First, make a code to interface touchscreen with microcontroller. Then you can use your PC-side PHP application to communicate with microcontroller through either serial port or USB port and get the touch data.

    ReplyDelete
  17. can i do it with PIC 18 family ???

    ReplyDelete
  18. Can I use here 8051 Microcontroller...??

    ReplyDelete
  19. @FiDO : You can do it with PIC18 family, but you will have to find a controller from PIC18 series which has 2 GPIO/ADC configurable lines and enough free GPIO lines to interface graphics LCD. I don't have the PIC18 code for the that, but you can transform this code to PIC18.

    ReplyDelete
  20. @Bimal : If you're talking about simple 8051 controllers (e.g. AT89C51 or AT89S51), you can't interface the touchscreen with them.

    ReplyDelete
  21. Is there a special external adc converter to interface with controller ...
    give me other mc that i can use....
    I m having a project of resistive touch screen interfaced with mc.and to have keypad on touchscreen.so can u suggest me which mc i can use..and also adc converter..

    ReplyDelete
  22. @Bimal : if you want to use external ADC, use dedicated touch screen controllers instead. You can find them on Atmel or Microchip site. Also, I suggest you to choose controller which has internal ADC as interfacing touch screen will be easier that way. Such controllers are LPC21xx series (Phillips), Atmel ATMega series and PIC24/ PIC32 series....

    ReplyDelete
  23. this is cool can u help me how to interface touch screen to pic 18f452

    ReplyDelete
    Replies
    1. First, try some codes for accessing ADCs of PIC18F452.... Then get a touch screen and go through the procedure I have written to get position of touch on the touch screen.

      Delete
  24. would u like to give me (assembly or c)code that you have written for phillips,same for atmega16??..

    ReplyDelete
    Replies
    1. Hi.. Go through the article again. I have given the code to access the touch screen in the article. But, you will have to modify it for ATMega16

      Delete
  25. Hi,
    That was a good one. infact a great for beginner. have you tried for capacitive???

    ReplyDelete
    Replies
    1. Thank you..
      No, I haven't tried this for capacitive touch screen, but I think that it will be more or less similar to this one. The only main change will be that there will be some additional circuitry that will convert change in the capacitance between two plates into respective voltage change. After that, everything will be same.

      Delete
    2. Hi Mehta,

      I Googled for Touch Screen Interfacing and i found your blog it was good. but could u share some snaps regarding interfacing etc......
      maddy_xyz420@yahoo.com

      Delete
  26. Hi Mehta,

    I Googled for Touch Screen Interfacing and i found your blog it was good. but could u share some snaps regarding interfacing etc......
    maddy_xyz420@yahoo.com

    ReplyDelete
    Replies
    1. which kind of snaps do you want ?

      Delete
    2. the interfacing part......
      and the x,y cordinate position.......
      and how you got that calc app on the screen.... etc.......

      Delete
    3. Like I have mentioned in the post, I have used a monochrome Graphics LCD for displaying the calculator. I have put the transparent Touch-Screen on the top of the LCD, so it seems that they both are same. Also, I have posted the code for reading the X and Y position of touch screen, which will work on LPC2148 microcontroller.

      Delete
  27. Hi gud wrk..
    I am also searching for this. And i also want to interface with PC i.e with this program i will get co-ordinates.In place of mouse to PC i want to use this as connecting the output of the microcontroller to PC by interfacing with USB.
    Totally what the theme is i want to operate the PC with touch screen not with mouse i am researching about that..
    Can u help me??
    For that what i have to modify in code?
    Can u mail me the details at saranyasai.s@gmail.com or else post here. It is important me. Please reply..
    Thank u..

    ReplyDelete
  28. Hi,
    Why can't touch screen be interfaced with 8051 family of microcontrollers?
    We could use an external ADC for it like ADC0809. Wont it work?

    ReplyDelete
  29. @SAM : For interfacing touch screen, you need to create voltage gradient in one direction (for example in X-direction ) and read the voltage in other direction ( Y- Direction ) and repeat this in other direction. For creating this voltage gradient, you have to use two microcontroller lines as GPIO (means you can set them as either '0' or '1' ) and other microcontroller line as ADC input. Now reading voltage in other direction needs this to be reversed, so microcontroller lines that acted as GPIO, needs to act as ADC input and other lines need to act as GPIO. External ADCs like ADC0809 doesn't provide this type of ADC/GPIO multiplexed functionality, so you can't use touchscreen with external ADCs.

    ReplyDelete
  30. Right, Got the concept...Thanks..
    You can stay in touch with me on: www.facebook.com/embeddedsystems

    ReplyDelete
  31. Hi dhaval i want to make touchscreen display which can replace notice boards in d collgs n i dnt hv ny informtn regarding dis n dis is my final yr prcjt n der is only 1 month to go so plz tell how i shld start n wat steps i shld follow to accomplish it?? N plz post as early as possible or can send me d details at vachipatel_24@yahoo.com n if possbl plz send me today so dat i can cmplt within reqrd time
    Thanx in advance
    Waiting for u quicker response

    ReplyDelete
  32. @Anonymous : If you are thinking of notice boards, on college, I don't think touch screen is an appropriate solution as the size of notice boards will be very large. Also, first of all, decide the type and size of the LCD that you want to use i.e. monochrome LCD or RGB color LCD. It depends on the type of content you want to display on the noticeboard. Based on that, decide which controller you want to use and in the last, select appropriate sized touch screen.

    ReplyDelete
    Replies
    1. I wanna to use monochrome lcd n size of lcd can b dat of mbl phn.....n i jst want to create menu on that display so when i touch dat menu its content are opened

      Delete
  33. I decide to use monochrome lcd now of which company n which controller n touch screen also d size of dis display shld b dat of mbl phn n i jst wanna to display menu so whnevr i touch it its contents r displayed

    ReplyDelete
    Replies
    1. @Anonymous : with the specifications you have given, I suggest you use a KS0106 based graphics LCD. Also, you can use either PIC32 controller or ATMega controller depending on your familiarity with either one. After that, try to interface the GLCD with the controller and try to display the menu that you wanted to. Now for touch screen, I think you should use small sized touch screens that are used in mobile phones. They are cheap and easily available in various sizes. So, buy one touch screen with the same size as the LCD and follow the steps I have mentioned in the article to interface the touch screen.

      Delete
  34. Thanks dhaval very much

    ReplyDelete
  35. hello dear
    i want to do this with Atmel 8085 microcontroller...
    can u plz guide me ?

    ReplyDelete
  36. @Ruler : Refer to my earlier comment about whether 8051 can be used for interfacing touch-screen or not. The same applies for 8085 too. It should answer your question.

    ReplyDelete
  37. Hi, Is this thing only work with 32-bit MCU's only or with all the things?

    ReplyDelete
  38. It is not necessary to use 32-bit microcontroller. You can use any controller that has all the features that I have mentioned in the article. Though you will have to change the code according to your microcontroller.

    ReplyDelete
  39. i was trying to interface touchscreen with at-mega16....
    i m not getting the desired output...
    here is what i am doing after referring your blog..

    while(1)
    {
    sbi(DDRA,x1); // pin where x1 is connected as o/p
    sbi(PORTA,x1); // logic 1/5v on x1
    sbi(DDRA,x2); // pin where x2 is connected as o/p
    cbi(PORTA,x2); // Gnd/Logic 0 on x2
    cbi(DDRA,y1); // pin where y1 is connected as i/p(high impd)
    x = readADC(4); //Function will read an analog voltage form y2
    _delay_ms(100);
    sprintf(line,"X:%03d",x);
    lcd_display(line,LINE1);

    sbi(DDRA,y1); // pin where y1 is connected as o/p
    sbi(PORTA,y1); // logic 1/5v on x1
    sbi(DDRA,y2); // pin where y2 is connected as o/p
    cbi(PORTA,y2); // Gnd/ logic 0 on y2
    cbi(DDRA,x2); //pin where x1 is connected as i/p(high impd)
    y = readADC(1);
    _delay_ms(100);
    sprintf(line,"Y:%03d",x);
    lcd_display(line,LINE2);
    }

    PORTA is an ADC PORT
    x1 is pin 0
    x2 is pin 1
    y1 is pin 2
    y2 is pin 3

    ReplyDelete
  40. what is the output that you are getting ?

    You can do one thing, first, remove the code to chk Y axis, and read the voltage with multimeter on the ADC pin. Something like this :
    ---------------------------------------------------------------
    sbi(DDRA,x1); // pin where x1 is connected as o/p
    sbi(PORTA,x1); // logic 1/5v on x1
    sbi(DDRA,x2); // pin where x2 is connected as o/p
    cbi(PORTA,x2); // Gnd/Logic 0 on x2
    cbi(DDRA,y1); // pin where y1 is connected as i/p(high impd)

    while(1)
    {
    x = readADC(4); //Function will read an analog voltage form y2
    _delay_ms(100);
    sprintf(line,"X:%03d",x);
    lcd_display(line,LINE1);
    }

    ReplyDelete
  41. TRISA1=0; __delay_ms(1); X1=1; // 5V
    TRISE0=0; __delay_ms(1); X2=0; // GND

    TRISE1=0; __delay_ms(1); Y1=0; //GND
    TRISA2=1; __delay_ms(10); xm=measure(2); //read adc Y2


    //measure y
    TRISE1=0; __delay_ms(1); Y1=0; //GND
    TRISA2=0; __delay_ms(1); Y2=1; //5V

    TRISE0=0; __delay_ms(1); X2=0; //GND
    TRISA1=1; __delay_ms(10); ym=measure(1); // read adc X1



    untouched time x=0,y=0

    when touch max x value=350 max y value=400
    when touch min x value=20 min y value=20

    ReplyDelete
    Replies
    1. @Anonymous : That's it...you have interfaced the touchscreen. You can make a function for it. Also, whenever you read the X value or Y value, subtract 20 from the value to get the absolute value.

      Delete
  42. in india from where i can buy touchscreen LCD? -Nishant

    ReplyDelete
  43. @Nishant : You can get Touchscreens from any big mobile repair stores. Many of the touchscreens used in the mobile phones are resistive touchscreen.

    ReplyDelete
    Replies
    1. Thank you for ur valuable one.
      Will u please mail me all the details for that Project?
      1.How to draw the Lines or pic in Touch Screen?
      2.What Touch Screen hav u Used?
      Then Etc...,
      My Mail Id ; amanikandan.be89@gmail.com Plese Urgent.
      Thank You,
      Manikandan A

      Delete
    2. For drawing lines on the GLCD, I used a library which provided a function using which, I could turn any pixel on or off. By using this library, I was able to draw lines / display picture.

      As I have mentioned in the article, I've used Resistive Touch Screen for this project.

      Delete
    3. This is a great project. Thank you for a thorough explaination. Can you please to provide details on how to draw graphics on a GLCD? I only had experience in programming a character LCD, not a GLCD before. I could not find any information on the web for a beginner like me when it comes to GLCD. Thank you very much in advance.

      Delete
  44. Excellent!!
    is there an arduino library or code that I can have for this?? If yes, please send to rajvignesh@edindia.co.in

    ReplyDelete
    Replies
    1. I have the code for ARM7 based controller. I am sure that you will be able to find the library for this on Internet...

      Delete
  45. sir ,
    m using atmega16 can u please tell me whole circuit.and how to give clock to touchscreen.Thanx

    ReplyDelete
    Replies
    1. Since this is a Resistive touch screen, you don't have to give clock to the touch screen.

      Delete
  46. pls give me details about glcd and is the relation between touch and glcd

    ReplyDelete
  47. please send the codings of 4wire touch screen interface with atmega 16 controller

    my mail id
    selvam27193@gmail.com

    ReplyDelete
    Replies
    1. Hi, I haven't tried this with ATMega16, but the core part remains the same. All you have to do is make your own routines for ADC interfacing.

      Delete
  48. hi sir,

    i am very impressed with this articles and your replies,i am going to try with ARM controller LPC2119/2129.i need circuit diagram to interface with LPC 2119 and full details about this project and if you have any other projects like this,send the details to mail id( nataraj87@gmail.com ) please do the needful.

    Thank you

    ReplyDelete
  49. sir how do we interface touch screen with avr atmega16 microcontroler??

    ReplyDelete
    Replies
    1. Here is a very interesting project that shows how to interface touch screen with AVR

      http://www.sparkfun.com/tutorials/139

      Delete
  50. plz i want to know how hardware are connected "diagram plz "

    ReplyDelete
  51. plz give me code for 4 wire resistive touchscreen to interface with avr atmega8L

    ReplyDelete
    Replies
    1. Here is a very interesting project that shows how to interface touch screen with AVR

      http://www.sparkfun.com/tutorials/139

      Delete
  52. This comment has been removed by the author.

    ReplyDelete
  53. Hi i actually interfaced 4 wire resistive touch screen with 8051. I used an external ADC0804 for analog to digital conversion, Mux-demux 74HC4053 for touch screen configuration as tabulated at above and AT89C51 for processing. I am about to complete my final semester project on "wireless home automation with touch screen interfacing" though there is no graphical LCD interfaced. Because the c51 used can not provide the proper refresh rate for graphical LCD. If any one want this project as well as code then u can contact me "saugatdai@gmail.com". Thank you D.A.M for knowledge about touch screen!

    ReplyDelete
    Replies
    1. You are welcome...

      Maybe you can take it a step ahead and build it on AVR / PIC / ARM based controllers. It can be very useful in learning how to interface GLCD.

      Delete
    2. @anonymous
      hai it a great work am to working on the touch screen interface with c51 an d i have left only two day to complete so can you send me the details of the "wireless home automation with touch screen interfacing" that you have done so that it will be very useful for me please kindly mail me at "rajkamall007@gmail.com" today or as soon as possible please thank you

      Delete
  54. sir can u tell me how may i know where i have to touch on screen for special function.how can diagram display on touch screen so that we can identify which buten i have to press for switch on device or off device ..........could u please send me detail of circuit diagram and other document at "rjkumar221@gmail.com" its urgent sir i want to make project for my final year.

    ReplyDelete
  55. sir,i need to a capacitive touch screen.then what will be the reading procedure for that?

    ReplyDelete
  56. i want to interface with pic16f877a so plz suggest me and also send me some materials if u have

    ReplyDelete
  57. would u please mail me the circuit diagram of lpc2148 interfacing with glcd and touchscreen,along with the project details. Thanks in advance
    Heres my id :kumaruday691@hotmail.com

    ReplyDelete
  58. so u r actually simultaneously need both x and y coordinates,......but actually sequentially reading both coordinates.......how's that possible....?????....will it be dependent on the clock.....i mean how much time is required to calculate both the coordinates.....so that they are available simultaneously both ports...

    ReplyDelete
  59. cool but how could i do it with atmega32.......

    ReplyDelete
  60. could i do it with atmega32....... pl send me code at shailesh4440@yahoo.co.in


    ReplyDelete
  61. Hi thank you for the post and also i want to know what is high impedence state and also this touch screen will give analog output right should i use ADC to read that and where the pins are connected can you please reply me at the earliest.

    ReplyDelete
  62. I am using at89c51 which requires external ADC. i want to know which pin is connected to what or please explain me what is high impedance state.
    Thank you.

    ReplyDelete
  63. my project is image based password authentication using touch screen .i googled and find all the hardware requirement like 4wire resitive touch screen,graphical lcd,steeper motor with driver ,buzzzer ,pic16f72 microcontroller ,led.how to start these thing to interface.

    ReplyDelete
  64. can u plz give me the C code of interfacing touchscreen with glcd using atmega16?i'm unable 2 undrstand the code you have written

    ReplyDelete
  65. Sir, i've interfaced 4 wire resistive touch screen with atmel 8535 and sending the adc values to terminal but i am not able to get proper values.. it shows alphabets, numbers and symbols..
    Please help..
    here is ma code for touchsccreen:

    #include
    #include
    #include
    #define y1 PA3
    #define x2 PA2
    #define y2 PA1
    #define x1 PA0

    void USARTInit(unsigned int);
    char receive();
    void transmit(char data);
    void ADC_init(void);
    unsigned int ADC_read(unsigned char);

    uint16_t adc_result0, adc_result1;

    char int_buffer[10];

    int main()
    {


    char data;

    /*First Initialize the USART with baud rate = 9600bps

    for Baud rate = 9600bps
    UBRR value = 95
    */

    USARTInit(95);
    ADC_init ();
    //Loop forever
    while(1)
    {
    //Read X

    DDRA |= (1<>8);

    /*Set Frame Format


    >> Asynchronous mode
    >> No Parity
    >> 1 StopBit
    >> char size 8

    */

    UCSRC=(1<<URSEL)|(3<<UCSZ0);


    //Enable The receiver and transmitter
    UCSRB=(1<<RXEN)|(1<<TXEN);


    }


    //This function is used to read the available data
    //from USART. This function will wait untill data is
    //available.
    char receive()
    {
    //Wait untill a data is available
    while(!(UCSRA & (1<<RXC)))
    {
    //Do nothing
    }

    //Now USART has got data from host
    //and is available is buffer

    return UDR;
    }


    //This fuction writes the given "data" to
    //the USART which then transmit it via TX line
    void transmit(char data)
    {
    //Wait untill the transmitter is ready
    while(!(UCSRA & (1<<UDRE)))
    {
    //Do nothing
    }

    //Now write the data to USART buffer

    UDR=data;
    }





    void ADC_init(void)
    {
    ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF
    ADMUX |= (1 << ADLAR);
    ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // Enable ADC and set Prescaler division factor as 128
    }

    unsigned int ADC_read(unsigned char ch)
    {
    ch = ch & 0x07;
    ADMUX =(1<<REFS0)|ch;
    ADCSRA|=(1<<ADSC); // start conversion
    while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
    ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it
    return (ADC);
    }


    ReplyDelete
  66. can we interface AT89S52 with a 4 wire resistive touch screen by any means (prefer it to be cheap)....

    ReplyDelete
  67. can any one help me pls how can i connect touch screen with my PIc18F97J60 controller.is it possible to interface.if yes i want a source code for that.pls guys help me out
    kindly waiting for your reply


    ReplyDelete
  68. can i interface capacities touch screen with pic ????

    ReplyDelete
  69. Great Admin this stuff is nice!!
    Touchscreen

    ReplyDelete
  70. can anyone tell me how to interface the capacitive touchscreen ???

    ReplyDelete
  71. hiii
    i want to interface touch screen to avr 328p controller using i2c pins can you help me.

    ReplyDelete
  72. hii,
    i want to Ft5426dq8 capacitive screen code.do you know capacitive touch ?????

    ReplyDelete