The driver code is shown below:
Code: Select all
// Touch module module connections
extern sfr sbit ADS7843_CS;
extern sfr sbit SoftSpi_SDI;
extern sfr sbit SoftSpi_SDO;
extern sfr sbit SoftSpi_CLK;
extern sfr sbit ADS7843_CS_Direction;
extern sfr sbit SoftSpi_SDI_Direction;
extern sfr sbit SoftSpi_SDO_Direction;
extern sfr sbit SoftSpi_CLK_Direction;
// End touch module module connections
#include "built_in.h"
unsigned int ads7843_read()
{
char lsb, msb;
unsigned int retval;
ADS7843_CS = 0;
Soft_SPI_Write(0x90);
ADS7843_CS = 1;
delay_us(2); // Tacq delay time
ADS7843_CS = 0;
delay_us(2); // Tacq delay time
msb = Soft_SPI_Read(0);
Soft_SPI_Write(0xd0);
ADS7843_CS = 1;
delay_us(2); // Tacq delay time
ADS7843_CS = 0;
delay_us(2); // Tacq delay time
lsb = Soft_SPI_Read(0);
ADS7843_CS = 1;
hi(retval) = msb; // Combine bytes into 16 bit word
lo(retval) = lsb;
return retval;
}
Code: Select all
// Touch module module connections
sbit ADS7843_CS at latC0_bit;
sbit SoftSpi_SDI at latC4_bit;
sbit SoftSpi_SDO at latC2_bit;
sbit SoftSpi_CLK at latC6_bit;
sbit ADS7843_CS_Direction at TRISC0_bit;
sbit SoftSpi_SDI_Direction at TRISC4_bit;
sbit SoftSpi_SDO_Direction at TRISC2_bit;
sbit SoftSpi_CLK_Direction at TRISC6_bit;
// End touch module module connections
void main() {
unsigned int result;
ADCON0 = 0x0F; // turn off analog inputs
ADCON1 = 0x0F; // turn off analog inputs
ANSELB = 0; // Configure PORTB pins as digital
ANSELC = 0; // Configure PORTC pins as digital
ANSELE = 0; // Configure PORTE pins as digital
TRISA = 0;
TRISB = 0;
TRISD = 0;
TRISE = 0;
latA = 0x00;
latB = 0x00;
latD = 0x00;
latE = 0x00;
UART1_Init(38400); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
ADS7843_CS = 1; // Deselect
ADS7843_CS_Direction = 0; // Set CS# pin as Output
Soft_SPI_Init(); // Initialize Soft_SPI
while(1)
{
result = ads7843_read();
IntToStr(result, txt);
UART1_Write_Text(txt);
delay_ms(500);
}
}
So all I get in the usart terminal is "Start" and then a stream of zero's (even though I'm touching the panel).