void main(void) {
byte paso=0;
byte Tecla = 0;
set_tris_a(0x0001111);
set_tris_b(0x00);
port_a=0x00;
port_b=0xf0;
while(true) {
paso++;
//else
// delay_ms(2000);
if(paso==1) {
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}else if(paso==2) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,1);
output_bit(PIN_B2,0);
output_bit(PIN_B3,0);
}else if(paso==3) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,0);
output_bit(PIN_B2,1);
output_bit(PIN_B3,0);
}else if(paso==4) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,0);
output_bit(PIN_B2,0);
output_bit(PIN_B3,1);
paso=0;
}
delay_ms(100);
while(input(PIN_A0)) {
}
}
}
void main(void) {
byte paso=0;
byte Tecla = 0;
set_tris_a(0x0001111);
set_tris_b(0x00);
port_a=0x00;
port_b=0xf0;
while(true) {
paso++;
//else
// delay_ms(2000);
if(paso==1) {
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}else if(paso==2) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,1);
output_bit(PIN_B2,0);
output_bit(PIN_B3,0);
}else if(paso==3) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,0);
output_bit(PIN_B2,1);
output_bit(PIN_B3,0);
}else if(paso==4) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,0);
output_bit(PIN_B2,0);
output_bit(PIN_B3,1);
paso=0;
}
delay_ms(100);
while(input(PIN_A0)) {
if(input(PIN_B0))
Tecla = '7';
if(input(PIN_B1))
Tecla = '4';
if(input(PIN_B2))
Tecla = '1';
if(input(PIN_B3))
Tecla = '*';
}
while(input(PIN_A1)) {
if(input(PIN_B0))
Tecla = '8';
if(input(PIN_B1))
Tecla = '5';
if(input(PIN_B2))
Tecla = '2';
if(input(PIN_B3))
Tecla = '0';
}
while(input(PIN_A3)) {
if(input(PIN_B0))
Tecla = '9';
if(input(PIN_B1))
Tecla = '6';
if(input(PIN_B2))
Tecla = '3';
if(input(PIN_B3))
Tecla = '#';
}
while(input(PIN_A4)) {
if(input(PIN_B0))
Tecla = ' ';
if(input(PIN_B1))
Tecla = 'A';
if(input(PIN_B2))
Tecla = 'B';
if(input(PIN_B3))
Tecla = 'C';
}
}
}
Pregunta, no puedo ver si 2 patas estan prendidas al mismo tiempo?
Lo que yo intentaba era que mientras tenga 5v en la pata A0 ver cual de las filas tambien estaba con 5v.
| 0 | 1 | 2 | 3 |
| 4 | 6 | 6 | 7 |
| 8 | 9 | a | b |
| c | d | e | f |
| fila 1 | 0 | 1 | 2 | 3 |
| fila 2 | 4 | 6 | 6 | 7 |
| fila 3 | 8 | 9 | a | b |
| fila 4 | c | d | e | f |
| columna 1 | columna 2 | columna 3 | columna 4 |
| fila 1 | 0 | 1 | 2 | 3 |
| fila 2 | 4 | 6 | 6 | 7 |
| fila 3 | 8 | 9 | a | b |
| fila 4 | c | d | e | f |
| columna 1(pulsador 0) | columna 2(pulsador 1) | columna 3(pulsador 2) | columna 4(pulsador 3) |
| Referencia: |
| 5V |
| 0V |
| Depende del estado del pulsador |
| fila 1 | 0 | 1 | 2 | 3 |
| fila 2 | 4 | 6 | 6 | 7 |
| fila 3 | 8 | 9 | a | b |
| fila 4 | c | d | e | f |
| columna 1(pulsador 4) | columna 2(pulsador 5) | columna 3(pulsador 6) | columna 4(pulsador 7) |
| Referencia: |
| 5V |
| 0V |
| Depende del estado del pulsador |
| fila 1 | 0 | 1 | 2 | 3 |
| fila 2 | 4 | 6 | 6 | 7 |
| fila 3 | 8 | 9 | a | b |
| fila 4 | c | d | e | f |
| columna 1(pulsador 8) | columna 2(pulsador 9) | columna 3(pulsador a) | columna 4(pulsador b) |
| Referencia: |
| 5V |
| 0V |
| Depende del estado del pulsador |
| fila 1 | 0 | 1 | 2 | 3 |
| fila 2 | 4 | 6 | 6 | 7 |
| fila 3 | 8 | 9 | a | b |
| fila 4 | c | d | e | f |
| columna 1(pulsador c) | columna 2(pulsador d) | columna 3(pulsador e) | columna 4(pulsador f) |
| Referencia: |
| 5V |
| 0V |
| Depende del estado del pulsador |
void main(void) {
int8 paso=0;
byte Tecla = 1;
byte tmp;
set_tris_a(0b0011111);
set_tris_b(0x00);
port_a=0x00;
port_b=0x00;
while(true) {
//if(!input(PIN_A0)&&!input(PIN_A1)&&!input(PIN_A3)&&!input(PIN_A4))
paso++;
Tecla = 0;
if(paso==1) {
output_bit(PIN_B0,1);
output_bit(PIN_B1,0);
output_bit(PIN_B2,0);
output_bit(PIN_B3,0);
if(input(PIN_A0)) {
Tecla = 1;
} else if(input(PIN_A1)) {
Tecla = 2;
} else if(input(PIN_A3)) {
Tecla = 3;
} else if(input(PIN_A4)) {
Tecla = 4;
}
}else if(paso==2) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,1);
output_bit(PIN_B2,0);
output_bit(PIN_B3,0);
if(input(PIN_A0)) {
Tecla = 5;
} else if(input(PIN_A1)) {
Tecla = 6;
} else if(input(PIN_A3)) {
Tecla = 7;
} else if(input(PIN_A4)) {
Tecla = 8;
}
}else if(paso==3) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,0);
output_bit(PIN_B2,1);
output_bit(PIN_B3,0);
if(input(PIN_A0)) {
Tecla = 9;
} else if(input(PIN_A1)) {
Tecla = 10;
} else if(input(PIN_A3)) {
Tecla = 11;
} else if(input(PIN_A4)) {
Tecla = 12;
}
}else if(paso==4) {
output_bit(PIN_B0,0);
output_bit(PIN_B1,0);
output_bit(PIN_B2,0);
output_bit(PIN_B3,1);
paso=0;
if(input(PIN_A0)) {
Tecla = 13;
} else if(input(PIN_A1)) {
Tecla = 14;
} else if(input(PIN_A3)) {
Tecla = 15;
} else if(input(PIN_A4)) {
Tecla = 16;
}
}
delay_ms(500);
if(Tecla == 1) {
output_high(PIN_B4);
output_high(PIN_B5);
delay_ms(5000);
}
// if(bit_test(port_b,7) == 1) {
// Tecla = 1;
// }
//}
//if(Tecla==1) {
//}
}
}
Para verificarlo puse una condicio abajo con Tecla = 1 y entra pero cuando quiero prender la salida A4 y A5, el proteus solo me muestra durante esos 5 segundos la ultima pata A5 y la pata A4 queda apagada.
Te cuento que soy un improvizado en esto de la electronica, todo lo estoy haciendo para manejar mi acuario. No se nada de eletronica, aclaro esto antes de que digas que bolu%#.
pablo, ya verás que en este foro nadie te tratará de bolu%# por no saber de electrónica... muchos empezaron de cero aquí mismo y no por ello los han defenestrado de ninguna forma.
Mientras pongas entusiasmo, ganas, esfuerzo y demuestres voluntad de aprender nadie te negará la ayuda aquí!! eso te lo garantizo.
#include <16F628A.h>
#FUSES NOWDT // Watch Dog Timer
#FUSES NOPUT // Power Up Timer
#FUSES NOPROTECT // Code not protected from reading
#FUSES NOBROWNOUT // Reset when brownout detected
#FUSES NOMCLR // Master Clear pin enabled
#FUSES NOLVP // No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES INTRC_IO // Internal RC Osc, no CLKOUT
#use delay(clock=4000000)
#byte port_a=0x05
#byte port_b=0x06
#use fast_io(a)
#use fast_io(b)
char c;
void delay()
{
delay_ms(5);
}
char kbd_getc() // función que explora todo el teclado
{
port_b=0b00000001; // verifica columna 1
if(bit_test(port_a,0)==1)
{delay();
return ('1');} // si se presiono el uno devuelve 1
if(bit_test(port_a,1)==1)
{delay();
return ('2');} // si se presiono el cuatro devuelve 4
if(bit_test(port_a,3)==1)
{delay();
return ('3');} // si se presiono el siete devuelve 7
if(bit_test(port_a,4)==1)
{delay();
return ('4'); } // si se presiono el * devuelve 10 = A
port_b=0b00000010; // verifica columna 2
if(bit_test(port_a,0)==1)
{delay();
return ('5');} // si se presiono el dos devuelve 2
if(bit_test(port_a,1)==1)
{delay();
return ('6');} // si se presiono el cinco devuelve 5
if(bit_test(port_a,3)==1)
{delay();
return ('7');} // si se presiono el ocho devuelve 8
if(bit_test(port_a,4)==1)
{delay();
return ('8');} // si se presiono el cero devuelve 0
port_b=0b00000100; // verifica columna 3
if(bit_test(port_a,0)==1)
{delay();
return ('9');} // si se presiono el tres devuelve 3
if(bit_test(port_a,1)==1)
{delay();
return ('A');} // si se presiono el seis devuelve 6
if(bit_test(port_a,3)==1)
{delay();
return ('B'); } // si se presiono el nueve devuelve 9
if(bit_test(port_a,4)==1)
{delay();
return 'C'; } // si se presiono el # devuelve 11 = B
// si se tiene una matriz 4x3 no se usará el pin RB3
port_b=0b00001000; // verifica columna 4
if(bit_test(port_a,0)==1)
{delay();
return ('D');} // si se presiono la C devuelve 12 = C
if(bit_test(port_a,1)==1)
{delay();
return ('E');} // si se presiono la D devuelve 13 = D
if(bit_test(port_a,3)==1)
{delay();
return ('F');} // si se presiono la E devuelve 14 = E
if(bit_test(port_a,4)==1)
{delay();
return ('*');} // si se presiono el F devuelve 15 = F
if((bit_test(port_a,0)==0)&&(bit_test(port_a,1)==0)&&(bit_test(port_a,3)==0)&&(bit_test(port_a,4)==0))
return (0); // devuelve 16 en caso de no haber presionado ningun pulsador
// podria colocarse otra alternativa en caso de que no se presione ningun pulsador
}
void main() // programa principal
{
set_tris_b(0x00); // define RB0 a RB3 (columnas) como salidas y RB4 a RB7 (filas) como entradas
port_b=0; // inicializa puerto B
set_tris_a(0xff); // define puerto A como todas entradas excepto RA0
port_a=0; // inicializa puerto A
port_b_pullups(TRUE); // activa pull up del puerto b, no hará falta conectar resistencias
while(true) // bucle de trabajo
{
while(1)
{
do
{
c=kbd_getc();
}while(c==0);
if(c=='1') {
port_b = 0b00010000;
delay_ms(50);
} else if(c=='2') {
port_b = 0b00100000;
delay_ms(50);
} else if(c=='3') {
port_b = 0b00110000;
delay_ms(50);
} else if(c=='4') {
port_b = 0b01000000;
delay_ms(50);
} else if(c=='5') {
port_b = 0b01010000;
delay_ms(50);
} else if(c=='6') {
port_b = 0b01100000;
delay_ms(50);
} else if(c=='7') {
port_b = 0b01110000;
delay_ms(20);
} else if(c=='8') {
port_b = 0b10000000;
delay_ms(50);
} else if(c=='9') {
port_b = 0b10010000;
delay_ms(50);
} else if(c=='A') {
port_b = 0b10100000;
delay_ms(50);
} else if(c=='B') {
port_b = 0b10110000;
delay_ms(50);
} else if(c=='C') {
port_b = 0b11000000;
delay_ms(50);
} else if(c=='D') {
port_b = 0b11010000;
delay_ms(50);
} else if(c=='E') {
port_b = 0b11100000;
delay_ms(50);
} else if(c=='F') {
port_b = 0b11110000;
delay_ms(50);
} else {
port_b = 0b00000000;
delay_ms(50);
}
}
}
#include <16F628A.h>
#FUSES NOWDT // Watch Dog Timer
#FUSES NOPUT // Power Up Timer
#FUSES NOPROTECT // Code not protected from reading
#FUSES NOBROWNOUT // Reset when brownout detected
#FUSES NOMCLR // Master Clear pin enabled
#FUSES NOLVP // No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES INTRC_IO // Internal RC Osc, no CLKOUT
#use delay(clock=4000000)
#byte port_a=0x05
#byte port_b=0x06
#use fast_io(a)
#use fast_io(b)
char c;
void delay()
{
delay_ms(0);
}
char kbd_getc() // función que explora todo el teclado
{
port_b=0b00000001; // verifica columna 1
if(bit_test(port_a,0)==1)
{delay();
return ('1');} // si se presiono el uno devuelve 1
if(bit_test(port_a,1)==1)
{delay();
return ('2');} // si se presiono el cuatro devuelve 4
if(bit_test(port_a,2)==1)
{delay();
return ('3');} // si se presiono el siete devuelve 7
if(bit_test(port_a,3)==1)
{delay();
return ('4'); } // si se presiono el * devuelve 10 = A
port_b=0b00000010; // verifica columna 2
if(bit_test(port_a,0)==1)
{delay();
return ('5');} // si se presiono el dos devuelve 2
if(bit_test(port_a,1)==1)
{delay();
return ('6');} // si se presiono el cinco devuelve 5
if(bit_test(port_a,2)==1)
{delay();
return ('7');} // si se presiono el ocho devuelve 8
if(bit_test(port_a,3)==1)
{delay();
return ('8');} // si se presiono el cero devuelve 0
port_b=0b00000100; // verifica columna 3
if(bit_test(port_a,0)==1)
{delay();
return ('9');} // si se presiono el tres devuelve 3
if(bit_test(port_a,1)==1)
{delay();
return ('A');} // si se presiono el seis devuelve 6
if(bit_test(port_a,2)==1)
{delay();
return ('B'); } // si se presiono el nueve devuelve 9
if(bit_test(port_a,3)==1)
{delay();
return 'C'; } // si se presiono el # devuelve 11 = B
// si se tiene una matriz 4x3 no se usará el pin RB3
port_b=0b00001000; // verifica columna 4
if(bit_test(port_a,0)==1)
{delay();
return ('D');} // si se presiono la C devuelve 12 = C
if(bit_test(port_a,1)==1)
{delay();
return ('E');} // si se presiono la D devuelve 13 = D
if(bit_test(port_a,2)==1)
{delay();
return ('F');} // si se presiono la E devuelve 14 = E
if(bit_test(port_a,3)==1)
{delay();
return ('*');} // si se presiono el F devuelve 15 = F
if((bit_test(port_a,0)==0)&&(bit_test(port_a,1)==0)&&(bit_test(port_a,2)==0)&&(bit_test(port_a,3)==0))
return (0); // devuelve 16 en caso de no haber presionado ningun pulsador
// podria colocarse otra alternativa en caso de que no se presione ningun pulsador
}
void main() // programa principal
{
set_tris_b(0x00); // define RB0 a RB3 (columnas) como salidas y RB4 a RB7 (filas) como entradas
port_b=0; // inicializa puerto B
set_tris_a(0b0001111); // define puerto A como todas entradas excepto RA0
port_a=0; // inicializa puerto A
port_b_pullups(TRUE); // activa pull up del puerto b, no hará falta conectar resistencias
while(true) // bucle de trabajo
{
while(1)
{
do
{
c=kbd_getc();
}while(c==0);
if(c=='1') {
port_b = 0b00010000;
delay_ms(50);
} else if(c=='2') {
port_b = 0b00100000;
delay_ms(50);
} else if(c=='3') {
port_b = 0b00110000;
delay_ms(50);
} else if(c=='4') {
port_b = 0b01000000;
delay_ms(50);
} else if(c=='5') {
port_b = 0b01010000;
delay_ms(50);
} else if(c=='6') {
port_b = 0b01100000;
delay_ms(50);
} else if(c=='7') {
port_b = 0b01110000;
delay_ms(50);
} else if(c=='8') {
port_b = 0b10000000;
delay_ms(50);
} else if(c=='9') {
port_b = 0b10010000;
delay_ms(50);
} else if(c=='A') {
port_b = 0b10100000;
delay_ms(50);
} else if(c=='B') {
port_b = 0b10110000;
delay_ms(50);
} else if(c=='C') {
port_b = 0b11000000;
delay_ms(50);
} else if(c=='D') {
port_b = 0b11010000;
delay_ms(50);
} else if(c=='E') {
port_b = 0b11100000;
delay_ms(50);
} else if(c=='F') {
port_b = 0b11110000;
delay_ms(50);
} else {
// port_b = 0b00000000;
// delay_ms(1050);
}
port_b = 0;
//while((bit_test(port_a,0)==1)||(bit_test(port_a,1)==1)||(bit_test(port_a,3)==1)||(bit_test(port_a,4)==1))
//{}
}
}
#byte CMCON
void main() {
setup_comparator(NC_NC_NC_NC);
COMCON = 0x07;
}