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
        Delay_us(1600);
96
   }
97
}
98
 
99
void menu()
100
{
101
int8 polozka = 3;
102
int8 old_polozka = 0;
103
int pom;
104
 
105
   while(true)
106
   {
107
      pom = klavesa();
108
      if (0x07 == pom) polozka++;
109
      if (0x0f == pom) polozka--;
110
      if (0x04 <= polozka) polozka = 1;
111
      if (0x00 == polozka) polozka = 3;
112
      if (0x16 == pom)   // enter
113
      {
114
         LED((1 << (polozka + 1)) | 1);
115
         switch(polozka)
116
         {
117
            case 1:
118
              kalibrace();
119
              break;
120
 
121
            case 2:
122
              trimovat();
123
              break;
124
 
125
            case 3:
126
              vysilat();
127
              break;
128
         };
129
         LED(1 << (polozka + 1));
130
         old_polozka=0;
131
      };
132
 
133
      if (polozka != old_polozka)
134
      {
135
         old_polozka=polozka;
136
         printf(lcd_putc,"\f");
137
         switch(polozka)
138
         {
139
            case 1:
140
              lcd_gotoxy(5,2);
141
              printf(lcd_putc,"Kalibrace");
142
              break;
143
 
144
            case 2:
145
              lcd_gotoxy(7,2);
146
              printf(lcd_putc,"Trim");
147
              break;
148
 
149
            case 3:
150
              lcd_gotoxy(6,2);
151
              printf(lcd_putc,"Vysilat");
152
              break;
153
         };
154
         LED(1 << (polozka + 1));
155
         Delay_ms(250);
156
      }
157
   }
158
}
159
 
160
void main()
161
{
162
int8 tlacitka,tlacitka_old;
163
   setup_adc_ports(RA0_RA1_RA3_ANALOG);
164
   setup_adc(ADC_CLOCK_DIV_2);
165
   setup_spi(FALSE);
166
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
167
   setup_timer_1(T1_DISABLED);
168
   setup_timer_2(T2_DISABLED,0,1);
169
 
170
   lcd_init();
171
   KL_init();
172
 
173
   menu();
174
 
175
while(true)
176
{
177
//char xx;
178
//      if (true == read_kl(&xx))
179
//      {
180
//      printf(lcd_putc,"%C",xx );
181
//      }
182
}
183
}