/* L=LOGIC LOW, H=LOGIC HIGH, Z=HIGH IMPEDANCE, X = DON'T CARE
|-----------------------------------------------|
| Functional Decode Table MT8870 |
|-----------------------------------------------|
| Dig TOE INH ESt Q4 Q3 Q2 Q1 |
| ANY L X H Z Z Z Z |
| 1 H X H 0 0 0 1 |
| 2 H X H 0 0 1 0 |
| 3 H X H 0 0 1 1 |
| 4 H X H 0 1 0 0 |
| 5 H X H 0 1 0 1 |
| 6 H X H 0 1 1 0 |
| 7 H X H 0 1 1 1 |
| 8 H X H 1 0 0 0 |
| 9 H X H 1 0 0 1 |
| 0 H X H 1 0 1 0 |
| * H X H 1 0 1 1 |
| # H X H 1 1 0 0 |
| A H L H 1 1 0 1 |
| B H L H 1 1 1 0 |
| C H L H 1 1 1 1 |
| D H L H 0 0 0 0 |
|-----------------------------------------------|
| A H H L | undetected, the output |
| B H H L | code will remain the |
| C H H L | same as the previous |
| D H H L | detected code. |
|----------------------------------------------*/
// DTMF a recivir: *A123456#
#include <18f4550.h> // #include <18f4550.h>
#fuses HS,PROTECT,PUT,WDT,NOBROWNOUT,NOLVP,NOCPD,WRT,MCLR
#use delay(clock=20000000, crystal=20000000)
#byte PORTA=0xf80 #byte TRISA=0xf92 #byte PORTB=0xf81 #byte TRISB=0xF93 #byte PORTC=0xf82 #byte TRISC=0xF94 #byte PORTD=0xf83 #byte TRISD=0xF95 #byte PORTE=0xf84 #byte TRISE=0xF96
#byte LATA=0xf89 #byte LATB=0xf8a #byte LATC=0xf8b #byte LATD=0xf8c #byte LATE=0xf8d
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, stop=1, stream=debug, ERRORS)
int DTMF_CMD;
int8 j=1;
int8 Temp;
int8 dtmf = 0;
char RX_DTMF[15];
char const ASCII[16] = {'D','8','4','#','2','0','6','B','1','9','5','A','3','*','7','C'};
// Interrupción para detectar el DTMF
#int_EXT
void EXT_isr(void){
DTMF_CMD = ASCII[(input_b() >> 1) & 0xF] ; // Leer todo PORTB
switch(dtmf)
{
case 0:
if(DTMF_CMD == '*'){
dtmf++;
RX_DTMF[0] = DTMF_CMD;
}
break;
case 1:
if(DTMF_CMD == '#' || j >= 9) { // Proteccion, la primera es cuando recibe el # sabeidno que termino, y la segunda es para que no supere la cantidad maxima de digitos
dtmf++;
RX_DTMF[9] = '\0';
j = 1;
}
else {
RX_DTMF[j++] = DTMF_CMD;
}
break;
case 2:
// Acá estaría completo y no haría nada hasta que se ponga en 0 dtmf
break;
}
}
void main(void){
porta=0x00; set_tris_a(0b00000000); portb=0x00; set_tris_b(0b11111111); portc=0x00; set_tris_c(0b10000000); portd=0x00; set_tris_d(0b00000000); porte=0x00; set_tris_e(0b00001000);
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
enable_interrupts(GLOBAL);
while(true){
}
}