Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 4 wire resistive touch screen interfacing with ATmega32

Status
Not open for further replies.

tahertinu

Member level 4
Member level 4
Joined
Jun 11, 2011
Messages
74
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Ahmedabad
Visit site
Activity points
1,752
hello every-buddy,
I am working on project interfacing touch screen with ATmega32. i have used this code
Code:
#ifndef F_CPU
#define F_CPU 8000000UL // or whatever may be your frequency
#endif
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
 
#include "lcd.h"
 
#define LTHRES 500
#define RTHRES 500
 
// initialize adc
void adc_init()
{
    // AREF = AVcc
    ADMUX = (1<<REFS0);
 
    // ADC Enable and prescaler of 128
    // 16000000/128 = 125000
    ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
}
 
// read adc value
uint16_t adc_read(uint8_t ch)
{
    // select the corresponding channel 0~7
    // ANDing with '7' will always keep the value
    // of 'ch' between 0 and 7
    ch &= 0b00000111;  // AND operation with 7
    ADMUX = (ADMUX & 0xF8)|ch;     // clears the bottom 3 bits before ORing
 
    // start single conversion
    // write '1' to ADSC
    ADCSRA |= (1<<ADSC);
 
    // wait for conversion to complete
    // ADSC becomes '0' again
    // till then, run loop continuously
    while(ADCSRA & (1<<ADSC));
 
    return (ADC);
}
 
int main()
{
    uint16_t adc_result0, adc_result1;
    char int_buffer[10];
    DDRC = 0x01;           // to connect led to PC0
 
    // initialize adc and lcd
    adc_init();
   lcd_init();

  // print some text
  lcd_set_cursor(0, 16);
  lcd_putstr("128x64 LCD");
  lcd_set_cursor(2, 16);
  lcd_putstr("HELLO");
  lcd_set_cursor(3, 16);
  lcd_putstr("WORLD");

 
   
 
    _delay_ms(500);
 
    while(1)
    {	DDRA |= (1<<DDA0);
        DDRA |= (1<<DDA2);
		DDRA &= ~(1<<DDA3);
		PORTA |= (1<<PA2);
		PORTA &= ~(1<<PA2);
		adc_result0 = adc_read(1);      // read X 
		
		DDRA |= (1<<DDA0);
        DDRA |= (1<<DDA2);
		DDRA &= ~(1<<DDA3);
		PORTA |= (1<<PA2);
		PORTA &= ~(1<<PA2);
        adc_result1 = adc_read(0);      // read Y
 
        // condition for led to glow
        if (adc_result0 < LTHRES && adc_result1 < RTHRES)
            PORTC = 0x01;
        else
            PORTC = 0x00;
 
        // now display on lcd
        itoa(adc_result0, int_buffer, 10);
		lcd_set_cursor(4, 11);
  		lcd_putstr(int_buffer);
		
 
        itoa(adc_result1, int_buffer, 10);
        		lcd_set_cursor(5, 11);
  				lcd_putstr(int_buffer);
        _delay_ms(50);
    }
}
IT'S not working please tell me where im wrong?
 

Quite mysterious how you want to read both x and y voltage with identical bit settings of PORTA?
We would expect 4 pins flipped between in- and output mode concurrently.
 

Quite mysterious how you want to read both x and y voltage with identical bit settings of PORTA?
We would expect 4 pins flipped between in- and output mode concurrently.

Code:
DDRA |= (1<<DDA0);
        DDRA |= (1<<DDA2);
		DDRA &= ~(1<<DDA3);
		PORTA |= (1<<PA0);
		PORTA &= ~(1<<PA2);
		adc_result0 = adc_read(1);      // read X 
		
		DDRA |= (1<<DDA3);
        DDRA |= (1<<DDA1);
		DDRA &= ~(1<<DDA2);
		PORTA |= (1<<PA1);
		PORTA &= ~(1<<PA3);
        adc_result1 = adc_read(0);      // read Y

sorry there was typo error.
still this is not working. what about fuse bit for ADC operation. should i desable Jtag?
 
Last edited:

i am stuck here because of Resistive touch screen. please someone throw light on my work and tell me where i am doing wrong. I have interfaced 4 wire resistive touch screen to microcontroller ATmega32 at PORTA0-to-PORTA3. i am getting 1023 and 1023 and some times 1022 on my graphical LCD which is connected on PORTD and PORTB. Here is my code.

// initialize adc
void adc_init()
{
// AREF = AVcc
ADMUX = (1<<REFS0);

// ADC Enable and prescaler of 128
// 16000000/128 = 125000
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
}

// read adc value
uint16_t adc_read(uint8_t ch)
{
// select the corresponding channel 0~7
// ANDing with '7' will always keep the value
// of 'ch' between 0 and 7
ch &= 0b00000111; // AND operation with 7
ADMUX = (ADMUX & 0xF8)|ch; // clears the bottom 3 bits before ORing

// start single conversion
// write '1' to ADSC
ADCSRA |= (1<<ADSC);

// wait for conversion to complete
// ADSC becomes '0' again
// till then, run loop continuously
while(ADCSRA & (1<<ADSC));

return (ADC);
}

int main()
{
uint16_t adc_result0, adc_result1;
char int_buffer[10];
DDRC = 0x01; // to connect led to PC0

adc_init(); // initialize adc and lcd

// Wait a little while the display starts up
for(volatile uint16_t i=0; i<15000; i++);

// Initialize the LCD
ks0108Init(0);

// Select a font
ks0108SelectFont(Arial_Bold_14, ks0108ReadFontData, BLACK);
// Set a position
ks0108GotoXY(15,10);
// Print some text
ks0108Puts_P(PSTR("***TAHER***"));
// a nice little round rect
ks0108DrawRoundRect(5, 5, 100, 20, 8, BLACK);

_delay_ms(500);

ks0108ClearScreen();

while(1)
{ DDRA |= (1<<DDA0);
DDRA |= (1<<DDA2);
DDRA &= ~(1<<DDA3);

PORTA |= (1<<PA0);
PORTA &= ~(1<<PA2);
_delay_ms(10);

adc_result0 = adc_read(1); // read adc value at PA0

// now display on lcd
itoa(adc_result0, int_buffer, 10);
ks0108GotoXY(10,10);
ks0108Puts(int_buffer);

DDRA |= (1<<DDA1);
DDRA |= (1<<DDA3);
DDRA &= ~(1<<DDA2);

PORTA |= (1<<PA1);
PORTA &= ~(1<<PA3);
_delay_ms(10);
adc_result1 = adc_read(0); // read adc value at PA1

itoa(adc_result1, int_buffer, 10);
ks0108GotoXY(10,30);
ks0108Puts(int_buffer);
_delay_ms(500);
ks0108ClearScreen();




}
}

please help me to read touch screen co-ordinates when touched
thanks.
 

Quite mysterious how you want to read both x and y voltage with identical bit settings of PORTA?
We would expect 4 pins flipped between in- and output mode concurrently.

tell me where i am wrong please its urgent.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top