Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
//#DEFINE  PL             PIN_B3              // ovladani klavesnice
2
//#DEFINE  STROBE_LED     PIN_C0
3
//#DEFINE  STROBE_KL      PIN_C1
4
//#DEFINE  DATA_OUT       PIN_C2
5
//#DEFINE  CP             PIN_C3
6
//#DEFINE  DATA_IN        PIN_C4
7
 
8
#DEFINE  znak_0     14
9
#DEFINE  znak_1     10
10
#DEFINE  znak_2     11
11
#DEFINE  znak_3     12
12
#DEFINE  znak_4     20
13
#DEFINE  znak_5     21
14
#DEFINE  znak_6     22
15
#DEFINE  znak_7     04
16
#DEFINE  znak_8     05
17
#DEFINE  znak_9     06
18
#DEFINE  znak_R     15
19
#DEFINE  znak_F     16
20
#DEFINE  znak_C     27
21
#DEFINE  nic        80
22
 
23
 
24
void KL_init()
25
{
26
int8 i;
27
   output_high(STROBE_KL);
28
   output_high(STROBE_LED);
29
 
30
   for (i=0;i<=7;i++)
31
   {
32
      output_low(DATA_IN);
33
      output_high(CP);
34
      output_low(CP);
35
   }
36
   output_low(STROBE_KL);
37
   output_low(STROBE_LED);
38
   output_high(CP);
39
   output_high(PL);
40
}
41
 
42
void KL_CP(j)
43
{
44
int8 i;
45
   for (i=0;i<=j;i++)
46
   {
47
      output_high(CP);
48
      output_low(CP);
49
   }
50
}
51
 
52
void LED(int8 LED)      //rosviti LED 1-7
53
{
54
int i;
55
   output_low(CP);
56
   output_low(STROBE_LED);
57
   for (i=0;i<=7;i++)
58
   {
59
      output_bit(DATA_IN,bit_test(LED,i));
60
      output_high(CP);
61
      output_low(CP);
62
   };
63
   output_high(STROBE_LED);
64
   output_low(STROBE_LED);
65
}
66
 
67
int8 klavesa()          //vrati cislo klavesy
68
{
69
   int8 i;
70
   int8 sloupec;
71
 
72
   for(sloupec=0; sloupec<=7; sloupec++)
73
   {
74
      output_low(STROBE_KL);
75
      output_low(DATA_IN);
76
      for (i=0;i<=7;i++)
77
      {                                   //nulovani sloupcu
78
        output_high(CP);
79
        output_low(CP);
80
      }
81
 
82
      output_high(DATA_IN);
83
      output_high(CP);                    //zavedeni 1 do registru sloupcu
84
      output_low(CP);
85
 
86
      output_low(DATA_IN);
87
      for (i=0;i<sloupec;i++)            //nastaveni sloupce
88
      {
89
        output_high(CP);
90
        output_low(CP);
91
      }
92
 
93
      output_high(STROBE_KL);
94
      output_low(PL);
95
      output_high(PL);
96
 
97
      for (i=0;i<5;i++)                  //posunuti cteciho registru
98
      {
99
        output_high(CP);
100
        output_low(CP);
101
      }
102
 
103
     /* if (1==input(DATA_OUT)) return(sloupec);           // pokud je 4. radek
104
      output_high(CP);
105
      output_low(CP);
106
      if (1==input(DATA_OUT)) return(sloupec);           // pokud je 3. radek
107
      output_high(CP);
108
      output_low(CP);*/
109
      if (1==input(DATA_OUT)) return(sloupec);           // pokud je 0. radek
110
      output_high(CP);
111
      output_low(CP);
112
      if (1==input(DATA_OUT)) return(0b1000 | sloupec);  // pokud je 1. radek
113
      output_high(CP);
114
      output_low(CP);
115
      if (1==input(DATA_OUT)) return(0b10000 | sloupec); // pokud je 2. radek
116
 
117
 
118
   }
119
   return(0x80);  // nastavy nejvissi bit, ze neni nic zmacknuto
120
}
121
 
122
boolean read_KL(char *klv)
123
{
124
   const char prev_tabulka[24]={'i','z','m','u','7','8','9','.','1','2','3','b','0','r','f','k','4','5','6','s',' ',' ','t','c'};
125
 
126
   *klv = klavesa();
127
   if (0x80==*klv) return(false);
128
   else
129
   {
130
      *klv = prev_tabulka[*klv];
131
      return(true);
132
   }
133
}
134