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

Interfacing ADS7843

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



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

Interfacing ADS7843
PostPosted: Tue Feb 22, 2011 8:52 pm     Reply with quote

Hello all, I am using TFT with touchscreen and trying to readout the coordinates using ADS7843, but i don't often get the exact point. I am reading it every second using timer. I am using PIC18F4620 clocked at 4 Mhz. Here is the code i use.

Code:
void read_touch(void)
{
int16 X = 0, Y = 0,temp=0;

         SetFontFgColor(RED); SetFontBgColor(WHITE);
         sprintf(str,"INT");
         PrintASCII(150,20,str,0X05);   

         CS_TRIS=0;
          delay(10000);
          strt();
          delay(2);
          WriteCharTo7843(0x90);
          X = ReadFromCharFrom7843();
         temp=0;
          delay(2);
          WriteCharTo7843(0xD0);
          delay(2);
          Y = ReadFromCharFrom7843();

            X=X/6.25;
            Y=Y/8.33;
         if(Y)   
         {
            X=X-320;
            Y=Y-240;
         sbitt=1;
            X=X*(-1);
            Y=Y*(-1);
            xX=X;
            xY=Y;
         }
         CS_TRIS=0;

}

void delay(int16 i)
{
while (i--);
}



void WriteCharTo7843(int8 num)
{
int carry=0x80,CYC;

   unsigned char count = 0;
   
   output_low(PIN_B1); // DCLK

   for (count = 0; count <8; count++)
   {
      CYC=carry & num;
      num <<= 1;
      if(CYC)
      output_high(PIN_B2); // DIN
      else
      output_low(PIN_B2); // DIN

      output_low(PIN_B1); // DCLK
      delay_cycles(5);
      output_high(PIN_B1); // DCLK
      delay_cycles(5);
    }
}

int16 ReadFromCharFrom7843 ()
{
    unsigned char count = 0;
    int16 Num = 0;
    for (count = 0; count <12; count++)
    {
          Num <<= 1;
      output_low(PIN_B1); // DCLK
      delay_cycles(5);
      output_high(PIN_B1); // DCLK
      delay_cycles(5);
         if(DOUT) Num++;
    }
    return(Num);
}


void strt(void)
{
output_low(PIN_B1); // DCLK
output_high(PIN_A4); // CS
output_high(PIN_B2); // DIN
output_high(PIN_B1); // DCLK
output_low(PIN_A4); // CS

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 23, 2011 4:46 pm     Reply with quote

I don't have this chip (ADS7843) and I don't have any experience with it,
but I quickly wrote this driver after looking at the data sheet. It seems
more likely to work than your driver. I set the mode byte to 0x90
because that's what you used. I don't know if it's correct for your
hardware. You need to decide if it's correct.
Code:

#include <18F4620.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

#define ADS7843_CS  PIN_C2

#define ADS7843_MODE  0x90   

//----------------------------------------
// Send the mode byte to the ADS7843 and then
// read the 12-bit result.
int16 ads7843_read(int8 mode)
{
int8 lsb, msb;
int16 retval;

output_low(ADS7843_CS);
spi_write(ADS7843_MODE);
delay_us(2);       // Tacq delay time
msb = spi_read(0);
lsb = spi_read(0);
output_high(ADS7843_CS);

retval = make16(msb, lsb);  // Combine bytes into 16 bit word
retval >>= 4;     // Right-justify the 12-bit result
return(retval);
}

//--------------------------------------
void ads7843_spi_init(void)
{
output_high(ADS7843_CS);   // Inactive state

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4);

delay_ms(10);
}

//======================================
void main(void)
{
int16 result;

ads7843_spi_init();

while(1)
  {
   result = ads7843_read(ADS7843_MODE);
   printf("%LX \n\r", result);
   delay_ms(500);
  }

}
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Wed Feb 23, 2011 10:23 pm     Reply with quote

Thank you PCM Programmer, For your information....I am using this board
http://topwaydisplay.com/Pub/Manual/TCB7843-Manual-Rev0.1.pdf
and what about the CLOCK, DATAIN, BUSY PINS ? are they not required?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 23, 2011 11:07 pm     Reply with quote

The program that I posted uses hardware SPI, so you need these
connections between the two boards:
Code:

PIC                  ADS7843 board

SCK  PIN_C3  ---->   DCLK  pin 3

SDI  PIN_C4  <----   DOUT  pin 7

SDO  PIN_C5  ---->   DIN   pin 5

\CS  PIN_C2  ---->   \CS   pin 4

GND  pin 12  -----   Vss   pin 10

Also, both boards should have a Vdd voltage of +5v.

I don't think the BUSY signal is needed. You don't have to connect it
to the PIC.
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Fri Feb 25, 2011 5:33 am     Reply with quote

Dear PCM Programmer
Thanks a lot and it solved my problem. I do have another question for you..
I use this TFT
http://www.topwaydisplay.com/Pub/Manual/LMT057DNAFWU-AAA-Manual-Rev0.3.pdf
Everything works fine. But I do face 2 problems.

1) I am trying to set a bigger font size. But it never works. I just have 8x8 font size.
2) I have a routine to display a picture of 32x32 size, but how should i make the same routine to display a 16x16 picture. I modified the code and successfully written one on my own to display it, but it takes lot of time as it draws pixel by pixel. But the routine that already exists uses memory mapping and so it does not take much time. Please advise.
Code:

void ShowBMP160(int32 X,int32 Y)
{   
   uchar i,j,k,Buffer[5];
   int16  p;
   int32 addr;
                     // Display RAM pointer
   addr=Y*5;            //
    addr=addr<<7;         //
   addr=addr+X*2;         // same as addr= X*2 + Y*320*2
   p=0;               // Data ROM pointer

   for(i=0;i<32;i++)
   {   
      Buffer[0]=4;
      Buffer[1]=0x81;
      Buffer[2]=addr;
      Buffer[3]=addr>>8;
      Buffer[4]=addr>>16;   
      WritePKG(Buffer);

   

      for(j=0;j<2;j++)         // sprit one line data to 8 packet
      {
         SdCmd(0x84);         // send data packet
         SdCmd(32);            // no of byte in one packet
         for(k=0;k<16;k++)      // no of pixels in one packet
         {
            SdCmd(pic05[p]);   // low byte
            SdCmd(pic05[p+1]);   // high byte
            p+=2;            
         }   
         CmdEnd();
      }
      addr+=640;               // next line
   }      
}



Here is my code that takes lot of time Very Happy
Code:

void showpic(int16 x,int16 y)
{
static int32 i=0;
int16 j,k;
uchar Buffer[5],Buffer1[6];
for(j=0;j<y;j++)
{
   for(k=0;k<x;k++)
   {
      Buffer[0]=3;
      Buffer[1]=0x20;
      Buffer[2]=pic05[i++];
      Buffer[3]=pic05[i++];
      WritePKG(Buffer);
delay_ms(5);

   Buffer1[0]=5;
   Buffer1[1]=0x23;
   Buffer1[2]=k;
   Buffer1[3]=k>>8;
   Buffer1[4]=j;
   Buffer1[5]=j>>8;
   WritePKG(Buffer1);
   delay_ms(5);

//   Draw_Dot(k,j);
   }
 }
}
wipsri



Joined: 10 May 2011
Posts: 6

View user's profile Send private message

need the details
PostPosted: Fri Jul 22, 2011 10:46 am     Reply with quote

Dear arunkish

I need to develop the TFT display with Touchscreen for my project. Can you please tell me where can I get the TFT and touch board in INDIA which you used.

Thanks in advance....
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