#include <16f88.h>
#fuses NOWDT,NOPROTECT,PUT
#fuses NOMCLR,INTRC_IO
#ZERO_RAM
#use delay(clock = 4000000)
#use rs232(baud=9600,rcv=PIN_B0, parity=N, bits=8, errors)
#use fast_io(A)
#use fast_io(B)
/************************************************************************
* I/O
************************************************************************/
#byte PORTA = 5 // Salida
#byte PORTB = 6 // Entradas
#byte PCL = 2
#bit Act_linea = PORTA.2 // Activa línea telefónica
#bit LED = PORTA.3 // LED Tiempo de grabación EEPROM
#bit IN1 = PORTB.1 // Entrada 1
#bit IN2 = PORTB.2 // Entrada 2
#bit DS1 = PORTB.4 // DIP Switch 1
#bit DS2 = PORTB.4 // DIP Switch 2
/***********************************************************************
* Definicion de Variables
***********************************************************************/
#define HI_PIN 0x02 // RA1 Tono alto
#define LOW_PIN 0x01 // RA0 Tono Bajo
unsigned char temp[40];
unsigned int i;
unsigned long j;
int EEADR;
unsigned long timeout;
int NumTelf;
int ttono;
/***********************************************************************
* Prototipos
***********************************************************************/
void delay_seg(int n);
void dtmfsend(int NumTelf, ttono);
void LeerEEprom(int EEADR);
/*-----------------------------------------------------------------------*/
void main(void) {
/*-----------------------------------------------------------------------*/
int NumRep;
set_tris_a(0x00);
set_tris_b(0xFF);
EEADR = 0;
LED = 1;
i = 0;
for(j=0; j < 100; j++)
{
timeout =0;
while(!kbhit()&&(++timeout<5000))
delay_us(10);
if(kbhit())
}
LED = 0; // Fin tiempo lectura puerto Serial
if(i != 0) // si i = 0 go to continuar.......
{
for(j=0; j< i; j++)
{
write_eeprom(EEADR,temp[j]);
EEADR++; // incrementa direccion EEPROM
}
}
if(!DS1 && !DS2)
while(IN2 == 1);
else
if(!DS1 && DS2)
while(IN2 == 0);
else
if(DS1 && DS2)
while(IN1 == 1 || IN2 == 1);
else
if(DS1 && DS2)
while(IN1 == 1 || IN2 == 0);
EEADR = 0x00;
LeerEEprom(EEADR);
NumRep = NumTelf;
do{
i = 1;
EEADR =0x02;
while(i < 4){
Act_linea = 1;
delay_seg(3);
LeerEEprom(EEADR);
while(NumTelf != 0x2f) {
dtmfsend(NumTelf, 0x41);
delay_ms(300);
EEADR++;
LeerEEprom(EEADR);
}
delay_seg(5);
for(j=0;j<20;j++)
{
dtmfsend(12, 0xff);
delay_seg(1);
}
i++;
EEADR++;
Act_linea = 0;
delay_seg(5);
}
Act_linea = 0;
delay_seg(5);
NumRep--;
} while(NumRep !=0);
}
void dtmfsend(int NumTelf, ttono) {
int low_count;
int high_count;
int salva_low_count;
int salva_high_count;
int high_tone_count;
int low_tone_count;
int temporal;
#asm
inicio:
movf NumTelf,0
andlw 0x0f ; key en W
movwf temporal ; Salva Key en tmp
call tabla_low_count ; Contador retardo tono bajo -> w
movwf salva_low_count ; Salva contador retardo tono bajo
movwf low_count
movf temporal,0 ; Key -> w
call tabla_high_count ; Contador retardo tono alto -> w
movwf salva_high_count ; Salva contador retardo tono alto
movwf high_count
clrf low_tone_count ; Tiempo tono 255 +
movlw ttono ; ttono en hdcnt
movwf high_tone_count ;
bucle:
clrwdt
nop
bucle1:
movlw (HI_PIN + LOW_PIN)
decfsz low_count,1 ; Si ambos contadores (lowcnt, highcnt)
andlw HI_PIN ; no han llegado a cero, w = B'00000000'
decfsz high_count,1 ; Si lowcnt llega a cero w = B'00000001'
andlw LOW_PIN ; Selecionado RB0. Si highcnt llega a cero
; w = B'00000010' seleccionando RB1
movwf temporal ; Salva w en tmp
xorwf PORTA,1 ; toggle RB selecionado
movf salva_low_count,0 ; Contador de retardo tono bajo -> w
btfsc temporal,0 ; Si RB0 selecionado
movwf low_count ; W -> lowcnt
movf salva_high_count,0 ; Contador de Retardo tono Alto -> w
btfsc temporal,1 ; Si Rb1 selecionado
movwf high_count ; W -> highcnt
decfsz low_tone_count,1 ; 1/2
goto bucle ; 2 3x255x hdcnt
decfsz high_tone_count,1 ; 1/2
goto bucle1 ; 2
goto fin
tabla_low_count: ; Contadores de retardo tonos bajos
addwf PCL,1
retlw 29
retlw 40
retlw 40
retlw 40
retlw 36
retlw 36
retlw 36
retlw 32
retlw 32
retlw 32
retlw 40
retlw 36
retlw 32
retlw 29
retlw 29
retlw 29
tabla_high_count: ; Contadores de retardo tonos altos
addwf PCL,1
retlw 21
retlw 23
retlw 21
retlw 19
retlw 23
retlw 21
retlw 19
retlw 23
retlw 21
retlw 19
retlw 17
retlw 17
retlw 17
retlw 17
retlw 23
retlw 19
fin:
#endasm
}
void LeerEEprom(int EEADR){
int eedata;
eedata=read_eeprom(EEADR);
switch(eedata) {
case 0x30:
NumTelf = 0;
break;
case 0x31:
NumTelf = 1;
break;
case 0x32:
NumTelf = 2;
break;
case 0x33:
NumTelf = 3;
break;
case 0x34:
NumTelf = 4;
break;
case 0x35:
NumTelf = 5;
break;
case 0x36:
NumTelf = 6;
break;
case 0x37:
NumTelf = 7;
break;
case 0x38:
NumTelf = 8;
break;
case 0x39:
NumTelf = 9;
break;
case 0x2f:
NumTelf = eedata;
break;
}
}
void delay_seg(int n) {
for(;n!=0; n--)
delay_ms(1000);
}