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 support@ccsinfo.com

18f4553 touchscreen

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








18f4553 touchscreen
PostPosted: Mon Sep 15, 2008 2:18 pm     Reply with quote

Hello, I try to use a glcd touchscreen with 18f4553. The touchscreen is connected to RA0,RA1,RA2,RA3, but does not work.

Have any one a library for the touchscreen ?

BUy
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Sep 15, 2008 2:28 pm     Reply with quote

There are some Touchscreen libraries available.

What compiler and version are you using?

Is the GLCD working?

The GLCD and touchscreen are two different things to the software...
Guest








PostPosted: Mon Sep 15, 2008 2:36 pm     Reply with quote

Hello the glcd are working.

The problem are with the touchscreen.

The compiler are CCS PCWHD 4.065

Thanks.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Sep 15, 2008 5:55 pm     Reply with quote

By the four listed connections, is this a 4 wire RESISTIVE touchscreen?
juanez



Joined: 15 Sep 2008
Posts: 2

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 7:21 am     Reply with quote

Yes, are resistive

http://www.circuit-ed.com/128x64-GLCD-BlWh-w-Touchscreen-P146C8.aspx
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 2:09 pm     Reply with quote

Hello,

Are you connecting the 4 output directly to your pic?
I have never used a resistive touchscreen, but I'm not sure that you can connect it directly to the analog input of your pic.
I suppose that you have to connect the 4 outputs to some resistors and a power supply to make voltage divider...

Good luck,
Franck.
Bcox



Joined: 09 Oct 2007
Posts: 17
Location: Windsor, CT

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 16, 2008 2:16 pm     Reply with quote

Hello,
I am using this exact LCD in a device that is going to production in the next few weeks. I will be happy to help as much as I can. Yes, you can attach the touch screen directly to the PIC. This is how i am driving it. I am leaving from work now but a few things to note:

Make sure you High Z the correct pin you are not using
Output high to one pin
output low to other pin on same plane
read ADC on last pin.

Read up on the links in the Circuit-ed site, and his TechBlog. Both will give you a good start.

I will be able to help you out a little more tomorrow.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 6:29 pm     Reply with quote

If you can make any use of it, here's some code I wrote for reading a touch screen using a PIC16F877. I'm making references to specific pin numbers, so it's important to be aware that the PIC is in the 40-pin DIP package. There are various setup items that are in the main() function, but context should make it clear what's needed. The routine here must be called repeatedly, at some fairly rapid rate. 1KHz ought to work well. Note that there is a procedure here which checks for whether the user is touching the screen; if not, the X and Y coordinates won't be changed. It would be easy to add a "no contact" flag, but my application didn't need it.

I shortened my original routine to remove a lot of irrelevant stuff, so if this isn't quite a workable piece of code, I claim to have been a bit careless in editing. It did work!


Code:

// 10-bit A/D is in "left justified" mode where the top 8 bits will be in adresh. We ignore the lower 2 bits.
// Y coordinate is read from resistance between PORTA.3 (pin 5) and PORTB.4 (pin 37), at PORTA.1 (pin 3)
// X coordinate is read from resistance between PORTA.1 (pin 3) and PORTB.3 (pin 36), at PORTA.3 (pin 5)

int hold_y, ypos, xpos;

void handle_ad(void)
{   
      static int ad_state, hold_y;

      if (++ad_state >= 6)
         ad_state = 0;

      switch(ad_state)
      {
         case 0:
            ypos = hold_y;
            xpos = adresh;                           // Read X coordinate on AD ch 3

            adcon0 = 0x81 + (1 << 3);            // Set up ch 1
            bit_clear(trisa, 3);                  // Make pin 5 an output (low)
            bit_clear(trisb, 4);                  // Make pin 37 an output
            bit_set(portb, 4);                     // Pin 37 is high
            bit_set(trisa, 1);                     // Make pin 3 an input (AD ch 1)
            bit_set(trisb, 3);                     // Make pin 36 high-Z
            break;

         case 1:
            bit_set(adcon0, 2);                     // Start A/D for ch 1
            break;

         case 2:
            hold_y = adresh;                           // Read A/D for ch 1 (vertical)

            adcon0 = 0x81 + (3 << 3);            // Read ch 3 for first time
            bit_clear(trisa, 1);                  // Make pin 3 an output (low)
            bit_clear(trisb, 3);                  // Make pin 36 an output
            bit_clear(portb, 3);                  // Pin 36 is low
            bit_set(trisb, 4);                     // Pin 37 is high-Z
            bit_clear(rbpu);                        // Port B pullups on, this pulls up 37 and thus 5 also
            bit_set(trisa, 3);                     // Make pin 5 an input (AD ch 3)
            break;

         case 3:
            bit_set(adcon0, 2);                     // Start A/D for ch 3
            break;

         case 4:
            if (adresh > 0x80)                     // Ch 3 reading
            {                                                //No contact, force repeat of states 3 and 4
               ad_state = 2;                           // Next state is 3, after increasing ad_state
               break;
            }

            bit_set(portb, 3);                     // Touchscreen is active, pin 36 is high
            bit_set(rbpu);                           // Port B pullups off
            break;

         case 5:
            bit_set(adcon0, 2);                     // Start A/D for ch 3
            break;
      }

}
juanez



Joined: 15 Sep 2008
Posts: 2

View user's profile Send private message

PostPosted: Tue Sep 23, 2008 10:09 am     Reply with quote

I try this code but the CCS compiler give me errors:

Undefined identifier addresh,adcon 0 ,,,etc

I need to learn the touch control resistive. I connected the 4 wires to the portA. I conected the touch sensor to RA0,RA1,RA2,RA3.

http://www.jvmbots.com/viewtopic.php?t=684
Here are the same but in mikrobasik, I need a library in C, for use in CCS.

Thanks.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Sep 23, 2008 11:18 am     Reply with quote

Here are some things that you need to do:

1. Understand how a touch screen works. There is one resistive panel for the X direction and one for the Y direction. Basically we apply a controlled voltage to one side of the X and Y resistive panels (in his example these are PIC pins B3 and B4). The voltage outputs of each panel go to separate A/D converter inputs(pins A1 and A3) to "measure" the output voltage which, in turn, indicates where the panel is being touched. The output of both panels taken together gives you the coordinates of the touch point on the panel.

2. Read and understand what his code is trying to do.

3. Add the statement #device ADC=10 near the beginning of your code to make sure the ADC is in 10 bit mode.

4. Define the registers that are referenced in his sample code. Here are examples of how it is done.

Code:

//define location of A/D control register
#BYTE ADCON0 = 0xFC2H

//define location of ADRESH control register
#BYTE ADRESH = 0xFC4H


You will need to read the PICF4550 (not 4553) data sheet page 66 to get the proper addresses for the remaining defines.

5. As mentioned earlier, his comments indicate he is using Pins A3, B4, A1, and B3 so, for his code to work, you will either need to use his pins or change them to match your requirements.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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