kirtan
Junior Member level 2
- Joined
- Mar 11, 2011
- Messages
- 20
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,515
I am using 4 wire resistive type touch screen interfaced with microcontroller (ATMega).
I have designed the program according to the required algorithm, y+ 5V y- 0v, read x- and then x+ 5V, x- 0V and read y-.
When i ready only x value it gives me correct answer, when i read the y value it also gives me correct value but when i try to read x and y in sequence then i get correct value of y but not of x. x almost remains constant.
Part of the code is shown below
/* par of main function*///////////////
while(1)
{
x_value = read_x();
lcd_command(0x82);
disp_lcd(x_value);
delay_ms(20);
y_value = read_y();
lcd_command(0xC2);
disp_lcd(y_value);
delay_ms(200);
}
/*................................................*/////////
part of routines
#define x_p PORTA0
#define y_p PORTA1
#define x_m PORTA2
#define y_m PORTA3
unsigned int read_x(void)
{ unsigned int ADC_value;
setbit(DDRA,y_p); //set as output pins
setbit(DDRA, y_m);
setbit(PORTA,y_p); //set as 1 +5V
clearbit(PORTA,y_m); //set as 0 0V
ADC_value = read_ADC(x_m);
return ADC_value;
}
unsigned int read_y(void)
{ unsigned int ADC_value;
setbit(DDRA,x_p); //set as output pins
setbit(DDRA, x_m);
setbit(PORTA,x_p); //set as 1 +5V
clearbit(PORTA,x_m); //set as 0 0V
ADC_value = read_ADC(y_m);
return ADC_value;
}
I have designed the program according to the required algorithm, y+ 5V y- 0v, read x- and then x+ 5V, x- 0V and read y-.
When i ready only x value it gives me correct answer, when i read the y value it also gives me correct value but when i try to read x and y in sequence then i get correct value of y but not of x. x almost remains constant.
Part of the code is shown below
/* par of main function*///////////////
while(1)
{
x_value = read_x();
lcd_command(0x82);
disp_lcd(x_value);
delay_ms(20);
y_value = read_y();
lcd_command(0xC2);
disp_lcd(y_value);
delay_ms(200);
}
/*................................................*/////////
part of routines
#define x_p PORTA0
#define y_p PORTA1
#define x_m PORTA2
#define y_m PORTA3
unsigned int read_x(void)
{ unsigned int ADC_value;
setbit(DDRA,y_p); //set as output pins
setbit(DDRA, y_m);
setbit(PORTA,y_p); //set as 1 +5V
clearbit(PORTA,y_m); //set as 0 0V
ADC_value = read_ADC(x_m);
return ADC_value;
}
unsigned int read_y(void)
{ unsigned int ADC_value;
setbit(DDRA,x_p); //set as output pins
setbit(DDRA, x_m);
setbit(PORTA,x_p); //set as 1 +5V
clearbit(PORTA,x_m); //set as 0 0V
ADC_value = read_ADC(y_m);
return ADC_value;
}