'****************************************************************
'* Name : RelTerm.BAS *
'* Author : Miguel Noe Garcia Perez *
'* Notice : Copyright (c) 2010 Iberica 2000 *
'* : All Rights Reserved *
'* Date : 09/03/2010 *
'* Version : 1.0 *
'* Notes : Reloj Termometro *
'* : *
'****************************************************************
Device 16F877a
XTAL = 4
' LCD pin Configuracion
lcd_type = 0
LCD_LINES = 4
LCD_DTPIN = PORTb.4
LCD_RSPIN = PORTb.3
LCD_ENPIN = PORTb.2
LCD_INTERFACE = 4
SCL_PIN = PORTC.3
SDA_PIN = PORTC.4
'***************************************************************************************
Cls ' Clear LCD
ALL_DIGITAL = True ' Set ports to digital mode
Clear ' Clear buffers
'******************************************************************************************
'********************* SIMBOLOS DEL PROGRAMA *********************************************
'******************************************************************************************
Symbol DQ = PORTB.1 ' Pin de conexión 1-Wire®
Symbol Seg = 0 ' Registro de Seg.
Symbol Minu = 1 ' Registro de Min.
Symbol Hora = 2 ' Registro de Horas
Symbol Dia = 3 ' Registro de Día
Symbol Dias = 4 ' Registro de Día
Symbol Mes = 5 ' Registro de Mes
Symbol Ano = 6 ' Registro de Año
Symbol Control = 7
Symbol SW1 = PORTb.4 ' Interruptor Set
Symbol SW2 = PORTB.5 ' Interruptor Incre
Symbol SW3 = PORTB.6 ' Interruptor Intro
Symbol SW4 = PORTB.7 ' Interruptor Extra
'*******************************************************************************************
'*************************** VARIABLES A$ **************************************************
'*******************************************************************************************
Dim Index As Byte ' Variable de uso general
Dim ROMCODE[8] As Byte ' Arreglo almacena el serial
Dim SERIAL[8] As Byte ' Arreglo almacena serial
Dim X As Word
Dim Contador As Word
Dim TEMPERATURA As Word ' Variable alm. temperatura
Dim FL_TEMP As Float ' Variable alm. temperatura
'Dim FL_TEMP As word ' Variable alm. temperatur
DIM Cifra as byte
Dim Sign as Byte
Dim Cnt as Byte
Dim Count_Per_Deg as Byte
Dim Temp as Word
Dim Temp_Dec as Byte
DIM Puntero AS BYTE
Dim RTC[8] As Byte ' Vector almacenamiento
'Dim Index As Byte ' Variable uso general
dim Btnvar as byte ' Pulsadores
dim Horas as byte
dim Minutos as Byte
dim Day As Byte
dim Days As Byte
dim Meses As Byte
Dim Anos As Byte
'**************************************************************************************
'************************* P R E S E N T A C I O N ************************************
'**************************************************************************************
'**************************************************************************************
'******************************* TERMOMETRO *******************************************
'**************************************************************************************
MAIN:
GoSub Conversion ' Rutina convertir Temperatura
GoSub Mostrar ' Rutina mostrar los valores
DelayMS 500
'Gosub Text
GoTo Main
End
Conversion2:
OWrite DQ,1,[$44] ' Comando Convertir Temp
High DQ ' DQ en alto por 750 ms
'******************* Tiempo de Conversion ************************
DelayMS 200 'Nota: Para el DS 1820 200 ms y para el DS 18S20 750 ms
OWrite DQ,1,[$CC,$BE] ' Comando leer SCRATCHPAD.
ORead DQ,0,[TEMP.LowByte,TEMP.HighByte]
Return
Conversion:
OWrite DQ,1,[$CC,$44] ' Comando Convertir Temp
'gosub Resete
High DQ ' DQ en alto por 750 ms
'******************* Tiempo de Conversion ************************
'DelayMS 200 'Nota: Para el DS 1820 200 ms y para el DS 18S20 750 ms
OWrite DQ,1,[$CC,$BE] ' Comando leer SCRATCHPAD.
'ORead DQ,0,[TEMP.LowByte,TEMP.HighByte]
OREAD DQ,2,[Temp.LOWBYTE,Temp.HIGHBYTE,Cnt,Cnt,Cnt,Cnt,Cnt,Count_Per_Deg] 'Lee el scratchpad
Return
Mostrar:
Temp_Dec = (6.25 * Cnt)
'Signo:
If Temp.8=1 Then
Temp=(Temp.LowByte ^ $FF) >> 1
If Cnt = 0 then Temp = Temp + 1
Sign = "-"
Else
Temp=(Temp >> 1)
Sign = " "
Temp_Dec = 100 - Temp_Dec
Endif
cls
Print at 1,1, "T",Sign, Dec Temp,".", Dec DIG Temp_Dec,1
'Print at 2,1, "T= ",dec TEMPERATURA
'Return
cls
GoSub RTC_INI ' Inicilizar el RTC
GoSub FECHA_INI ' Cargar Fecha inicial
' DelayMS 500 ' Retardo 500ms
Loop:
GoSub LEER_RTC ' Leer registros RTC
GoSub MOSTRAR_RTC ' Mostrat registros RTC
gosub Pulsadores
'DelayMS 1000
GoTo Loop
End
RTC_INI:
BusIn $D1,0,[RTC[Seg]] ' Lee byte 0, RTC
BusOut $D0,0,[RTC[Seg] & $7F] ' Pone 0 en bit CH
Return ' Para Activar RTC
FECHA_INI:
RTC[Seg] = $50 ' Ajusta los Seg. iniciales
RTC[Minu]= $59 ' Ajusta los Min. iniciales
RTC[Hora]= $0F ' Ajusta la Hora inicial
RTC[Dia] = $20 ' Ajusta el Día inicial
rtc[Dias]= $01 ' Ajuste del dia lunes Martes
RTC[Mes] = $02 ' Ajusta el Mes inicial
RTC[Ano] = $08 ' Ajusta el Año inicial
rtc[Control]=$10 ' Ajunte Reg Control
BusOut $D0,0,[Str RTC\8] ' Escribe registros RTC
Return
LEER_RTC:
For Index = 0 To 6
BusIn $D1,Index,[RTC[Index]] ' Lee registros
Next ' del RTC 0..6
GoSub BCD2BIN
Return
MOSTRAR_RTC:
print at 1,1,DEC2 RTC[Hora], ":", DEC2 RTC[Minu],":", DEC2 RTC[Seg]
print at 2,1,DEC2 RTC[Dia], "/", DEC2 RTC[Mes],"/20", DEC2 RTC[Ano]
'print at 4,1,$FE,$10,$FE,$10,$FE,$10,$FE,$10,"Reloj"
select rtc[Dias]
case 1
print at 1,10,"Lunes"
case 2
print at 1,10,"Martes"
case 3 '23456
print at 1,10,"Mierc."
case 4 '23456
print at 1,10,"Jueves"
case 5 '23456
print at 1,10,"Viernes"
case 6 '23456
print at 1,10,"Sabado"
case 7 '23456
print at 1,10,"Domingo"
end select
'print at 3,1,"DIAS:", dec2 rtc[Dias]
Return
BCD2BIN:
For Index = 0 To 6
RTC[Index] = (RTC[Index]/16)*10 + RTC[Index] & $0F
Next
Return
Pulsadores:
NoPress2: button sw1,0,255,250,Btnvar,0,retur
goto Ajuste
Retur:
return
'NoPress1: button sw2,0,255,250,Btnvar,0,NoPress3
' ValorPantalla = ValorPantalla -1: goto Ver
'NoPress3: button sw3,0,255,250,Btnvar,0,NoPress2
' GOTO EnterVer
' ' goto NoPress2
Ajuste:
'cls
print at 1,1,DEC2 RTC[Hora], ":", DEC2 RTC[Minu],":", DEC2 RTC[Seg]
print at 2,1,DEC2 RTC[Dia], "/", DEC2 RTC[Mes],"/20", DEC2 RTC[Ano]
print at 3,1,$FE,$10,$FE,$10,$FE,$10,$FE,$10,"......SET......."
'HorasPut: print at 4,1,$FE,$10,$FE,$10,$FE,$10,$FE,$10,"Hora: ",dec2 RTC[Hora]
if RTC[Hora] >= 24 then RTC[Hora]= $00
Seting: button sw4,0,255,250,Btnvar,0,Ae
dec RTC[Hora]:delayms 200:Goto Ajuste
Ae:
button sw2,0,255,250,Btnvar,0,Be
inc RTC[Hora]:delayms 200:Goto ajuste
Be:
button sw3,0,255,250,Btnvar,0,Ajuste
BusOut $D0,2,[RTC[Hora]] ' Escribe registros RTC
'DelayMS 500 ' Retardo 500ms
'GoSub LEER_RTC ' Leer registros RTC
cls
GOTO loop
NoPull:
Seting2:
delayms 200
'**************************************************************************************
'********* TODO ESTO ES DE MI AMIGO TRIGO TODOS LOS DERECHOS SON DE TRIGO *************
'**************************************************************************************
'PRIMERO IMPRIMIMOS LAS DECENAS
Cifra = dig temp, 1 'Decenas de grado.
Puntero = 64 'Primer carácter de la CGRAM, numerado como 0
Gosub Que_cifra
print AT 1,9, 0,1
print AT 2,9, 2,3
'Y A CONTINUACIÓN LAS UNIDADES
Cifra = dig temp, 0 'Unidades de grado.
Puntero = 96 'Quinto carácter de la CGRAM, numerado como 4
Gosub Que_cifra
print AT 1,11, 4,5, "TEMP"
print AT 2,11, 6,7, ".",Dec DIG Temp_Dec, 1, 223 'el 223 es el símbolo de grado
return
Que_cifra:
select Cifra.
case 0: gosub cero: RETURN 'Rutinas para crear los gráficos correspondientes a esas cifras en gran formato
CASE 1: GOSUB UNO: RETURN
CASE 2: GOSUB DOS: RETURN
CASE 3: GOSUB TRES: RETURN
CASE 4: GOSUB CUATRO: RETURN
CASE 5: GOSUB CINCO: RETURN
CASE 6: GOSUB SEIS: RETURN
CASE 7: GOSUB SIETE: RETURN
CASE 8: GOSUB OCHO: RETURN
CASE 9: GOSUB NUEVE: RETURN
ENDSELECT
'CARGANDO LOS CARACTERES PERSONALIZADOS EN LA CGRAM
CERO:
'SI:
Print 254,Puntero,$07,$0F,$1C,$18,$18,$18,$18,$18
'SD:
Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$06,$06,$06
'II:
Print 254,Puntero + 16,$18,$18,$18,$18,$18,$1C,$0F,$07
'ID:
Print 254,Puntero + 24,$06,$06,$06,$06,$06,$0E,$1C,$18
RETURN
UNO:
'SI:
Print 254,Puntero,$00,$00,$00,$01,$01,$00,$00,$00
'SD:
Print 254,Puntero + 8,$0C,$1C,$1C,$1C,$1C,$0C,$0C,$0C
'II:
Print 254,Puntero + 16,$00,$00,$00,$00,$00,$00,$00,$00
'ID:
Print 254,Puntero + 24,$0C,$0C,$0C,$0C,$0C,$0C,$1E,$1E
RETURN
DOS:
'SI:
Print 254,Puntero,$07,$0F,$1C,$18,$00,$00,$00,$00
'SD:
Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$06,$0E,$1C
'II:
Print 254,Puntero + 16,$01,$03,$07,$0E,$1C,$18,$1F,$1F
'ID:
Print 254,Puntero + 24,$18,$10,$00,$00,$00,$00,$1E,$1E
RETURN
TRES:
'SI:
Print 254,Puntero,$07,$0F,$1C,$18,$00,$00,$01,$01
'SD:
Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$0E,$1C,$18
'II:
Print 254,Puntero + 16,$00,$00,$00,$18,$18,$1C,$0F,$07
'ID:
Print 254,Puntero + 24,$1C,$0E,$06,$06,$06,$0E,$1C,$18
RETURN
CUATRO:
'SI:
Print 254,Puntero,$00,$00,$01,$01,$03,$03,$07,$06
'SD:
Print 254,Puntero + 8,$1C,$18,$18,$10,$10,$00,$00,$00
'II:
Print 254,Puntero + 16,$0E,$0C,$1C,$1F,$1F,$00,$00,$00
'ID:
Print 254,Puntero + 24,$0C,$0C,$0C,$1E,$1E,$0C,$0C,$0C
RETURN
CINCO:
'SI:
Print 254,Puntero,$1F,$1F,$18,$18,$18,$18,$1F,$1F
'SD:
Print 254,Puntero + 8,$1E,$1E,$00,$00,$00,$00,$18,$1C
'II:
Print 254,Puntero + 16,$00,$00,$00,$00,$18,$1C,$0F,$07
'ID:
Print 254,Puntero + 24,$0E,$06,$06,$06,$06,$0E,$1C,$18
RETURN
SEIS:
'SI:
Print 254,Puntero,$07,$0F,$1C,$18,$18,$18,$1B,$1F
'SD:
Print 254,Puntero + 8,$18,$1C,$0E,$06,$00,$00,$18,$1C
'II:
Print 254,Puntero + 16,$1C,$18,$18,$18,$18,$1C,$0F,$03
'ID:
Print 254,Puntero + 24,$0E,$06,$06,$06,$06,$0E,$1C,$18
RETURN
SIETE:
'SI:
Print 254,Puntero,$1F,$1F,$00,$00,$00,$00,$00,$01
'SD:
Print 254,Puntero + 8,$1E,$1E,$06,$0E,$0C,$1C,$18,$18
'II:
Print 254,Puntero + 16,$01,$03,$03,$07,$06,$0E,$0C,$0C
'ID:
Print 254,Puntero + 24,$10,$10,$00,$00,$00,$00,$00,$00
RETURN
OCHO:
'SI:
Print 254,Puntero,$07,$0F,$1C,$18,$18,$1C,$0F,$0F
'SD:
Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$0E,$1C,$18
'II:
Print 254,Puntero + 16,$1C,$18,$18,$18,$18,$1C,$0F,$03
'ID:
Print 254,Puntero + 24,$0E,$06,$06,$06,$06,$0E,$1C,$18
RETURN
NUEVE:
'SI:
Print 254,Puntero,$07,$0F,$1C,$18,$18,$18,$18,$1C
'SD:
Print 254,Puntero + 8,$18,$1C,$0E,$06,$06,$06,$06,$0E
'II:
Print 254,Puntero + 16,$0F,$07,$00,$00,$18,$1C,$0F,$07
'ID:
Print 254,Puntero + 24,$1E,$16,$06,$06,$06,$0E,$1C,$18
RETURN
Resete:
REPEAT
DELAYMS 25 ' Wait until conversion is complete
OREAD DQ,4,[Cnt] ' Keep reading low pulses until
UNTIL Cnt=0 ' the DS1820 is finished
Return