-
Notifications
You must be signed in to change notification settings - Fork 0
/
practicas 9 de julio.c
71 lines (59 loc) · 1.18 KB
/
practicas 9 de julio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <16f887.h>
#FUSES INTRC_IO
#USE delay (clock=8000000)
#include <lcd.c>
void init();
int8 lee_microsw(void);
int lee_dato(void);
int procesa_dato(int d);
void despliega(int a);
void main(void)
{
int dato, dato_procesado;
init();
while(1)
{
dato = lee_dato();
dato_procesado = procesa_dato(dato);
despliega(dato_procesado);
delay_ms(500);
}
}
void init(void)
{
set_tris_c(0xff);
set_tris_e(0xff);
lcd_init();
}
int lee_dato(void)
{
int valor;
valor = input(PIN_C0);// este es el pin con el que queremos iniciar.
valor+= (input(PIN_C1)*2);//valor+= input(PIN_C1) equivale a valor= valor + input(PIN_C1)
valor+= (input(PIN_C2)*4);
valor+= (input(PIN_C3)*8);
valor+= (input(PIN_C4)*16);
valor+= (input(PIN_C5)*32);
valor+= (input(PIN_E1)*64);
valor+= (input(PIN_E2)*128);
return valor;
}
int procesa_dato(int d)
{
int bits, j, b=0;
for(j=0;j<8;j++)
{
bits = d & (1<<j);
if(bits == 0)
{
b++;
}
}
return b;
}
void despliega(int a)
{
lcd_putc("\f");
lcd_putc("El # de 0 es:");
printf(lcd_putc,"%u", a);
}