[code' Program to create telephone pad tone
' Oscillator must be set to 20MHz
DEVICE = 16F628a
XTAL = 4
ALL_DIGITAL = TRUE
PORTB_PULLUPS = ON ' Enable PORTB pull-ups
LCD_DTPIN = PORTb.4
LCD_RSPIN = PORTa.0
LCD_ENPIN = PORTa.2
LCD_INTERFACE = 4 ' 4-bit Interface
LCD_LINES = 2
LCD_TYPE = 0
' Define program variables
Dim Col as Byte ' Keypad column
Dim Row as Byte ' Keypad row
Dim Key as Byte ' Key value
Dim Tone as Byte ' Tone number
dim XLCD as Byte
dim YLCD As Byte
dim Pitch as byte
dim Clave as Byte
dim Digitos as byte
dim Posicion as byte
dim Leer as byte
' Define program Symbol
Symbol Altavoz = PORTa.1 ' Alias speaker pin
Symbol Rele = porta.3
symbol Led = porta.4
'trisa=%11111111
Delayms 50 ' Estavilizacion LCD
' Comienza el programa ran-up
'********************1234567890123456
high Led
Print at 1,1,"Teclado / Clave "
Print at 2,1,"IBERICA 2000/1.0"
Delayms 2000
low led
cls
Cero: posicion = 0
digitos = 0
Inicio:
'*********************************************************************************
'*** Lee EEprom para conprovar que la memoria
'*** no se a escrito nunca y pide clave nueva
'*********************************************************************************
Leer = eread 0 'LEE EL LA EEPROM LA POSICION CERO
if Leer = $FF then Nueva 'COMPUEBA QUE VALE LA POSICION CERO
goto vieja 'SI VALE FF PIDE CLAVA NUEVA, SI NO VA A VIEJA
Nueva:
high Led
'********************1234567890123456
Print at 1,1,"Leyendo Memoria "
Print at 2,1," Codigo Activa "
Delayms 2000
cls
'********************1234567890123456
print at 1,1," Clave Nueva: "
print at 2,1,"> <"
xlcd=2
ylcd=2
Otra: 'SE GENERA UN BUCLE DE PARA INTRODUCIR 4 DIGITOS
For digitos = 0 to 3
Gosub Getkey
Lookup Tone,["0123456789*0#"],Key'
ewrite Posicion,[key] 'GRABA EN LA EEPROM LAS TECLAS PULSADAS
posicion = posicion +1 'INCREMENTA UNA POSICION EN LA EEPROM
Print at Xlcd,ylcd, Key 'INPRIMA EL LA LCD LA TECLA PULSADA
ylcd = ylcd +1 'INCREMENTA CURSOR A LA DERECHA
Dtmfout Altavoz, [Tone] 'GENERA TONO DE GRABACION
Next 'SALE DEL BUCLE
'****************** 1234567890123456
Print Cls, "CLAVE Grabada " '
print at 2,1,"En Memoria EEPro"
Dtmfout Altavoz, [12]
Delayms 2000
cls
Vieja:
high Led
'****************** 1234567890123456
Print Cls, " Teclea Clave"
print at 2,1,"> <"
xlcd = 2
ylcd = 2
Clave = 0
Digitos = 0
' Oprotunidad = 0
Posicion = 0
Loop:
if ylcd >= 17 then Inicio
Gosub Getkey ' Get a key from the keypad
Leer = eread Posicion
posicion = posicion + 1
Lookup Tone,["0123456789*0#"],Key
Print at Xlcd,ylcd,Key
if Leer = Key then Clave = Clave + 1
ylcd = ylcd +1
Dtmfout Altavoz, [Tone]
if ylcd = 6 then Compara
Goto Loop ' Do it forever
Compara:
if Clave = 4 Then Abre
Cierra:
'****************** 1234567890123456
print cls , "Acceso Denegado"
Dtmfout Altavoz, [3]
Delayms 2000
goto vieja
Abre: high Rele
print Cls , "Acceso Permitido"
For Pitch = 0 to 120
Sound Altavoz,[Pitch,1]
Next
Delayms 2000
low Rele
goto vieja
' Subroutine to get a key from keypad
Getkey:
Delayms 50 ' Debounce
Getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If (PORTB >> 4) <> $0F Then Getkeyu ' If any keys down, loop
Delayms 50 ' Debounce
Getkeyp:
' Wait for keypress
For Col = 0 To 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (Dcd Col) ^ $FF ' Set one column pin to output
Row = PORTB >> 4 ' Read row
If Row <> $0F Then Gotkey ' If any keydown, exit
Next
Goto Getkeyp ' No keys down, go look again
' Change row and column to key number 0 - 15
Gotkey:
Key = (Col * 3) + (Ncd (Row ^ $0F)) -1
'Key = (Col * 3) + (Ncd (Row ^ $0F))
' Translate key to telephone keypad tone
' 10 = *
' 11 = #
' 12 = A
' 13 = B
' 14 = C
' 15 = D
Lookup Key,[1,2,3,4,5,6,7,8,9,10,11,12],Tone
Return ' Subroutine over
End]