Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
#include "E:\@Dokumenty\pic\vysilac\main.h"
2
 
3
#DEFINE LCD_RS          PIN_B1      // rizeni registru LCD displeje
4
#DEFINE LCD_E           PIN_B2      // enable LCD displeje
5
#DEFINE LCD_DATA_LSB    PIN_B4      // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
6
#INCLUDE "MYLCD.C"
7
 
8
#DEFINE  VYSILAC        PIN_C3
9
#DEFINE  OSA_X          0           // adresa A/D prevodniku pro osu X
10
#DEFINE  OSA_Y          1           // adresa A/D prevodniku pro osu Y
11
#DEFINE  IMPULS         250         // sirka impulsu pro false |-|
12
#DEFINE  TTL1           PIN_b4
13
#DEFINE  TTL2           PIN_b3
14
 
15
int stredX, stredY, x, y;
16
 
17
 
18
void odeslat (int8 kodeslani)
19
{
20
   int i;
21
 
22
   for  (i=0;i<=7;i++)
23
   {
24
     if (1==bit_test(kodeslani,i))
25
     {
26
        output_high(VYSILAC);
27
        delay_us(2*IMPULS);          // X pri 1: |--|___
28
        output_low(VYSILAC);
29
        delay_us(3*IMPULS);
30
     }
31
     else
32
     {
33
         output_high(VYSILAC);
34
         delay_us(IMPULS);           // X pri 0: |-|__|-|_
35
         output_low(VYSILAC);
36
 
37
         delay_us(2*IMPULS);
38
 
39
         output_high(VYSILAC);
40
         delay_us(IMPULS);
41
         output_low(VYSILAC);
42
         delay_us(IMPULS);
43
     };
44
   }
45
}
46
 
47
void synchronizace()
48
{
49
int8 sinchro;
50
   sinchro=0b00001111;
51
 
52
   odeslat (sinchro);                  // synchronizace: |--|___|--|___|--|___|--|___|-|__|-|_|-|__|-|_|-|__|-|_|-|__|-|_
53
}
54
 
55
 
56
 
57
void odesli (int8 X, int8 Y)
58
{
59
  odeslat(X+ (X << 4));
60
  odeslat(Y+ (Y << 4));
61
 
62
}
63
 
64
 
65
void kalibrace()
66
{
67
int8 min_x;
68
int8 max_x;
69
int8 min_y;
70
int8 max_y;
71
int8 sred_x;
72
int8 sred_y;
73
int8 adc;
74
   min_x=max_x=min_y=max_y=sred_x=sred_y=128;
75
 
76
   printf(lcd_putc,"Paku dejte do prostred a stisknete tlacitko");
77
znovu:   
78
   if (TTL1 || TTL2)
79
   {
80
   set_adc_channel(OSA_X);
81
   delay_us(10);
82
   sred_x=read_adc();
83
   set_adc_channel(OSA_y);
84
   delay_us(10);
85
   sred_y=read_adc();
86
   };
87
 
88
   //else goto znovu;
89
 
90
   printf(lcd_putc,"\f");
91
   printf(lcd_putc,"Pak ");
92
 
93
   set_adc_channel(OSA_X);
94
   delay_us(10);
95
 
96
   adc=read_adc();
97
 
98
   if (max_x < adc )max_x=adc;
99
   if (min_x > adc )min_x=adc;
100
 
101
   set_adc_channel(OSA_y);
102
   delay_us(10);
103
 
104
   adc=read_adc();
105
 
106
   if (max_y < adc )max_y=adc;
107
   if (min_y > adc )min_y=adc;
108
 
109
   if (TTL1 || TTL2) return;
110
}
111
 
112
 
113
void main()
114
{
115
int c=0;
116
 
117
   setup_adc_ports(RA0_RA1_RA3_ANALOG);
118
   setup_adc(ADC_CLOCK_DIV_2);
119
   setup_spi(FALSE);
120
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
121
   setup_timer_1(T1_DISABLED);
122
   setup_timer_2(T2_DISABLED,0,1);
123
 
124
   lcd_init();
125
 
126
   while (c<=16)
127
   {
128
   lcd_gotoxy(c,1);
129
   printf(lcd_putc,"_");
130
   delay_ms(50);
131
   printf(lcd_putc,"\f");
132
   c++;
133
   }
134
 
135
   printf(lcd_putc,"\fAhoj!");
136
   delay_ms(1500);
137
 
138
   printf(lcd_putc,"\f");
139
 
140
 
141
   while(true)
142
   {
143
      set_adc_channel(OSA_X);
144
      lcd_gotoxy(1,1);
145
      x=read_adc() >> 4;
146
      printf(lcd_putc,"X: %D      ", x);
147
      set_adc_channel(OSA_Y);
148
      lcd_gotoxy(1,2);
149
      y=read_adc() >> 4;
150
      printf(lcd_putc,"Y: %D      ", y);
151
 
152
 
153
 
154
 
155
 
156
 /*     output_high(PIN_C1);
157
      output_low(PIN_C2);
158
      delay_ms(100);
159
      output_low(PIN_C1);
160
      output_high(PIN_C2);
161
      delay_ms(100);*/
162
 
163
      lcd_gotoxy(7,2);
164
      printf(lcd_putc,"vysilam");
165
 
166
      output_high(PIN_C4);
167
      output_high(PIN_C6);
168
      delay_ms(1);
169
      output_low(PIN_C4);
170
      synchronizace();
171
      odesli(x,y);
172
      output_low(PIN_C6);
173
 
174
 
175
   }
176
 
177
}