Sie sind auf Seite 1von 4

Funciones incorporadas en RGNKeyLCD:

RGN_GetKeyCode
Función que obtiene el Código de Tecla (1..16) del Keypad (4x4)de Proteus KEYPAD-SMALLCALC
0 : Tecla NO presionada
1..16: Corresponde a una de las 16 teclas del Keypad
RGN_GetKeyMask
Función que obtiene el Caracter correspondiente al KEYPAD-SMALLCALC
RGN_InputByte( variable tipo Byte)
Función que obtiene un Byte del Keypad
"=" es la tecla de ingreso ENTER
"C" es la tecla de retroceso SUPR
RGN_InputDato(variable tipo RGN_StructDato )
Procedimiento que obtiene un Dato controlado del Keypad
La primera fila del LCD muestra el Texto del Dato a ingresar
La segunda fila muestra el Valor actual y el Rango (Mínimo … Máximo) permitido
En caso de que el Dato introducido este fuera de Rango, se muestra un mensaje de error y se vuelve a pedir el Dato
Estructura de la variable RGN_StructDato usada por procedimiento RGN_InputDato:
DTxt: Texto a mostrar en el LCD
DVal: Valor por default del dato
DMin: Rango Mínimo del dato
DMax: Rango Máximo del dato
program TestRGNKeyLcd

include "RGNKeyLCD"

' Lcd module connections


dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit

LCD_RS_Direction as sbit at TRISB4_bit


LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections

' Keypad module connections


dim keypadPort as byte at PORTC
' End of keypad module connections

'Variables para las Pruebas


dim Codigo as byte
dim CodigoStr as string[3]
dim CodigoChr as char
dim CodigoDefault as byte
dim Valor as RGN_StructDato

main:
Lcd_Init()
Keypad_Init()
LCD_Cmd(_LCD_CURSOR_OFF)

'Prueba funcion RGN_GetKeyCode


bucle:
Codigo=RGN_GetKeyCode
ByteToStr(Codigo,CodigoStr)
LCD_Out(1,1,CodigoStr)
goto bucle

'Prueba funcion RGN_GetKeyMask


' bucle:
' CodigoChr=RGN_GetKeyMask
' LCD_Chr(1,1,CodigoChr)
' goto bucle

'Prueba funcion RGN_InputByte


' CodigoDefault=10
' bucle:
' LCD_Cmd(_LCD_CLEAR)
' LCD_Out(1,1,"Digite:")
' Codigo=RGN_InputByte(CodigoDefault)
' Codigo=Codigo/2
' ByteToStr(Codigo,CodigoStr)
' LCD_Out(2,1,"Codigo/2:")
' LCD_Out(2,9,CodigoStr)
' Delay_ms(750)
' goto bucle

'Prueba procedure RGN_InputDato


' Valor.DTxt="Temperatura="
' Valor.DVal=50
' Valor.DMin=15
' Valor.DMax=75
' bucle:
' LCD_Cmd(_LCD_CLEAR)
' RGN_InputDato(Valor)
' Codigo=Valor.Dval/2
' ByteToStr(Codigo,CodigoStr)
' LCD_Cmd(_LCD_CLEAR)
' LCD_Out(1,1,"Temperatura/2=")
' LCD_Out(2,1,CodigoStr)
' Delay_ms(1000)
' goto bucle
end.
module RGNKeyLCD
const RGN_KeyMask as string[16]= ("7","4","1","C"
,"8","5","2","0"
,"9","6","3","="
,"/","*","-","+")

'Estructura de la variable RGN_StructDato usada por procedimiento RGN_InputDato


' DTxt: Texto a mostrar en el LCD
' DVal: Valor por default del dato
' DMin: Rango Minimo del dato
' DMax: Rango Maximo del dato
structure RGN_StructDato
dim DTxt as string[13]
dim DVal,DMin,DMax as byte
end structure

sub function RGN_GetKeyCode as byte


