Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
//#DEFINE  AD_OSA_X          0           // adresa A/D prevodniku pro osu X
2
//#DEFINE  AD_OSA_Y          1           // adresa A/D prevodniku pro osu Y
3
//#DEFINE  TL1           PIN_A2          // tlacitka
4
//#DEFINE  TL2           PIN_A4
5
 
6
//#DEFINE  EEleve_x           0
7
//#DEFINE  EEprave_x          1          //adresovani EEPROM
8
//#DEFINE  EEhorni_y          2
9
//#DEFINE  EEdolni_y          3
10
 
11
//#DEFINE  EEmin_x            4          // ulozeni hodnot (adresy)
12
//#DEFINE  EEmax_x            5
13
//#DEFINE  EEmin_y            6
14
//#DEFINE  EEmax_y            7
15
//#DEFINE  EEstred_x          8
16
//#DEFINE  EEstred_y          9
17
 
18
 
19
unsigned int min_x;
20
unsigned int max_x;
21
unsigned int min_y;
22
unsigned int max_y;
23
unsigned int stred_x;
24
unsigned int stred_y;
25
unsigned int leve_x;
26
unsigned int prave_x;
27
unsigned int horni_y;
28
unsigned int dolni_y;
29
 
30
 
31
/*#DEFINE  TEXT0    "Joy set to cent"
32
#DEFINE  TEXT1    "er and press OK"
33
#DEFINE  TEXT2    "Joy move in some "
34
#DEFINE  TEXT3    "full circle"
35
#DEFINE  TEXT4    "Calib. complete"*/
36
 
37
#DEFINE  TEXT0    " Dejte paku do "
38
#DEFINE  TEXT1    "prostøed"
39
#DEFINE  TEXT2    "Udelajte par"
40
#DEFINE  TEXT3    "kruhù"
41
#DEFINE  TEXT4    "hotovo"
42
 
43
 
44
void Joystick (int *ted_x, int *ted_y, int8 *ted_tl1, int8 *ted_tl2)
45
{
46
   set_adc_channel(AD_OSA_X);
47
   delay_us(10);
48
   *ted_x=read_adc();
49
   set_adc_channel(AD_OSA_Y);
50
   delay_us(10);
51
   *ted_y=read_adc();
52
 
53
 
54
 if (!input(TL1))
55
  {
56
  delay_us(500);
57
  if (!input(TL1)) *ted_tl1=True;
58
  }
59
  else *ted_TL1=False;
60
 
61
 if (!input(TL2))
62
  {
63
  delay_us(500);
64
  if (!input(TL2)) *ted_tl2=True;
65
  }
66
  else *ted_tl2=False;
67
}
68
 
69
 
70
 
71
void kalibrace()
72
{
73
 
74
int  x,y;
75
int8 tlac1,tlac2;
76
 
77
   min_x = max_x = min_y = max_y = stred_x = stred_y = 128;
78
 
79
// ROZSACH JOYSTIKU
80
   printf(lcd_putc,"\f");
81
   printf(lcd_putc,TEXT2);
82
   lcd_gotoxy(1,2);
83
   printf(lcd_putc,TEXT3);
84
 
85
   while(input(TL1))
86
   {
87
      if (0x17 == klavesa()) return;         // escape
88
 
89
      Joystick(&x,&y,&tlac1,&tlac2);
90
 
91
      if (max_x < x )max_x=x;
92
      if (min_x > x )min_x=x;
93
      if (max_y < y )max_y=y;                //zjisteni meznich hodnot
94
      if (min_y > y )min_y=y;
95
   };
96
 
97
   Delay_ms(500);
98
   printf(lcd_putc,"\f");
99
   printf(lcd_putc,TEXT0);
100
   lcd_gotoxy(1,2);
101
   printf(lcd_putc,TEXT1);
102
 
103
   while(input(TL1))
104
   joystick(&stred_x,&stred_y,&tlac1,&tlac2);            //nastaveni stredu
105
 
106
 
107
 
108
    leve_x=max_x - stred_x;
109
    prave_x=stred_x - min_x;
110
    horni_y=max_y - stred_y;
111
    dolni_y=stred_x - min_x;
112
 
113
    leve_x = leve_x / 8;                     //vypocet parametru
114
    prave_x = prave_x / 8;
115
    horni_y = horni_y / 8;
116
    dolni_y = dolni_y / 8;
117
 
118
   write_eeprom(EEleve_x,leve_x);
119
   write_eeprom(EEprave_x,prave_x);
120
   write_eeprom(EEstred_x,stred_x);
121
   write_eeprom(EEstred_y,stred_y);
122
   write_eeprom(EEhorni_y,horni_y);
123
   write_eeprom(EEdolni_y,dolni_y);
124
 
125
   //write_eeprom(EEmin_x,min_x);              //zapis
126
   //write_eeprom(EEmax_x,max_x);
127
   //write_eeprom(EEmin_y,min_y);
128
   //write_eeprom(EEmax_y,max_y);
129
}
130
 
131
 
132