-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch.c
76 lines (61 loc) · 2.09 KB
/
touch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*************************************************************************
Title: Asuro Bibliothek
Author: Michael Tissen und Alexander Berg
File: $Id: functionen.c,v 1.6.2.1 2007/07/01 11:14:38 peter Exp $
Software: AVR-GCC 4.1, AVR Libc 1.4.6 or higher
Hardware: Atmega32
License: GNU General Public License
DESCRIPTION:
Eine Sammlung von Funktionen für den Asuro.
USAGE:
Zur Nutzung funktionen.h und Settings.h einbinden
LICENSE:
Copyright (C) --
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*************************************************************************/
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
#include <stdio.h>
#include "include/Settings.h"
#include "include/touch.h"
#include "include/adc.h"
void GetTouch(int *X,int *Y)
{
double Ux,Uy;
int x,y;
//x
DDRA |= (1<<PA1); //PA0: 5V
DDRA |= (1<<PA0); //PA1: 0V
PORTA |= (1<<PA0);
_delay_ms(16);
//adc(PORT) liefert gemesse Spanung in V
Uy = ReadChannel(2);
Uy = ((Uy*5.0)/1024.0);
y = ((Uy-Uy1) / (Uy2-Uy1)) * WIDTH;
PORTA &= ~(1<<PA0); //PA0 und
DDRA &= ~(1<<PA0); //PA1 wiedr
DDRA &= ~(1<<PA1); //Eingang
//y
DDRA |= (1<<PA3); //PA3: 5V
DDRA |= (1<<PA2); //PA2: 0V
PORTA |= (1<<PA2);
_delay_ms(16);
//adc(PORT) liefert gemesse Spanung in V
Ux = ReadChannel(0);
Ux = ((Ux*5.0)/1024.0);
x = (((Ux-Ux1) / (Ux2-Ux1))*HEIGHT);
PORTA &= ~(1<<PA2); //PA2 und
DDRA &= ~(1<<PA2); //PA1 wiedr
DDRA &= ~(1<<PA3); //Eingang
_delay_ms(100);
*X = x;
*Y = y;
}