'****************************************************************
'* Name : termo.pbp *
'* Author : Max. E. Reyes Vera Juarez *
'* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 07/12/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
include "fp20.bas" ' INCLUIR RUTINA DE PUNTO FLOATANTE
Define __16F877 1 ' DEFINICION DE MCU
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTA ' DEFINICION DE LOS REGISTROS DEL LCD
Define LCD_RSBIT 2
Define LCD_EREG PORTA
Define LCD_EBIT 5
Define ADC_CLOCK 3 ' PONIENDO EN 3 EL RELOJ DE LA FUENTE
Define ADC_BITS 10 ' NUMERO DE BITS DEL RESULTADO
Define ADC_SAMPLEUS 15 ' SETEO DEL TIEMPO DE MEDICION
TRISA = 11 ' PUERTO A 3 ENTRADAS Y 3 SALIDAS
TRISB = 127
ADCON1 = 142 ' PUERTO A COMO ADC Y JUSTIFICACION A LA DERECHA
OPTION_REG.7 = 0 ' HABILITAR PULL-UPS
Low PORTA.4 ' APAGO LINEA DEL LCD R/W (W)
Pause 500 ' PAUSA PARA LCD
sensor var word ' VARIABLE PARA GUARDAR EL VALOR DE ADC
fpplaces var byte ' USADO PARA DEFINIR LA POSICION DEL PUNTO
ahold var word ' REQUERIDO POR FPDISPLAYR
bhold var word ' REQUERIDO POR FPDISPLAYR
resulthold VAR word ' VARIABLE PARA REALIZAR OPERACIONES CON FP
TERMO VAR PORTA.0
PROG1 VAR PORTB.0 ' ALIAS PIN RB0
PROG2 VAR PORTB.1 ' ALIAS PIN RB1
PROG3 VAR PORTB.2 ' ALIAS PIN RB2
PROG4 VAR PORTB.3 ' ALIAS PIN RB3
HTEMP VAR PORTB.4 ' ALIAS PIN RB4
LTEMP VAR PORTB.5 ' ALIAS PIN RB5
EXIT VAR PORTB.6 ' ALIAS PIN RB6
INIT: 'inicio de la rutina principal
lcdout $fe,1, " TEMPERATURA DE:" 'mostramos mensaje en la primer linea del LCD
LCDOUT $FE,$C0 'nos pasamos a la segunda linea del LCD
ADCIN TERMO, sensor ' Adquirimos el valor del ADC en RA0 y se guarda en variable sensor
resulthold=(sensor*104)
aint=resulthold
gosub itofa
bint=213
gosub itofb
gosub fpdiv
fpplaces=2: gosub fpdisplayr
pause 50
goto init
' LA RUTINA FPDISPLAYR VERIFICA EL NUMERO DE LUGARES, LUEGO AÑADE EL VALOR
' APROPIADO PARA EL REDONDEO. PARA SALVAR ESPACIO EN LA RAM, LOS VALORES SON
' DIFICILES DE CODIFICAR EN FORMATO DE PUNTO FLOTANTE
fpdisplayr: If fpplaces=0 Then ' Set floating point barg to 0.5
bexp = $7E
bargb0 = $00
bargb1 = $01
Endif
If fpplaces=1 Then ' Set floating point barg to 0.05
bexp = $7A
bargb0 = $4C
bargb1 = $CD
Endif
If fpplaces=2 Then ' Set floating point barg to 0.005
bexp = $77
bargb0 = $23
bargb1 = $D8
Endif
If fpplaces=3 Then ' Set floating point barg to 0.0005
bexp = $74
bargb0 = $03
bargb1 = $13
Endif
If fpplaces=4 Then ' Set floating point barg to 0.00005
bexp = $70
bargb0 = $51
bargb1 = $B7
Endif
If aargb0.7 Then ' Check the floating point sign bit
Gosub fpsub ' If negative, subtract barg from aarg
Else
Gosub fpadd ' If positive, add barg to aarg
Endif
' The fpdisplay routine outputs the signed value of aarg in decimal floating point format. It
' can display an absolute value of 32767, and decimals to 4 places. The number of decimal
' places should be stored in fpplaces before calling the routine. The routine reads the
' floating point value of aarg. This value should NOT be converted to an integer before
' calling fpdisplay. The integer conversion will be perfomed as part of this routine, and
' aint will be returned to the calling program just as from the itofa routine.
fpdisplay: bexp = aexp ' Store the FP value of aarg to the barg variables
bargb0 = aargb0
bargb1 = aargb1
Gosub ftoia ' Convert aarg to integer
ahold = aint ' Save this value for the final display
Gosub itofa ' Convert integer back to float
Swap aexp,bexp ' Swap the FP values of aarg and barg before subtraction
Swap aargb0,bargb0
Swap aargb1,bargb1
Gosub fpsub ' Subtract the integer portion from the full number
bint = 10 ' Make bint = 10 E fpplaces
If fpplaces=2 Then
bint = 100
Endif
If fpplaces=3 Then
bint = 1000
Endif
If fpplaces=4 Then
bint = 10000
Endif
bhold = bint ' Save the integer value of bint for zeros loop
Gosub itofb ' Convert bint to integer prior to FP multiply
Gosub fpmul ' Multiply the decimal portion x 10 E fpplaces
Gosub ftoia ' Convert result to aint integer
If (ahold.15) OR (aint.15) Then ' Check for negative integer or decimal
Lcdout "-" ' Display minus
' Serout2 spin,sbaud,["-"] ' Use for 2400 bps serial output
Endif
Lcdout " ", dec abs ahold ' Display integer portion
' Serout2 spin,sbaud,[dec abs ahold] ' Use for 2400 bps serial output
If fpplaces > 0 Then
Lcdout "."
' Serout2 spin,sbaud,["."] ' Use for 2400 bps serial output
zeros: bhold = bhold / 10 ' Set bhold to be next place to right
If (abs aint < bhold) AND (bhold > 1) Then ' Check for leading zero in decimal
Lcdout "0" ' Display leading zero
' Serout2 spin,sbaud,["0"] ' Use for 2400 bps serial output
Goto zeros ' loop to check for another zero
Endif
Lcdout dec abs aint ' Display the rest of the decimal portion
lcdout " ßC" ' muestra ºC
' Serout2 spin,sbaud,[dec abs aint] ' Use for 2400 bps serial output
Endif
aint = ahold ' Restore the original value of aint
Return