Aguijón Software Libraries
1.0
Documentation for the included Libraries
Main Page
Files
File List
Globals
All
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
inputs.c
Go to the documentation of this file.
1
/********************************************************************
2
FileName: inputs.c
3
Dependencies: See INCLUDES section
4
Hardware: Aguijón rev3.0
5
Complier: Microchip XC16(for PIC24), C30(for PIC24)
6
Company: Vinagrón Digital
7
8
Software License Agreement:
9
10
blah blah blah
11
12
********************************************************************
13
File Description:
14
Includes demonstration functions.
15
16
17
Change History:
18
Rev Description
19
---- -----------------------------------------
20
1.0 Initial release
21
********************************************************************/
22
23
#include <p24FJ128GB106.h>
24
#include <GenericTypeDefs.h>
25
#include "
definitions.h
"
26
#include "
inputs.h
"
27
28
40
void
DIPconfig
(
unsigned
char
cfg)
41
{
42
switch
(cfg){
43
case
DMSB
:
44
DSWMSBE
= 0;
//habilitar MSB
45
DSWLSBE
= 1;
//deshabilitar LSB
46
break
;
47
case
DLSB
:
48
DSWMSBE
= 1;
//deshabilitar MSB
49
DSWLSBE
= 0;
//habilitar LSB
50
break
;
51
case
DDIS
:
52
DSWMSBE
= 1;
//<-|-DIP SW disable
53
DSWLSBE
= 1;
//<-+
54
break
;
55
}
56
}
57
69
unsigned
char
readDIP
(
void
)
70
{
71
unsigned
char
i, result=0;
72
73
for
(i=0 ; i<8 ; i++){
74
switch
(i){
75
case
0:
//MSB
76
DIPconfig
(
DMSB
);
//habilita los MSB del DIP
77
if
(!
DIP1_5
){result += 128;}
78
break
;
79
case
1:
80
if
(!
DIP2_6
){result += 64;}
81
break
;
82
case
2:
83
if
(!
DIP3_7
){result += 32;}
84
break
;
85
case
3:
86
if
(!
DIP4_8
){result += 16;}
87
break
;
88
case
4:
//LSB
89
DIPconfig
(
DLSB
);
//enable LSB
90
if
(!
DIP1_5
){result += 8; }
91
break
;
92
case
5:
93
if
(!
DIP2_6
){result += 4; }
94
break
;
95
case
6:
96
if
(!
DIP3_7
){result += 2; }
97
break
;
98
case
7:
99
if
(!
DIP4_8
){result += 1; }
100
break
;
101
}
102
}
103
104
DIPconfig
(
DDIS
);
//Disable DIP SW
105
106
return
result;
107
}
108
120
BOOL
DebounceKeyb
(
void
)
121
{
122
if
(!
SW1
|| !
SW2
|| !
SW3
|| !
SW4
){
//any SWx pressed
123
delayms
(10);
//wait 10 mS
124
if
(!
SW1
|| !
SW2
|| !
SW3
|| !
SW4
){
//is it still pressed?
125
return
TRUE
;
//yes, we have a valid key press
126
}
else
{
127
return
FALSE
;
//no valid keypress
128
}
129
}
130
}
131
143
BOOL
DebounceOpto
(
void
)
144
{
145
if
(!
OPTO1
|| !
OPTO2
|| !
OPTO3
|| !
OPTO4
){
//any OPTOx Active
146
delayms
(10);
//wait 10mS
147
if
(!
OPTO1
|| !
OPTO2
|| !
OPTO3
|| !
OPTO4
){
//still active?
148
return
TRUE
;
//yes, valid input
149
}
else
{
150
return
FALSE
;
//not a valid input
151
}
152
}
153
}
154
166
unsigned
char
getActiveSW
(
void
)
167
{
168
unsigned
char
tecla = 0;
169
170
if
(!
SW1
) { tecla = 1; }
//se guarda en "tecla" el valor del switch presionado
171
else
if
(!
SW2
){ tecla = 2; }
//se presiono el 2
172
else
if
(!
SW3
){ tecla = 3; }
// ... 3
173
else
if
(!
SW4
){ tecla = 4; }
// ... el 4
174
else
{
175
return
0;
//no hay switches presionados
176
}
177
178
if
(!
DebounceKeyb
()){
//al parecer todo va bien, hacer debounce
179
return
0;
//hubo un error en la rutina de debounce
180
}
181
return
tecla;
//todo sale bien, regresar el valor del switch
182
}
183
195
unsigned
char
readSW
(
void
)
196
{
197
static
unsigned
char
pressed = 0;
//<! Stores the value of the currently pressed key
198
static
unsigned
char
lastPressed = 0;
//<! Stores the vakue of the last pressed key
199
200
//se activan en 0 !SWx
201
pressed =
getActiveSW
();
//saber cual sw esta presionado y hacer debounce
202
203
if
(pressed){
204
if
(pressed == lastPressed){
205
return
0;
206
}
else
{
207
lastPressed = pressed;
208
return
pressed;
209
}
210
}
else
{
211
if
(lastPressed != 0){
212
lastPressed = 0;
213
}
214
return
0;
215
}
216
return
0;
217
}
218
230
unsigned
char
readOI
(
void
)
231
{
232
//se activan en 0 !OPTOx
233
if
(!
OPTO1
){
234
DebounceOpto
();
235
return
1;
236
}
else
if
(!
OPTO2
){
237
DebounceOpto
();
238
return
2;
239
}
else
if
(!
OPTO3
){
240
DebounceOpto
();
241
return
3;
242
}
else
if
(!
OPTO4
){
243
DebounceOpto
();
244
return
4;
245
}
else
{
246
return
0;
247
}
248
}
Aguijon
Documented Software
Aguijon 3.0
inputs.c
Generated on Sat Nov 17 2012 19:00:33 for Aguijón Software Libraries by
1.8.2