sub function RGN_GetKeyMask as char
sub function RGN_InputByte(dim Dato as byte) as byte
sub procedure RGN_InputDato(dim byref SDato as RGN_StructDato)

implements

'---------------------------------------------------------------------------
'Funcion que obtiene el Codigo de Tecla del Keypad de Proteus KEYPAD-SMALLCALC
' 0 : Tecla NO presionada
' 1..16: Corresponde a una de las 16 teclas del keypad
' 1 5 9 13
' "7" "8" "9" "-"

' 2 6 10 14
' "4" "5" "6" "*"

' 3 7 11 15
' "1" "2" "3" "-"

' 4 8 12 16
' "C" "0" "=" "+"

sub function RGN_GetKeyCode as byte


dim Tecla as byte
Tecla=0
while Tecla = 0
Tecla = Keypad_Key_Click()
wend
result=Tecla
end sub

'---------------------------------------------------------------------------
'Funcion que obtiene el Caracter correspondiente al KEYPAD-SMALLCALC
sub function RGN_GetKeyMask as char
result=RGN_KeyMask[RGN_GetKeyCode-1]
end sub

'---------------------------------------------------------------------------
'Funcion que obtiene un Byte del keypad
' "=" es la tecla de ingreso ENTER
' "C" es la tecla de retroceso SUPR
sub function RGN_InputByte(dim Dato as byte) as byte
dim Cont as byte
dim Tecla as char
dim DatoStr as string[3]
Cont=0
DatoStr=""
do
Tecla=RGN_GetKeyMask
select case Tecla
case "=","/","*","-","+" 'Hacer NADA

case "C" 'Retroceder


if Cont>0 then
Lcd_Cmd(_Lcd_Move_Cursor_Left)
Lcd_Out_Cp(" ")
Lcd_Cmd(_Lcd_Move_Cursor_Left)
Dec(Cont)
else
Cont=0
end if
case else 'Incluir caracter
DatoStr[Cont]=Tecla
Lcd_Chr_Cp(Tecla)
Inc(Cont)
end select
loop until ((Cont>2) or (Tecla="="))
DatoStr[Cont]=0 'Terminar string
if Cont=0 then
Result=Dato
else
Result=StrToWord(DatoStr)
end if
end sub

'---------------------------------------------------------------------------
'Procedimiento que obtiene un Dato controlado del keypad
'La primera fila del LCD muestra el Texto del Dato a ingresar
'La segunda fila muestra el Valor actual y el Rango (Minimo..Maximo) permitido
'En caso de que el Dato introducido este fuera de Rango, se muestra un
'mensaje de error y se vuelve a pedir el Dato
sub procedure RGN_InputDato(dim byref SDato as RGN_StructDato)
dim SDatoStr as string[3]
dim Dato,Range_Ok as byte
do
Lcd_cmd(_Lcd_Clear)
Lcd_Out(2,1,"val= .. ")
ByteToStr(SDato.DVal,SDatoStr)
Lcd_Out(2,5,SDatoStr) 'Mostrar Valor en fila 2
ByteToStr(SDato.DMin,SDatoStr)
Lcd_Out(2,9,SDatoStr) 'Mostrar Minimo en fila 2
ByteToStr(SDato.DMax,SDatoStr)
Lcd_Out(2,14,SDatoStr) 'Mostrar Maximo en fila 2
Lcd_Out(1,1,SDato.DTxt) 'Mostrar Texto en fila 1

Lcd_cmd(_Lcd_Blink_Cursor_On)
Dato=RGN_InputByte(SDato.Dval) 'Obtener Dato
Lcd_cmd(_Lcd_Cursor_Off)
'Comprobar el rango
Range_Ok=(Dato>=SDato.DMin) and (Dato<=SDato.DMax)

if Not Range_Ok then


Lcd_Out(2,1," Error de Rango ")
Delay_ms(500)
else
SDato.Dval=Dato 'Convalidar Dato
end if
loop until Range_Ok
end sub
end.

Das könnte Ihnen auch gefallen