Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
// Vysilac
2
 
3
#include "main.h"
4
#include "..\common.h"
5
//Displej
6
#DEFINE  LCD_RS         PIN_B1      // rizeni registru LCD displeje
7
#DEFINE  LCD_E          PIN_B2      // enable LCD displeje
8
#DEFINE  LCD_DATA_LSB   PIN_B4      // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
9
#INCLUDE "MYLCD.C"
10
#INCLUDE "lcd2.c"
11
//Klavesnice
12
#DEFINE  PL             PIN_B3              // ovladani klavesnice
13
#DEFINE  STROBE_LED     PIN_C0
14
#DEFINE  STROBE_KL      PIN_C1
15
#DEFINE  DATA_OUT       PIN_C2
16
#DEFINE  CP             PIN_C3
17
#DEFINE  DATA_IN        PIN_C4
18
#INCLUDE "keybord.c"
19
//Vysilac
20
#DEFINE  VYSILAC        PIN_C5
21
#INCLUDE "vysilac.c"
22
//Joistick
23
#DEFINE  EEleve_x           0
24
#DEFINE  EEprave_x          1          //adresovani EEPROM
25
#DEFINE  EEhorni_y          2
26
#DEFINE  EEdolni_y          3
27
 
28
#DEFINE  EEmin_x            4
29
#DEFINE  EEmax_x            5
30
#DEFINE  EEmin_y            6
31
#DEFINE  EEmax_y            7
32
#DEFINE  EEstred_x          8
33
#DEFINE  EEstred_y          9
34
 
35
#DEFINE  AD_OSA_X          1           // adresa A/D prevodniku pro osu X
36
#DEFINE  AD_OSA_Y          0           // adresa A/D prevodniku pro osu Y
37
#DEFINE  TL1            PIN_C6
38
#DEFINE  TL2            PIN_C7
39
#INCLUDE "Joystick.c"
40
 
41
int  x,y,tlac1,tlac2;
42
 
43
void trimovat()
44
{
45
   odeslat_paket(Trim,0b0001);
46
   odeslat_paket(OSA_X,x);
47
   odeslat_paket(OSA_Y,y);
48
}
49
 
50
void vysilat()
51
{
52
 
53
   leve_x = read_eeprom(EEleve_x);
54
   prave_x = read_eeprom(EEprave_x);
55
   stred_x = read_eeprom(EEstred_x);
56
   stred_y = read_eeprom(EEstred_y);
57
   horni_y = read_eeprom(EEhorni_y);
58
   dolni_y = read_eeprom(EEdolni_y);
59
 
60
   Delay_ms(200);
61
   lcd_gotoxy(6,2);
62
   printf(lcd_putc,"Vysilam");
63
 
64
   while(0x80 == klavesa())
65
      {
66
         Joystick(&x,&y,&tlac1,&tlac2);
67
         /*if (stred_x >= x)
68
         {
69
            x = stred_x - x;
70
            x = x/leve_x;
71
         }
72
         else
73
         {
74
            x = x - stred_x;
75
            x = x/prave_x;
76
         }
77
 
78
         if (stred_y >= y)
79
         {
80
            y = stred_y - y;
81
            y = y/dolni_y;
82
         }
83
         else
84
         {
85
            y = y - stred_y;
86
            y = y/horni_y;
87
         }*/
88
 
89
         x=x/8;
90
         y=y/8;
91
 
92
        odeslat_paket(OSA_X,x);
93
        Delay_us(1600);
94
        odeslat_paket(OSA_Y,y);
95
   }
96
}
97
 
98
void menu()
99
{
100
int8 polozka = 3;
101
int8 old_polozka = 0;
102
int pom;
103
 
104
   while(true)
105
   {
106
      pom = klavesa();
107
      if (0x07 == pom) polozka++;
108
      if (0x0f == pom) polozka--;
109
      if (0x04 <= polozka) polozka = 1;
110
      if (0x00 == polozka) polozka = 3;
111
      if (0x16 == pom)   // enter
112
      {
113
         LED((1 << (polozka + 1)) | 1);
114
         switch(polozka)
115
         {
116
            case 1:
117
              kalibrace();
118
              break;
119
 
120
            case 2:
121
              trimovat();
122
              break;
123
 
124
            case 3:
125
              vysilat();
126
              break;
127
         };
128
         LED(1 << (polozka + 1));
129
         old_polozka=0;
130
      };
131
 
132
      if (polozka != old_polozka)
133
      {
134
         old_polozka=polozka;
135
         printf(lcd_putc,"\f");
136
         switch(polozka)
137
         {
138
            case 1:
139
              lcd_gotoxy(5,2);
140
              printf(lcd_putc,"Kalibrace");
141
              break;
142
 
143
            case 2:
144
              lcd_gotoxy(7,2);
145
              printf(lcd_putc,"Trim");
146
              break;
147
 
148
            case 3:
149
              lcd_gotoxy(6,2);
150
              printf(lcd_putc,"Vysilat");
151
              break;
152
         };
153
         LED(1 << (polozka + 1));
154
         Delay_ms(250);
155
      }
156
   }
157
}
158
 
159
void main()
160
{
161
int8 tlacitka,tlacitka_old;
162
   setup_adc_ports(RA0_RA1_RA3_ANALOG);
163
   setup_adc(ADC_CLOCK_DIV_2);
164
   setup_spi(FALSE);
165
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
166
   setup_timer_1(T1_DISABLED);
167
   setup_timer_2(T2_DISABLED,0,1);
168
 
169
   lcd_init();
170
   KL_init();
171
 
172
   menu();
173
 
174
while(true)
175
{
176
//char xx;
177
//      if (true == read_kl(&xx))
178
//      {
179
//      printf(lcd_putc,"%C",xx );
180
//      }
181
}
182
}